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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: plugin-transform-modules-systemjs transformation is unsafe #13888

Closed
1 task
Rich-Harris opened this issue Oct 27, 2021 · 6 comments 路 Fixed by #14057
Closed
1 task

[Bug]: plugin-transform-modules-systemjs transformation is unsafe #13888

Rich-Harris opened this issue Oct 27, 2021 · 6 comments 路 Fixed by #14057
Assignees
Labels
area: modules i: bug i: needs triage outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: traverse (scope)

Comments

@Rich-Harris
Copy link
Contributor

馃捇

  • Would you like to work on a fix?

How are you using Babel?

Programmatic API (babel.transform, babel.parse)

Input code

REPL.

import { x } from './x.js';

if (true) {
	const x = 1;
	console.log(x);
}

new (class extends x {})();

Configuration file name

No response

Configuration

Using @babel/plugin-transform-modules-systemjs, nothing else

Current and expected behavior

I would expect the x = 1 to declare a local constant, as it does in the original code. Instead, it assigns to a new module-level variable (which in this case has the same name as an import, causing an error).

Environment

  System:
    OS: macOS 10.15.7
  Binaries:
    Node: 16.5.0 - ~/.nvm/versions/node/v16.5.0/bin/node
    Yarn: 1.22.5 - /usr/local/bin/yarn
    npm: 7.19.1 - ~/.nvm/versions/node/v16.5.0/bin/npm
  npmPackages:
    @babel/core: ^7.15.8 => 7.15.8 
    @babel/plugin-proposal-dynamic-import: ^7.14.5 => 7.14.5 
    @babel/plugin-transform-modules-systemjs: ^7.15.4 => 7.15.4 

Possible solution

No response

Additional context

cc @guybedford :)

@babel-bot
Copy link
Collaborator

Hey @Rich-Harris! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite.

@guybedford
Copy link
Contributor

Thanks for finding this @Rich-Harris. This is definitely a bug in the scope handling that it's collapsing all the local blocks without renaming in the hoisting operation.

//cc @joeldenning @nicolo-ribaudo

@The-x-Theorist
Copy link
Contributor

I'd like to work on this issue?

@The-x-Theorist
Copy link
Contributor

If we rename the variables in hoisting operation, babel-plugin-proposal-do-expressions/test/fixtures/do-expressions/variable-declaration-start-to-iife/exec.js: bar is not defined this test throws error.

@lightmare
Copy link
Contributor

If we rename the variables in hoisting operation, babel-plugin-proposal-do-expressions/test/fixtures/do-expressions/variable-declaration-start-to-iife/exec.js: bar is not defined this test throws error.

Can you keep the name for var declarations, and only rename const/let ?

@The-x-Theorist
Copy link
Contributor

Can you keep the name for var declarations, and only rename const/let ?

Yeah, I can do that.

@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Jun 17, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 17, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: modules i: bug i: needs triage outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: traverse (scope)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants
@guybedford @Rich-Harris @lightmare @nicolo-ribaudo @babel-bot @The-x-Theorist and others