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 check #87

Closed Riim closed 8 years ago

Riim commented 8 years ago

Input:

/**
 * @typesign (el: HTMLElement, name: string) -> boolean;
 */
let hasClass;

if (document.documentElement.classList) {
    hasClass = (el, name) => {
        return el.classList.contains(name);
    };
} else {
    let reNotWhite = /\S+/g;

    hasClass = (el, name) => {
        return (el.className.match(reNotWhite) || []).indexOf(name) != -1;
    };
}

module.exports = hasClass;

Output:

    "use strict";

    function _typeof(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }

    /**
     * @typesign (el: HTMLElement, name: string) -> boolean;
     */
    var hasClass = undefined;

    if (document.documentElement.classList) {
        hasClass = function (el, name) {
            return el.classList.contains(name);
        };
    } else {
        (function () {
            var reNotWhite = /\S+/g;

            hasClass = function (el, name) {
                return (el.className.match(reNotWhite) || []).indexOf(name) != -1;
            };
        })();
    }

    module.exports = hasClass;

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

Added check will never pass.

phpnode commented 8 years ago

@Riim can you confirm that you're using 3.4.6 ? I really thought I'd fixed this.

phpnode commented 8 years ago

By the way, you can work around this in the meantime using a pragma

Riim commented 8 years ago

Yes: "babel-plugin-typecheck": "^3.4.6",

phpnode commented 8 years ago

fixed in #88