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

Cannot read property 'name' of undefined #76

Closed sgodwin424 closed 8 years ago

sgodwin424 commented 8 years ago

The following example:

class Bar
{

}

class Foo
{
    _bar: Bar;

    constructor()
    {
        this._bar = new Bar();
    }

    SetBar(): void
    {
        let bar: ?Bar = null;

        if (bar != null)
        {
            this._bar = bar;
        }
    }
}

Produces the error:

C:\Users\Scott\documents\github\test\node_modules\babel-core\lib\transformation\file\index.js:540
      throw err;
      ^

TypeError: C:/Users/Scott/documents/github/test/foo.js: Cannot read property 'name' of undefined
    at maybeInstanceOfAnnotation (C:\Users\Scott\documents\github\test\node_modules\babel-plugin-typecheck\lib\index.js:2377:44)
    at maybeInstanceOfAnnotation (C:\Users\Scott\documents\github\test\node_modules\babel-plugin-typecheck\lib\index.js:2375:16)
    at Object._instanceof [as instanceof] (C:\Users\Scott\documents\github\test\node_modules\babel-plugin-typecheck\lib\index.js:594:16)
    at staticCheckAnnotation (C:\Users\Scott\documents\github\test\node_modules\babel-plugin-typecheck\lib\index.js:1369:41)
    at AssignmentExpression (C:\Users\Scott\documents\github\test\node_modules\babel-plugin-typecheck\lib\index.js:404:16)
    at NodePath._call (C:\Users\Scott\documents\github\test\node_modules\babel-traverse\lib\path\context.js:74:18)
    at NodePath.call (C:\Users\Scott\documents\github\test\node_modules\babel-traverse\lib\path\context.js:46:17)
    at NodePath.visit (C:\Users\Scott\documents\github\test\node_modules\babel-traverse\lib\path\context.js:104:12)
    at TraversalContext.visitQueue (C:\Users\Scott\documents\github\test\node_modules\babel-traverse\lib\context.js:153:16)
    at TraversalContext.visitSingle (C:\Users\Scott\documents\github\test\node_modules\babel-traverse\lib\context.js:113:19)

When attempting to use the require hook or use the babel cli. Removing the _bar: Bar; removes the error.

phpnode commented 8 years ago

fixed in 3.4.2