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
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
packages/babel-plugin-transform-typescript/test/fixtures/exports/export-const-enums/input.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
const enum None {}; | ||
export type { None }; |
5 changes: 5 additions & 0 deletions
5
...s/babel-plugin-transform-typescript/test/fixtures/exports/export-const-enums/options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"plugins": ["transform-typescript"], | ||
"sourceType": "module", | ||
"validateLogs": true | ||
} |
6 changes: 6 additions & 0 deletions
6
...ges/babel-plugin-transform-typescript/test/fixtures/exports/export-const-enums/output.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
var None; | ||
|
||
(function (None) {})(None || (None = {})); | ||
|
||
; | ||
export {}; |
1 change: 1 addition & 0 deletions
1
...babel-plugin-transform-typescript/test/fixtures/exports/export-context-variables/input.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default undefined; |
5 changes: 5 additions & 0 deletions
5
...l-plugin-transform-typescript/test/fixtures/exports/export-context-variables/options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"plugins": ["transform-typescript"], | ||
"sourceType": "module", | ||
"validateLogs": true | ||
} |
1 change: 1 addition & 0 deletions
1
...bel-plugin-transform-typescript/test/fixtures/exports/export-context-variables/output.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default undefined; |
1 change: 1 addition & 0 deletions
1
packages/babel-plugin-transform-typescript/test/fixtures/exports/export-globals/input.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default Math; |
5 changes: 5 additions & 0 deletions
5
packages/babel-plugin-transform-typescript/test/fixtures/exports/export-globals/options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"plugins": ["transform-typescript"], | ||
"sourceType": "module", | ||
"validateLogs": true | ||
} |
1 change: 1 addition & 0 deletions
1
packages/babel-plugin-transform-typescript/test/fixtures/exports/export-globals/output.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default Math; |
5 changes: 5 additions & 0 deletions
5
...pescript/test/fixtures/optimize-const-enums/export-const-enum-type-and-value/options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"plugins": [["transform-typescript", { "optimizeConstEnums": true }]], | ||
"sourceType": "module", | ||
"validateLogs": true | ||
} |
5 changes: 5 additions & 0 deletions
5
...ypescript/test/fixtures/optimize-const-enums/export-const-enum-type-no-deopt/options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"plugins": [["transform-typescript", { "optimizeConstEnums": true }]], | ||
"sourceType": "module", | ||
"validateLogs": true | ||
} |
16 changes: 16 additions & 0 deletions
16
...-typescript/test/fixtures/optimize-const-enums/export-const-enum-type-no-deopt/stderr.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
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)". |
3 changes: 2 additions & 1 deletion
3
packages/babel-plugin-transform-typescript/test/fixtures/regression/10162/options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
{ | ||
"plugins": ["./plugin.js", "transform-typescript"], | ||
"sourceType": "module" | ||
"sourceType": "module", | ||
"validateLogs": true | ||
} |
1 change: 0 additions & 1 deletion
1
packages/babel-plugin-transform-typescript/test/fixtures/regression/10162/output.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
const foo = 2; | ||
export default foo; | ||
["The exported identifier \"foo\" is not declared in Babel's scope tracker\nas a JavaScript value binding, and \"@babel/plugin-transform-typescript\"\nnever encountered it as a TypeScript type declaration.\nIt will be treated as a JavaScript value.\n\nThis problem is likely caused by another plugin injecting\n\"foo\" without registering it in the scope tracker. If you are the author\n of that plugin, please use \"scope.registerDeclaration(declarationPath)\"."]; |
17 changes: 1 addition & 16 deletions
17
packages/babel-plugin-transform-typescript/test/fixtures/regression/10162/plugin.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
packages/babel-plugin-transform-typescript/test/fixtures/regression/10162/stderr.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
The exported identifier "foo" 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 | ||
"foo" without registering it in the scope tracker. If you are the author | ||
of that plugin, please use "scope.registerDeclaration(declarationPath)". |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The test case is
We first remove the enum declaration
WhitespaceFlag
, so the referencedWhitespaceFlag
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.