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

Fix const violations in ESM imports when transformed to CJS #13258

Merged
merged 5 commits into from Jun 22, 2021

Conversation

@overlookmotel
Copy link
Contributor

@overlookmotel overlookmotel commented May 4, 2021

Q                       A
Fixed Issues? No issue filed
Patch: Bug Fix? Yes
Major: Breaking Change? No
Minor: New Feature? No
Tests Added + Pass? Yes
Documentation PR Link n/a
Any Dependency Changes? No
License MIT

This PR fixes similar cases to #13248 in plugin-transform-modules-commonjs relating to const violations with import statements.

e.g.:

import x from 'foo';
x = 1;

This PR:

  1. Fixes compilation error if import x from 'foo'; x &&= 1;
  2. Adds const violation errors for import x from 'foo'; for ( x in {} ) {}
  3. Fixes a small bug with for loops without a block statement e.g. export let x = 1; for ( x in {} ) x();
  4. Adds more tests for assignments

@codesandbox
Copy link

@codesandbox codesandbox bot commented May 4, 2021

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:

Sandbox Source
babel-repl-custom-plugin Configuration
babel-plugin-multi-config Configuration

packages/babel-helper-simple-access/src/index.ts Outdated Show resolved Hide resolved
}
}
if (imported.get(name) && !importConstViolationName) {
importConstViolationName = name;

This comment has been minimized.

@JLHwung

JLHwung May 19, 2021
Contributor

Should we record all const violation names? e.g.

import { x, y } from 'foo';
for ( [x, y] of [] );

This comment has been minimized.

@nicolo-ribaudo

nicolo-ribaudo May 20, 2021
Member

It's enough to report the first one, since we only inject the error for the first one (the others are not observable anyway).

This comment has been minimized.

@overlookmotel

overlookmotel Jun 22, 2021
Author Contributor

I think @nicolo-ribaudo is correct. Only the first is necessary as that will throw an error before the 2nd is evaluated.

@overlookmotel
Copy link
Contributor Author

@overlookmotel overlookmotel commented May 21, 2021

@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.

@overlookmotel overlookmotel force-pushed the overlookmotel:module-import-assignments branch from 125cc47 to f76a694 Jun 22, 2021
@overlookmotel
Copy link
Contributor Author

@overlookmotel overlookmotel commented Jun 22, 2021

@JLHwung Changes requested have been made. I think this is ready to merge if you're happy with it.

Copy link
Contributor

@JLHwung JLHwung left a comment

Thanks!

@nicolo-ribaudo nicolo-ribaudo changed the title Fix const violations in ES module imports when transformed to CommonJS Fix const violations in ESM imports when transformed to CJS Jun 22, 2021
@nicolo-ribaudo nicolo-ribaudo merged commit 5ac5e35 into babel:main Jun 22, 2021
23 checks passed
23 checks passed
@github-actions
Prepare Cache
Details
@github-actions
Validate Yarn dependencies and constraints
Details
@github-actions
Test on Node.js Latest
Details
@github-actions
Build Babel Artifacts
Details
@github-actions
Test Babel 8 breaking changes
Details
@github-actions
Publish to local Verdaccio registry
Details
@github-actions
Lint
Details
@github-actions
Test on Node.js (14)
Details
@github-actions
Test on Node.js (12)
Details
@github-actions
Test on Node.js (10)
Details
@github-actions
Test on Node.js (8)
Details
@github-actions
Test on Node.js (6)
Details
@github-actions
Test on Windows
Details
@github-actions
Third-party Parser Tests
Details
@github-actions
Test @babel/runtime integrations
Details
@github-actions
E2E (babel)
Details
@github-actions
E2E (babel-old-version)
Details
@github-actions
E2E (create-react-app)
Details
@github-actions
E2E (vue-cli)
Details
@github-actions
E2E (jest)
Details
@gitpod-io
Gitpod Open an online workspace in Gitpod
Details
@codesandbox
ci/codesandbox Building packages succeeded.
Details
@codecov
codecov/project 92.05% (target 90.00%)
Details
@overlookmotel
Copy link
Contributor Author

@overlookmotel overlookmotel commented Jun 23, 2021

Thanks very much for swift merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants