[babel 8] Don't create TSParenthesizedType nodes by default (#12608)
Co-authored-by: Huáng Jùnliàng <jlhwung@gmail.com> Co-authored-by: Sergey Melyukov <s.melukov@gmail.com>
This commit is contained in:
parent
2338b052ad
commit
62290aa1ba
1
packages/babel-generator/test/fixtures/typescript/types-parenthesized-babel-7/input.js
vendored
Normal file
1
packages/babel-generator/test/fixtures/typescript/types-parenthesized-babel-7/input.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
type T = ({});
|
||||
3
packages/babel-generator/test/fixtures/typescript/types-parenthesized-babel-7/options.json
vendored
Normal file
3
packages/babel-generator/test/fixtures/typescript/types-parenthesized-babel-7/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"BABEL_8_BREAKING": false
|
||||
}
|
||||
1
packages/babel-generator/test/fixtures/typescript/types-parenthesized-babel-7/output.js
vendored
Normal file
1
packages/babel-generator/test/fixtures/typescript/types-parenthesized-babel-7/output.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
type T = ({});
|
||||
@ -0,0 +1 @@
|
||||
type T = ({});
|
||||
@ -0,0 +1,4 @@
|
||||
{
|
||||
"parserOpts": { "createParenthesizedExpressions": true },
|
||||
"BABEL_8_BREAKING": false
|
||||
}
|
||||
@ -0,0 +1 @@
|
||||
type T = ({});
|
||||
@ -0,0 +1 @@
|
||||
type T = ({});
|
||||
@ -0,0 +1,4 @@
|
||||
{
|
||||
"parserOpts": { "createParenthesizedExpressions": true },
|
||||
"BABEL_8_BREAKING": true
|
||||
}
|
||||
@ -0,0 +1 @@
|
||||
type T = ({});
|
||||
3
packages/babel-generator/test/fixtures/typescript/types-parenthesized/options.json
vendored
Normal file
3
packages/babel-generator/test/fixtures/typescript/types-parenthesized/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"BABEL_8_BREAKING": true
|
||||
}
|
||||
@ -1 +1 @@
|
||||
type T = ({});
|
||||
type T = {};
|
||||
|
||||
@ -842,6 +842,18 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
case tt.bracketL:
|
||||
return this.tsParseTupleType();
|
||||
case tt.parenL:
|
||||
if (process.env.BABEL_8_BREAKING) {
|
||||
if (!this.options.createParenthesizedExpressions) {
|
||||
const startPos = this.state.start;
|
||||
this.next();
|
||||
const type = this.tsParseType();
|
||||
this.expect(tt.parenR);
|
||||
this.addExtra(type, "parenthesized", true);
|
||||
this.addExtra(type, "parenStart", startPos);
|
||||
return type;
|
||||
}
|
||||
}
|
||||
|
||||
return this.tsParseParenthesizedType();
|
||||
case tt.backQuote:
|
||||
return this.tsParseTemplateLiteralType();
|
||||
|
||||
4
packages/babel-parser/test/fixtures/typescript/types/conditional-infer/options.json
vendored
Normal file
4
packages/babel-parser/test/fixtures/typescript/types/conditional-infer/options.json
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"plugins": ["typescript"],
|
||||
"createParenthesizedExpressions": true
|
||||
}
|
||||
4
packages/babel-parser/test/fixtures/typescript/types/parenthesized/options.json
vendored
Normal file
4
packages/babel-parser/test/fixtures/typescript/types/parenthesized/options.json
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"plugins": ["typescript"],
|
||||
"createParenthesizedExpressions": true
|
||||
}
|
||||
1
packages/babel-parser/test/fixtures/typescript/types/tuple-optional-babel-7/input.ts
vendored
Normal file
1
packages/babel-parser/test/fixtures/typescript/types/tuple-optional-babel-7/input.ts
vendored
Normal file
@ -0,0 +1 @@
|
||||
let x: [string, number?, (string | number)?]
|
||||
3
packages/babel-parser/test/fixtures/typescript/types/tuple-optional-babel-7/options.json
vendored
Normal file
3
packages/babel-parser/test/fixtures/typescript/types/tuple-optional-babel-7/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"BABEL_8_BREAKING": false
|
||||
}
|
||||
74
packages/babel-parser/test/fixtures/typescript/types/tuple-optional-babel-7/output.json
vendored
Normal file
74
packages/babel-parser/test/fixtures/typescript/types/tuple-optional-babel-7/output.json
vendored
Normal file
@ -0,0 +1,74 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":44,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":44}},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":44,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":44}},
|
||||
"sourceType": "module",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "VariableDeclaration",
|
||||
"start":0,"end":44,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":44}},
|
||||
"declarations": [
|
||||
{
|
||||
"type": "VariableDeclarator",
|
||||
"start":4,"end":44,"loc":{"start":{"line":1,"column":4},"end":{"line":1,"column":44}},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start":4,"end":44,"loc":{"start":{"line":1,"column":4},"end":{"line":1,"column":44},"identifierName":"x"},
|
||||
"name": "x",
|
||||
"typeAnnotation": {
|
||||
"type": "TSTypeAnnotation",
|
||||
"start":5,"end":44,"loc":{"start":{"line":1,"column":5},"end":{"line":1,"column":44}},
|
||||
"typeAnnotation": {
|
||||
"type": "TSTupleType",
|
||||
"start":7,"end":44,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":44}},
|
||||
"elementTypes": [
|
||||
{
|
||||
"type": "TSStringKeyword",
|
||||
"start":8,"end":14,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":14}}
|
||||
},
|
||||
{
|
||||
"type": "TSOptionalType",
|
||||
"start":16,"end":23,"loc":{"start":{"line":1,"column":16},"end":{"line":1,"column":23}},
|
||||
"typeAnnotation": {
|
||||
"type": "TSNumberKeyword",
|
||||
"start":16,"end":22,"loc":{"start":{"line":1,"column":16},"end":{"line":1,"column":22}}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "TSOptionalType",
|
||||
"start":25,"end":43,"loc":{"start":{"line":1,"column":25},"end":{"line":1,"column":43}},
|
||||
"typeAnnotation": {
|
||||
"type": "TSParenthesizedType",
|
||||
"start":25,"end":42,"loc":{"start":{"line":1,"column":25},"end":{"line":1,"column":42}},
|
||||
"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}}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"init": null
|
||||
}
|
||||
],
|
||||
"kind": "let"
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
3
packages/babel-parser/test/fixtures/typescript/types/tuple-optional/options.json
vendored
Normal file
3
packages/babel-parser/test/fixtures/typescript/types/tuple-optional/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"BABEL_8_BREAKING": true
|
||||
}
|
||||
@ -39,24 +39,24 @@
|
||||
},
|
||||
{
|
||||
"type": "TSOptionalType",
|
||||
"start":25,"end":43,"loc":{"start":{"line":1,"column":25},"end":{"line":1,"column":43}},
|
||||
"start":26,"end":43,"loc":{"start":{"line":1,"column":26},"end":{"line":1,"column":43}},
|
||||
"typeAnnotation": {
|
||||
"type": "TSParenthesizedType",
|
||||
"start":25,"end":42,"loc":{"start":{"line":1,"column":25},"end":{"line":1,"column":42}},
|
||||
"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}}
|
||||
}
|
||||
]
|
||||
}
|
||||
"type": "TSUnionType",
|
||||
"start":26,"end":41,"loc":{"start":{"line":1,"column":26},"end":{"line":1,"column":41}},
|
||||
"extra": {
|
||||
"parenthesized": true,
|
||||
"parenStart": 25
|
||||
},
|
||||
"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}}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user