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
Throw a better error when transforming imported bindings in types #13739
Merged
nicolo-ribaudo
merged 3 commits into
babel:main
from
nicolo-ribaudo:better-error-module-transforms-in-type-annotation
Sep 16, 2021
Merged
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions
5
...in-transform-modules-commonjs/test/fixtures/integration/missing-flow-plugin-deep/input.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import A from "x"; | ||
|
||
export function fn(x: A.b[2]) { | ||
return A.method(x); | ||
} |
6 changes: 6 additions & 0 deletions
6
...ransform-modules-commonjs/test/fixtures/integration/missing-flow-plugin-deep/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,6 @@ | ||
{ | ||
"externalHelpers": true, | ||
"sourceType": "module", | ||
"plugins": ["transform-modules-commonjs", "syntax-flow"], | ||
"throws": "Cannot transform the imported binding \"A\" since it's also used in a type annotation. Please strip type annotations using @babel/preset-typescript or @babel/preset-flow." | ||
} |
3 changes: 3 additions & 0 deletions
3
...ansform-modules-commonjs/test/fixtures/integration/missing-flow-plugin-type-cast/input.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { A } from "x"; | ||
|
||
var x = ({} : A.b[0]); |
6 changes: 6 additions & 0 deletions
6
...orm-modules-commonjs/test/fixtures/integration/missing-flow-plugin-type-cast/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,6 @@ | ||
{ | ||
"externalHelpers": true, | ||
"sourceType": "module", | ||
"plugins": ["transform-modules-commonjs", "syntax-flow"], | ||
"throws": "Cannot transform the imported binding \"A\" since it's also used in a type annotation. Please strip type annotations using @babel/preset-typescript or @babel/preset-flow." | ||
} |
5 changes: 5 additions & 0 deletions
5
...-plugin-transform-modules-commonjs/test/fixtures/integration/missing-flow-plugin/input.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import A from "x"; | ||
|
||
export function fn(x: A) { | ||
return A.method(x); | ||
} |
6 changes: 6 additions & 0 deletions
6
...gin-transform-modules-commonjs/test/fixtures/integration/missing-flow-plugin/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,6 @@ | ||
{ | ||
"externalHelpers": true, | ||
"sourceType": "module", | ||
"plugins": ["transform-modules-commonjs", "syntax-flow"], | ||
"throws": "Cannot transform the imported binding \"A\" since it's also used in a type annotation. Please strip type annotations using @babel/preset-typescript or @babel/preset-flow." | ||
} |
5 changes: 5 additions & 0 deletions
5
...ugin-transform-modules-commonjs/test/fixtures/integration/missing-ts-plugin-deep/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,5 @@ | ||
import A from "x"; | ||
|
||
export function fn(x: A.b[2]) { | ||
return A.method(x); | ||
} |
6 changes: 6 additions & 0 deletions
6
...-transform-modules-commonjs/test/fixtures/integration/missing-ts-plugin-deep/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,6 @@ | ||
{ | ||
"externalHelpers": true, | ||
"sourceType": "module", | ||
"plugins": ["transform-modules-commonjs", "syntax-typescript"], | ||
"throws": "Cannot transform the imported binding \"A\" since it's also used in a type annotation. Please strip type annotations using @babel/preset-typescript or @babel/preset-flow." | ||
} |
3 changes: 3 additions & 0 deletions
3
...dules-commonjs/test/fixtures/integration/missing-ts-plugin-type-assertion-legacy/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,3 @@ | ||
import { A } from "x"; | ||
|
||
var x = {} as A.b[0]; |
6 changes: 6 additions & 0 deletions
6
...s-commonjs/test/fixtures/integration/missing-ts-plugin-type-assertion-legacy/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,6 @@ | ||
{ | ||
"externalHelpers": true, | ||
"sourceType": "module", | ||
"plugins": ["transform-modules-commonjs", "syntax-typescript"], | ||
"throws": "Cannot transform the imported binding \"A\" since it's also used in a type annotation. Please strip type annotations using @babel/preset-typescript or @babel/preset-flow." | ||
} |
3 changes: 3 additions & 0 deletions
3
...form-modules-commonjs/test/fixtures/integration/missing-ts-plugin-type-assertion/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,3 @@ | ||
import { A } from "x"; | ||
|
||
var x = <A.b[0]> {}; |
6 changes: 6 additions & 0 deletions
6
...-modules-commonjs/test/fixtures/integration/missing-ts-plugin-type-assertion/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,6 @@ | ||
{ | ||
"externalHelpers": true, | ||
"sourceType": "module", | ||
"plugins": ["transform-modules-commonjs", "syntax-typescript"], | ||
"throws": "Cannot transform the imported binding \"A\" since it's also used in a type annotation. Please strip type annotations using @babel/preset-typescript or @babel/preset-flow." | ||
} |
5 changes: 5 additions & 0 deletions
5
...el-plugin-transform-modules-commonjs/test/fixtures/integration/missing-ts-plugin/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,5 @@ | ||
import A from "x"; | ||
|
||
export function fn(x: A) { | ||
return A.method(x); | ||
} |
6 changes: 6 additions & 0 deletions
6
...lugin-transform-modules-commonjs/test/fixtures/integration/missing-ts-plugin/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,6 @@ | ||
{ | ||
"externalHelpers": true, | ||
"sourceType": "module", | ||
"plugins": ["transform-modules-commonjs", "syntax-typescript"], | ||
"throws": "Cannot transform the imported binding \"A\" since it's also used in a type annotation. Please strip type annotations using @babel/preset-typescript or @babel/preset-flow." | ||
} |
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.
we don't have an alias to cover all type usage for flow/ts? (or is this it anyway)
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.
It's enough to cover the nodes where the AST stops being an expression and starts being a type. The problem with a
TypeScript
/Flow
catch-all is that both TS and Flow introduce some expression nodes (for example, in enums).