Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: do not report global variables as injected binding (#14827)
* test: update regression/10162 * fix: global variables must not be global types * refactor: let GLOBAL_TYPES be a map<scope, set> * log warning messages to test fixtures
- Loading branch information
Showing
17 changed files
with
78 additions
and
33 deletions.
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)". |