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

Babel 6.7 warning: You or one of the Babel plugins you are using are using Flow declarations as bindings #134

Closed panrafal closed 8 years ago

panrafal commented 8 years ago

On the newest Babel 6.7 (with babel-traverse 6.7.2) the below warning shows up. It's caused by this PR: https://github.com/babel/babel/pull/3414

You or one of the Babel plugins you are using are using Flow declarations as bindings.
Support for this will be removed in version 6.8. To find out the caller, grep for this
message and change it to a `console.trace()`.

at Scope.warnOnFlowBinding (node_modules/babel-traverse/lib/scope/index.js:976:15)
at Scope.getOwnBinding (node_modules/babel-traverse/lib/scope/index.js:991:17)
at Scope.getBinding (node_modules/babel-traverse/lib/scope/index.js:985:27)
at isTypeChecker (node_modules/babel-plugin-typecheck/lib/index.js:52:568)
at staticCheckAnnotation (node_modules/babel-plugin-typecheck/lib/index.js:15:8390)
at Object.AssignmentExpression (node_modules/babel-plugin-typecheck/lib/index.js:6:7919)
at NodePath._call (node_modules/babel-traverse/lib/path/context.js:63:18)
at NodePath.call (node_modules/babel-traverse/lib/path/context.js:47:17)
at NodePath.visit (node_modules/babel-traverse/lib/path/context.js:93:12)
at TraversalContext.visitQueue (node_modules/babel-traverse/lib/context.js:146:16)
at TraversalContext.visitSingle (node_modules/babel-traverse/lib/context.js:115:19)
at TraversalContext.visit (node_modules/babel-traverse/lib/context.js:178:19)
phpnode commented 8 years ago

ugh!

prewk commented 8 years ago

I feel like this will bite us soon, have you had any chance to look at it?

phpnode commented 8 years ago

Agree this is a problem, unfortunately not yet, I'm tied up with other projects at the moment. PR would be gratefully accepted.

idchlife commented 8 years ago

What does it mean? In babel 6.7 this plugin just won't work?

igl commented 8 years ago

Support for this will be removed in version 6.8.

LucaColonnello commented 8 years ago

Rewire fix it in this way: https://github.com/speedskater/babel-plugin-rewire/commit/80d717a3014cac97e3fa6b8e60f991e30d977b76

Hope could be helpful... I really like this plugin and I don't wanna miss it!

gajus commented 8 years ago

I have traced the error message. All of these errors come from this line:

https://github.com/codemix/babel-plugin-typecheck/blob/c5554cb0fc7bc09cc3a585ed5883e7ca08090e7f/src/index.js#L2899

  function getTypeChecker (id: Identifier|QualifiedTypeIdentifier, scope: Scope): NodePath|false {
    const binding = scope.getBinding(id.name);
    if (binding === undefined) {
      return false;
    }

Unfortunately, knowing that is not enough to solve the issue. I have looked into how https://github.com/speedskater/babel-plugin-rewire/commit/80d717a3014cac97e3fa6b8e60f991e30d977b76 fixed the issue and came up with:

  function getTypeChecker (id: Identifier|QualifiedTypeIdentifier, scope: Scope): NodePath|false {
    const binding = (!t.isFlow || (!t.isFlow(id) && !t.isFlow(id.parent))) ? scope.getBinding(id.name) : undefined;

However, in this case, t.isFlow(id) && !t.isFlow(id.parent)) is true, therefore the function ends up calling scope.getBinding(id.name) anyway.

I know too little about type bindings and this particular issue to solve it. However, it could be a stepping stone for whoever tries after me.

gajus commented 8 years ago

Here is the PR that introduced the change.

https://phabricator.babeljs.io/rBC9b229f1f089277a928ec6786b5c4791a7d8c1b96

The change has been introduced by @amasad. I guess we will need to wait until he follows up with an explanation.

ntkoopman commented 8 years ago

A solution would be to look for the variable that is defined for every type instead of the type itself.

gajus commented 8 years ago

@phpnode can this be assigned a priority?

phpnode commented 8 years ago

@gajus it's high priority, i've started work on v4 which avoids this problem but it's a way from being releasable. I tried hacking around this issue in the existing plugin and ran into problems, but I will try again because it will be faster than waiting for v4.

phpnode commented 8 years ago

Fixed in 3.9.0