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

v3.4.0 "Cannot iterate void" #71

Closed sgodwin424 closed 8 years ago

sgodwin424 commented 8 years ago

I am running into a similar situation as in #68 where I receive an error trying to use the babel require hook, while I do not simply using babel-cli.

The following example:

class Foo
{
    constructor()
    {
        this.foo = [ ];
    }

    MyFunction(): void
    {
        for (let f: string of this.foo)
        {
            // ...
        }
    }
}

And the error is:

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

SyntaxError: C:/Users/Scott/Documents/GitHub/test/foo.js: Cannot iterate void
←[0m   8 |     MyFunction←[94m←[1m(←[22m←[39m←[94m←[1m)←[22m←[39m←[1m:←[22m ←[36mvoid←[39m
   9 |     ←[32m{←[39m
> 10 |         ←[36mfor←[39m ←[94m←[1m(←[22m←[39mlet f←[1m:←[22m string of ←[36mthis←[39m←[1m.←[22mfoo←[94m←[1m)←[22m←[39m
     |         ^
  11 |         ←[32m{←[39m
  12 |
  13 |         ←[32m}←[39m←[0m
    at File.buildCodeFrameError (C:\Users\Scott\Documents\GitHub\test\node_modules\babel-core\lib\transformation\file\index.js:407:15)
    at NodePath.buildCodeFrameError (C:\Users\Scott\Documents\GitHub\test\node_modules\babel-core\node_modules\babel-traverse\lib\path\index.js:148:26)
    at ForOfStatement (C:\Users\Scott\Documents\GitHub\test\node_modules\babel-plugin-typecheck\lib\index.js:434:20)
    at NodePath._call (C:\Users\Scott\Documents\GitHub\test\node_modules\babel-core\node_modules\babel-traverse\lib\path\context.js:74:18)
    at NodePath.call (C:\Users\Scott\Documents\GitHub\test\node_modules\babel-core\node_modules\babel-traverse\lib\path\context.js:46:17)
    at NodePath.visit (C:\Users\Scott\Documents\GitHub\test\node_modules\babel-core\node_modules\babel-traverse\lib\path\context.js:104:12)
    at TraversalContext.visitQueue (C:\Users\Scott\Documents\GitHub\test\node_modules\babel-core\node_modules\babel-traverse\lib\context.js:153:16)
    at TraversalContext.visitMultiple (C:\Users\Scott\Documents\GitHub\test\node_modules\babel-core\node_modules\babel-traverse\lib\context.js:108:17)
    at TraversalContext.visit (C:\Users\Scott\Documents\GitHub\test\node_modules\babel-core\node_modules\babel-traverse\lib\context.js:195:19)
    at Function.traverse.node (C:\Users\Scott\Documents\GitHub\test\node_modules\babel-core\node_modules\babel-traverse\lib\index.js:139:17)
phpnode commented 8 years ago

@sgodwin424 hey, this is the 2nd time I've been unable to replicate one of your bug reports, I wonder if you have something misconfigured in your .babelrc or in the options passed to babel.register(), or whether something in my configuration is masking the issues. Please could you do me a massive favour and create a repo with your babel config which replicates this issue?

See https://github.com/codemix/babel-plugin-typecheck/pull/72

sgodwin424 commented 8 years ago

I've created a repo at https://github.com/sgodwin424/typecheck-bug-test. Something is definitely wrong, I've tested it on two separate computers and am getting the same error. Hopefully it's just a simple configuration error, but I can't seem to find anything wrong with what I have setup.

Just do:

npm install
node bar

Also, just to be thorough, my node version is 5.1.0.

phpnode commented 8 years ago

@sgodwin424 thanks! looking into this now