Repository navigation
fix: Warning when export before enum
#18157
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
|
|
||
| export { Enum }; | ||
|
|
||
| const enum Enum {} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "plugins": [["transform-typescript"]], | ||
| "sourceType": "module", | ||
| "validateLogs": true | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| export { Enum }; | ||
| var Enum = /*#__PURE__*/function (Enum) { | ||
| return Enum; | ||
| }(Enum || {}); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1 @@ | ||
| The exported identifier "WhitespaceFlag" is not declared in Babel's scope tracker | ||
| as a JavaScript value binding, and "@babel/plugin-transform-typescript" | ||
| never encountered it as a TypeScript type declaration. | ||
| It will be treated as a JavaScript value. | ||
|
|
||
| This problem is likely caused by another plugin injecting | ||
| "WhitespaceFlag" without registering it in the scope tracker. If you are the author | ||
| of that plugin, please use "scope.registerDeclaration(declarationPath)". | ||
| The exported identifier "WhitespaceFlag" is not declared in Babel's scope tracker | ||
| as a JavaScript value binding, and "@babel/plugin-transform-typescript" | ||
| never encountered it as a TypeScript type declaration. | ||
| It will be treated as a JavaScript value. | ||
|
|
||
| This problem is likely caused by another plugin injecting | ||
| "WhitespaceFlag" without registering it in the scope tracker. If you are the author | ||
| of that plugin, please use "scope.registerDeclaration(declarationPath)". |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -755,6 +755,12 @@ class Scope { | |
| return; | ||
| } | ||
|
|
||
| if (path.isTSEnumDeclaration() && !path.node.declare) { | ||
| const id = path.get("id"); | ||
| this.registerBinding(kind, id, path); | ||
|
Comment on lines
+758
to
+760
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
With Useful? React with 👍 / 👎.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While adding tests, I discovered that
Comment on lines
+758
to
+760
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When an enum appears in a nested block and an enclosing function/program has a same-named binding, this new special case registers the enum in that enclosing scope because the collector routes non- Useful? React with 👍 / 👎. |
||
| return; | ||
| } | ||
|
|
||
| const parent = this.getProgramParent(); | ||
| const ids = path.getOuterBindingIdentifiers(true); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When this plugin version is loaded by an older but supported
@babel/core/@babel/traverse(the plugin's peer range is^8.0.0), enums have no scope binding, so withoptimizeConstEnumsan input such asexport const enum E { A }takes this branch and becomesObject.assign(E, ...)without ever declaringE, throwing during module evaluation. A missing binding must follow the declaration-creation path, and the paired traverse change must likewise remain compatible with older plugin versions.Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am surprised that AI has also discovered this.