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
Fix const violations in ESM imports when transformed to CJS #13258
Fix const violations in ESM imports when transformed to CJS #13258
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit f76a694:
|
packages/babel-helper-module-transforms/src/rewrite-live-references.ts
Outdated
Show resolved
Hide resolved
} | ||
} | ||
if (imported.get(name) && !importConstViolationName) { | ||
importConstViolationName = name; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we record all const violation names? e.g.
import { x, y } from 'foo';
for ( [x, y] of [] );
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's enough to report the first one, since we only inject the error for the first one (the others are not observable anyway).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think @nicolo-ribaudo is correct. Only the first is necessary as that will throw an error before the 2nd is evaluated.
@JLHwung @nicolo-ribaudo Thanks for the comments. Just to let you know, I'm flat out next few weeks, so will have to leave this until my project is done. But I'll come back to this and make the changes requested next month. |
125cc47
to
f76a694
Compare
@JLHwung Changes requested have been made. I think this is ready to merge if you're happy with it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Thanks very much for swift merge. |
This PR fixes similar cases to #13248 in plugin-transform-modules-commonjs relating to const violations with
import
statements.e.g.:
This PR:
import x from 'foo'; x &&= 1;
import x from 'foo'; for ( x in {} ) {}
export let x = 1; for ( x in {} ) x();