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 committed Mar 11, 2020
1 parent 3840d15 commit 33c10f4
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 51 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 @@ -773,6 +773,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 @@ -150,79 +150,64 @@
},
{
"type": "TSOptionalType",
"start": 25,
"start": 26,
"end": 43,
"loc": {
"start": {
"line": 1,
"column": 25
"column": 26
},
"end": {
"line": 1,
"column": 43
}
},
"typeAnnotation": {
"type": "TSParenthesizedType",
"start": 25,
"end": 42,
"type": "TSUnionType",
"start": 26,
"end": 41,
"loc": {
"start": {
"line": 1,
"column": 25
"column": 26
},
"end": {
"line": 1,
"column": 42
"column": 41
}
},
"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
}
}
},
"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
}
{
"type": "TSNumberKeyword",
"start": 35,
"end": 41,
"loc": {
"start": {
"line": 1,
"column": 35
},
"end": {
"line": 1,
"column": 41
}
}
]
}
}
]
}
}
]
Expand All @@ -237,4 +222,4 @@
],
"directives": []
}
}
}

0 comments on commit 33c10f4

Please sign in to comment.