Skip to content

Commit

Permalink
Don't create TSParenthesizedType when `createParenthesizedExpressio…
Browse files Browse the repository at this point in the history
…ns` disabled (babel#9546)
  • Loading branch information
smelukov authored and JLHwung committed Jan 11, 2021
1 parent 4f83a09 commit 903280d
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 2 deletions.
7 changes: 7 additions & 0 deletions packages/babel-parser/src/plugins/typescript/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,13 @@ export default (superClass: Class<Parser>): Class<Parser> =>
case tt.bracketL:
return this.tsParseTupleType();
case tt.parenL:
if (!this.options.createParenthesizedExpressions) {
this.expect(tt.parenL);
const type = this.tsParseType();
this.expect(tt.parenR);
return type;
}

return this.tsParseParenthesizedType();
case tt.backQuote:
return this.tsParseTemplateLiteralType();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"plugins": ["typescript"],
"createParenthesizedExpressions": true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"plugins": ["typescript"],
"createParenthesizedExpressions": true
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
},
{
"type": "TSOptionalType",
<<<<<<< HEAD
"start":25,"end":43,"loc":{"start":{"line":1,"column":25},"end":{"line":1,"column":43}},
"typeAnnotation": {
"type": "TSParenthesizedType",
Expand All @@ -54,9 +55,66 @@
{
"type": "TSNumberKeyword",
"start":35,"end":41,"loc":{"start":{"line":1,"column":35},"end":{"line":1,"column":41}}
}
]
=======
"start": 26,
"end": 43,
"loc": {
"start": {
"line": 1,
"column": 26
},
"end": {
"line": 1,
"column": 43
}
},
"typeAnnotation": {
"type": "TSUnionType",
"start": 26,
"end": 41,
"loc": {
"start": {
"line": 1,
"column": 26
},
"end": {
"line": 1,
"column": 41
}
},
"types": [
{
"type": "TSStringKeyword",
"start": 26,
"end": 32,
"loc": {
"start": {
"line": 1,
"column": 26
},
"end": {
"line": 1,
"column": 32
}
}
},
{
"type": "TSNumberKeyword",
"start": 35,
"end": 41,
"loc": {
"start": {
"line": 1,
"column": 35
},
"end": {
"line": 1,
"column": 41
}
>>>>>>> 838145b1b5 (Don't create `TSParenthesizedType` when `createParenthesizedExpressions` disabled (#9546))
}
}
]
}
}
]
Expand Down

0 comments on commit 903280d

Please sign in to comment.