codemix / babel-plugin-typecheck

Static and runtime type checking for JavaScript in the form of a Babel plugin.
MIT License
886 stars 44 forks source link

Impassable excess tests #82

Closed Riim closed 8 years ago

Riim commented 8 years ago

Input:

let Component = createClass({
    constructor(block, options) {
        if (options.init) {
            this.init = options.init;
        }
        if (options.dispose) {
            this.dispose = options.dispose;
        }

        block[KEY_COMPONENT] = this;
    },

    init: null,
    dispose: null
});

Output:

var Component = createClass({
    constructor: function constructor(block, options) {
        if (options.init) {
            this.init = options.init;

            if (!(this.init == null)) {
                throw new TypeError('Value of "this.init" violates contract, expected void got ' + (this.init === null ? 'null' : _typeof(this.init) === 'object' && this.init.constructor ? this.init.constructor.name || '[Unknown Object]' : _typeof(this.init)));
            }
        }
        if (options.dispose) {
            this.dispose = options.dispose;

            if (!(this.dispose == null)) {
                throw new TypeError('Value of "this.dispose" violates contract, expected void got ' + (this.dispose === null ? 'null' : _typeof(this.dispose) === 'object' && this.dispose.constructor ? this.dispose.constructor.name || '[Unknown Object]' : _typeof(this.dispose)));
            }
        }

        block[KEY_COMPONENT] = this;

        if (!(block[KEY_COMPONENT] != null && _typeof(block[KEY_COMPONENT]) === 'object' && typeof block[KEY_COMPONENT].constructor === 'function' && block[KEY_COMPONENT].init == null && block[KEY_COMPONENT].dispose == null)) {
            throw new TypeError('Value of "block[KEY_COMPONENT]" violates contract, expected { constructor(): any;\n  init: void;\n  dispose: void;\n} got ' + (block[KEY_COMPONENT] === null ? 'null' : _typeof(block[KEY_COMPONENT]) === 'object' && block[KEY_COMPONENT].constructor ? block[KEY_COMPONENT].constructor.name || '[Unknown Object]' : _typeof(block[KEY_COMPONENT])));
        }
    },

    init: null,
    dispose: null
});

All three added tests will always throw an error.

phpnode commented 8 years ago

fixed in 3.4.5