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: do not report global variables as injected binding #14827

Merged
merged 4 commits into from Aug 4, 2022

Conversation

JLHwung
Copy link
Contributor

@JLHwung JLHwung commented Aug 3, 2022

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

As suggested by the OP, we use hasBinding here, which also checks global variables (e.g. Math) and context variables (e.g. undefined). Note that the scope is always a top-level scope so hasBinding here is equivalent to hasOwnBinding + global variables check.

Also refactored the GLOBAL_TYPES data structure so we don't have to find the program node from export specifiers, after all they share the same scope.

@JLHwung JLHwung added PR: Bug Fix 🐛 A type of pull request used for our changelog categories area: typescript labels Aug 3, 2022
@babel-bot
Copy link
Collaborator

babel-bot commented Aug 3, 2022

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

@@ -0,0 +1,16 @@
The exported identifier "WhitespaceFlag" is not declared in Babel's scope tracker
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The test case is

const enum WhitespaceFlag {
  before = 1 << 0,
  after = 1 << 1,
}

export type { WhitespaceFlag as WF1 };
export { type WhitespaceFlag as WF2 };

export const before = WhitespaceFlag.before;

We first remove the enum declaration WhitespaceFlag, so the referenced WhitespaceFlag becomes invalid and the warning is triggered. In a way it is similar to #14818 where we removed the scope binding info but didn't fix its now-dangling referenced paths.

@JLHwung JLHwung merged commit 9fad3a8 into babel:main Aug 4, 2022
@JLHwung JLHwung deleted the fix-14826 branch August 4, 2022 12:50
@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 Nov 4, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: typescript outdated A closed issue/PR that is archived due to age. Recommended to make a new issue 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]: @babel/plugin-transform-typescript outputs warnings on export of global-scope identifiers
3 participants