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: support module expression scopes #16091

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

DMartens
Copy link

@DMartens DMartens commented Nov 9, 2023

Q                       A
Fixed Issues? Fixes #16037
Patch: Bug Fix? 👍
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

The Program visitor can now only be called once for the top-level (cannot access the parent property on node, so I added a class field).
Also added a visitor for ModuleExpression nesting a module scope.

@babel-bot
Copy link
Collaborator

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/55795/

@nicolo-ribaudo nicolo-ribaudo added the PR: Bug Fix 🐛 A type of pull request used for our changelog categories label Nov 14, 2023
Copy link
Member

@nicolo-ribaudo nicolo-ribaudo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also add a test that in this example:

let a = 2;
(module { a; })

the a reference inside the module block does not refer to the outer a declaration?

@DMartens
Copy link
Author

DMartens commented Nov 14, 2023

This is not implemented, as this only a simple fix, so that analyzing the scope works at all without throwing an error.
As I understand, eslint-scope has no concept of "isolated" scopes (variables can be read from any parent scope).
One idea to hack it in would be to track the module expressions and check it either in the Identifier visitor or when referencing a value.
But honestly I think this change should be made by eslint-scope or in a separate PR as this would require more extensive testing (e.g. nested module expressions).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: Bug Fix 🐛 A type of pull request used for our changelog categories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: module expression scope handling
3 participants