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

Undeclared variables being assigned when used with preset env targeting ES5 #45

Closed
i-like-robots opened this issue Oct 14, 2019 · 2 comments

Comments

@i-like-robots
Copy link

i-like-robots commented Oct 14, 2019

When using the babel-plugin-transform-async-to-promises along with @babel/preset-env targeting an ES5 environment (such as IE 11) variables can be assigned without first being declared which causes the following error/s:

ReferenceError: assignment to undeclared variable varname

I have created a minimum test case demonstrating this issue here: https://github.com/i-like-robots/broken-babel-async-await-transform-test-case

There appears to be several ways to mitigate the issue as manifested in the example above:

  • Change the target to an ES6 compatible environment so that the variable declarations to not need transforming to use var syntax (not an option for us)
  • Move the export default statement to another line (most practical but in our case would require changes to number of code bases across our projects)
  • Avoid using certain variables within the scope of a function generated by this plugin (probably not possible)

This may be a duplicate of #38

@rpetrich
Copy link
Owner

rpetrich commented Oct 21, 2019

Babel's scope tracking got more strict in babel 7.6 and broke the tracking of variables across functions; this is now remedied in master and will be in the next release.

@i-like-robots
Copy link
Author

Thank you @rpetrich 👍

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

2 participants