Skip to content

Commit

Permalink
Add disallowJSXAmbiguity option to the TS syntax plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Oct 11, 2021
1 parent 6027225 commit 2e6cdfb
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 3 deletions.
3 changes: 2 additions & 1 deletion packages/babel-plugin-syntax-typescript/package.json
Expand Up @@ -24,7 +24,8 @@
"@babel/core": "^7.0.0-0"
},
"devDependencies": {
"@babel/core": "workspace:*"
"@babel/core": "workspace:*",
"@babel/helper-plugin-test-runner": "workspace:*"
},
"engines": {
"node": ">=6.9.0"
Expand Down
7 changes: 5 additions & 2 deletions packages/babel-plugin-syntax-typescript/src/index.js
Expand Up @@ -15,7 +15,7 @@ function removePlugin(plugins, name) {
}
}

export default declare((api, { isTSX }) => {
export default declare((api, { isTSX, disallowJSXAmbiguity }) => {
api.assertVersion(7);

return {
Expand All @@ -31,7 +31,10 @@ export default declare((api, { isTSX }) => {
// in TS depends on the extensions, and is purely dependent on 'isTSX'.
removePlugin(plugins, "jsx");

parserOpts.plugins.push("typescript", "classProperties");
parserOpts.plugins.push(
["typescript", { disallowJSXAmbiguity }],
"classProperties",
);

if (!process.env.BABEL_8_BREAKING) {
// This is enabled by default since @babel/parser 7.1.5
Expand Down
@@ -0,0 +1,3 @@
{
"plugins": [["syntax-typescript", { "disallowJSXAmbiguity": true }]]
}
@@ -0,0 +1 @@
<T>x;
@@ -0,0 +1,3 @@
{
"throws": "This syntax is reserved in files with the .mts or .cts extension. Use an `as` expression instead. (1:0)"
}
@@ -0,0 +1,2 @@
<T,>() => 1;
<T,>(x) => 1;
@@ -0,0 +1,3 @@
<T>() => 1;

<T>(x) => 1;
@@ -0,0 +1,2 @@
<T>() => 1;
<T>(x) => 1;
@@ -0,0 +1,3 @@
{
"throws": "This syntax is reserved in files with the .mts or .cts extension. Add a trailing comma, as in `<T,>() => ...`. (1:0)"
}
3 changes: 3 additions & 0 deletions packages/babel-plugin-syntax-typescript/test/index.js
@@ -0,0 +1,3 @@
import runner from "@babel/helper-plugin-test-runner";

runner(import.meta.url);
1 change: 1 addition & 0 deletions yarn.lock
Expand Up @@ -1995,6 +1995,7 @@ __metadata:
resolution: "@babel/plugin-syntax-typescript@workspace:packages/babel-plugin-syntax-typescript"
dependencies:
"@babel/core": "workspace:*"
"@babel/helper-plugin-test-runner": "workspace:*"
"@babel/helper-plugin-utils": "workspace:^7.14.5"
peerDependencies:
"@babel/core": ^7.0.0-0
Expand Down

0 comments on commit 2e6cdfb

Please sign in to comment.