Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with export class Bug { ... }; export default Bug; in Babel 7 #199

Closed
Ashoat opened this issue Jul 13, 2018 · 8 comments
Closed

Issue with export class Bug { ... }; export default Bug; in Babel 7 #199

Ashoat opened this issue Jul 13, 2018 · 8 comments

Comments

@Ashoat
Copy link

Ashoat commented Jul 13, 2018

I am seeing this issue with react-native@0.56.0 and metro@0.38.3 (and also metro@0.38.1).

Here's the code that causes the issue:

export class Bug {

  constructor(props) {
    this.test(props);
  }

  test = (props) => {
    // Error-causing line
    const test = props.test;
  }

}

export default Bug;

The error is:

error: bundling failed: TypeError: Property body[1] of BlockStatement expected node to be of a type ["Statement"] but instead got "ClassExpression"
    at validate (/Users/ashoat/Dropbox/src/rn56babelbug/node_modules/@babel/types/lib/definitions/utils.js:130:13)
    at validator (/Users/ashoat/Dropbox/src/rn56babelbug/node_modules/@babel/types/lib/definitions/utils.js:97:7)
    at Object.validate (/Users/ashoat/Dropbox/src/rn56babelbug/node_modules/@babel/types/lib/definitions/utils.js:177:7)
    at validate (/Users/ashoat/Dropbox/src/rn56babelbug/node_modules/@babel/types/lib/validators/validate.js:17:9)
    at builder (/Users/ashoat/Dropbox/src/rn56babelbug/node_modules/@babel/types/lib/builders/builder.js:46:27)
    at Object.BlockStatement (/Users/ashoat/Dropbox/src/rn56babelbug/node_modules/@babel/types/lib/builders/generated/index.js:245:31)
    at NodePath.replaceExpressionWithStatements (/Users/ashoat/Dropbox/src/rn56babelbug/node_modules/@babel/traverse/lib/path/replacement.js:212:57)
    at NodePath.insertBefore (/Users/ashoat/Dropbox/src/rn56babelbug/node_modules/@babel/traverse/lib/path/modification.js:47:17)
    at NodePath.unshiftContainer (/Users/ashoat/Dropbox/src/rn56babelbug/node_modules/@babel/traverse/lib/path/modification.js:204:15)

I've created a repo with this minimal repro here. I attempted to repro the issue without Metro, by setting up a Babel project with the same code and babel-preset-react-native here, but was unable to repro. My conclusion is that the issue has something to do with how Metro consumes Babel.

@Ashoat
Copy link
Author

Ashoat commented Jul 13, 2018

I initially found this problem while investigating this React Native issue. Additionally I think this React Native issue might be related, which @charpeni was able to repro on a naked Metro setup.

In both cases, the issue can be addressed by using two separate expressions to declare the class versus export it.

@Ashoat
Copy link
Author

Ashoat commented Jul 13, 2018

This Babel issue may be related. It looks like the specific issue there had to do with plugin ordering, which perhaps is the culprit here (though I doubt in the same way).

@rafeca
Copy link
Contributor

rafeca commented Aug 2, 2018

@mjesun does this have anything to do with the Babel issues that manifest on our constant folding plugin? (more info)

@mjesun
Copy link
Contributor

mjesun commented Aug 8, 2018

Yeah, it could be. Apparently scope traversing has some bugs in Babel. I've tried pinging them with no luck, though.

@Ashoat
Copy link
Author

Ashoat commented Aug 8, 2018

If we could get a pure-Babel repro I think it would easier to get their attention. But my attempts at that were unsuccessful, probably because I’m not accurately mirroring the way Metro consumes Babel. Any advice?

@mjesun
Copy link
Contributor

mjesun commented Aug 8, 2018

The issues I've found so far are related to calling path.scope.crawl() after performing some evaluations. See an example in babel/babel#8387; maybe this helps repro'ing.

@kelset
Copy link
Contributor

kelset commented Aug 28, 2018

I think this may be fixed via Babel 7.0 and Metro 0.44.x (once this is merged #233)

@rafeca
Copy link
Contributor

rafeca commented Sep 6, 2018

Yes, we can close this one already! 😄

@rafeca rafeca closed this as completed Sep 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants