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
Handle .mts
and .cts
files in @babel/preset-typescript
#13838
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
c1682fd
Add `disallowJSXAmbiguity` option to the TS parser plugin
nicolo-ribaudo 57cc34b
Add `disallowJSXAmbiguity` option to the TS syntax plugin
nicolo-ribaudo 7e55e16
Handle `.mts` and `.cts` files in `@babel/preset-typescript`
nicolo-ribaudo 07343ca
`disallowJSXAmbiguity` -> `disallowAmbiguousJSXLike`
nicolo-ribaudo 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
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
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
3 changes: 3 additions & 0 deletions
3
packages/babel-parser/test/fixtures/typescript/disallow-jsx-ambiguity/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,3 @@ | ||
{ | ||
"plugins": [["typescript", { "disallowAmbiguousJSXLike": true }]] | ||
} |
1 change: 1 addition & 0 deletions
1
...ages/babel-parser/test/fixtures/typescript/disallow-jsx-ambiguity/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 @@ | ||
<T>x; |
38 changes: 38 additions & 0 deletions
38
...s/babel-parser/test/fixtures/typescript/disallow-jsx-ambiguity/type-assertion/output.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,38 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":5,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":5}}, | ||
"errors": [ | ||
"SyntaxError: This syntax is reserved in files with the .mts or .cts extension. Use an `as` expression instead. (1:0)" | ||
], | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":5,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":5}}, | ||
"sourceType": "script", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "ExpressionStatement", | ||
"start":0,"end":5,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":5}}, | ||
"expression": { | ||
"type": "TSTypeAssertion", | ||
"start":0,"end":4,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":4}}, | ||
"typeAnnotation": { | ||
"type": "TSTypeReference", | ||
"start":1,"end":2,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":2}}, | ||
"typeName": { | ||
"type": "Identifier", | ||
"start":1,"end":2,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":2},"identifierName":"T"}, | ||
"name": "T" | ||
} | ||
}, | ||
"expression": { | ||
"type": "Identifier", | ||
"start":3,"end":4,"loc":{"start":{"line":1,"column":3},"end":{"line":1,"column":4},"identifierName":"x"}, | ||
"name": "x" | ||
} | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
...el-parser/test/fixtures/typescript/disallow-jsx-ambiguity/type-parameter-babel-7/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 @@ | ||
<T>() => 1; | ||
<T>(x) => 1; |
3 changes: 3 additions & 0 deletions
3
...arser/test/fixtures/typescript/disallow-jsx-ambiguity/type-parameter-babel-7/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,3 @@ | ||
{ | ||
"BABEL_8_BREAKING": false | ||
} |
87 changes: 87 additions & 0 deletions
87
...parser/test/fixtures/typescript/disallow-jsx-ambiguity/type-parameter-babel-7/output.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,87 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":24,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":12}}, | ||
"errors": [ | ||
"SyntaxError: This syntax is reserved in files with the .mts or .cts extension. Add a trailing comma, as in `<T,>() => ...`. (1:0)", | ||
"SyntaxError: This syntax is reserved in files with the .mts or .cts extension. Add a trailing comma, as in `<T,>() => ...`. (2:0)" | ||
], | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":24,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":12}}, | ||
"sourceType": "script", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "ExpressionStatement", | ||
"start":0,"end":11,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":11}}, | ||
"expression": { | ||
"type": "ArrowFunctionExpression", | ||
"start":0,"end":10,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":10}}, | ||
"id": null, | ||
"generator": false, | ||
"async": false, | ||
"params": [], | ||
"body": { | ||
"type": "NumericLiteral", | ||
"start":9,"end":10,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":10}}, | ||
"extra": { | ||
"rawValue": 1, | ||
"raw": "1" | ||
}, | ||
"value": 1 | ||
}, | ||
"typeParameters": { | ||
"type": "TSTypeParameterDeclaration", | ||
"start":0,"end":3,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":3}}, | ||
"params": [ | ||
{ | ||
"type": "TSTypeParameter", | ||
"start":1,"end":2,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":2}}, | ||
"name": "T" | ||
} | ||
] | ||
} | ||
} | ||
}, | ||
{ | ||
"type": "ExpressionStatement", | ||
"start":12,"end":24,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":12}}, | ||
"expression": { | ||
"type": "ArrowFunctionExpression", | ||
"start":12,"end":23,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":11}}, | ||
"id": null, | ||
"generator": false, | ||
"async": false, | ||
"params": [ | ||
{ | ||
"type": "Identifier", | ||
"start":16,"end":17,"loc":{"start":{"line":2,"column":4},"end":{"line":2,"column":5},"identifierName":"x"}, | ||
"name": "x" | ||
} | ||
], | ||
"body": { | ||
"type": "NumericLiteral", | ||
"start":22,"end":23,"loc":{"start":{"line":2,"column":10},"end":{"line":2,"column":11}}, | ||
"extra": { | ||
"rawValue": 1, | ||
"raw": "1" | ||
}, | ||
"value": 1 | ||
}, | ||
"typeParameters": { | ||
"type": "TSTypeParameterDeclaration", | ||
"start":12,"end":15,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":3}}, | ||
"params": [ | ||
{ | ||
"type": "TSTypeParameter", | ||
"start":13,"end":14,"loc":{"start":{"line":2,"column":1},"end":{"line":2,"column":2}}, | ||
"name": "T" | ||
} | ||
] | ||
} | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
...st/fixtures/typescript/disallow-jsx-ambiguity/type-parameter-unambiguous-babel-7/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 @@ | ||
<T,>() => 1; | ||
<T,>(x) => 1; |
3 changes: 3 additions & 0 deletions
3
...ixtures/typescript/disallow-jsx-ambiguity/type-parameter-unambiguous-babel-7/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,3 @@ | ||
{ | ||
"BABEL_8_BREAKING": false | ||
} |
Oops, something went wrong.
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.
This was quite annoying: since user-defined options have precedence over preset-defined options, it disabled
preset-typescript
's extension-basedsourceType
inference.Removing this default makes all the tests fail because of the
output.js
file extension (Babel defaults to modules, so the test runner expects.mjs
extensions) -- I'll handle it in a separate PR.