Fix const violations in ESM imports when transformed to CJS#13258
Fix const violations in ESM imports when transformed to CJS#13258nicolo-ribaudo merged 5 commits intobabel:mainfrom
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.
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.
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.
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. |
|
Thanks very much for swift merge. |
This PR fixes similar cases to #13248 in plugin-transform-modules-commonjs relating to const violations with
importstatements.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();