Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ts): skip func-type param start on parsing (#14293)
* fix(ts): skip func-type param start on parsing Currently we skip the param start at tokenizing level, assuming `}` only matches `{` and `]` only matches `[`. However, as ES evolves such assumptions are no longer valid. Furthermore, we reinterpret `}` as template continuation in parseTemplateSubstitution, therefore, the skip param routine should be moved to parsing level instead of tokenizing. * fix: tt.braceL is consumed in parseObjectLike
- Loading branch information
Showing
30 changed files
with
659 additions
and
21 deletions.
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
1 change: 1 addition & 0 deletions
1
...est/fixtures/typescript/types-arrow-function-babel-7/array-pattern-with-es-tuple/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 @@ | ||
type F = ([ x = #[0] ]) => {} |
4 changes: 4 additions & 0 deletions
4
...fixtures/typescript/types-arrow-function-babel-7/array-pattern-with-es-tuple/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,4 @@ | ||
{ | ||
"sourceType": "module", | ||
"plugins": ["typescript", ["recordAndTuple", { "syntaxType": "hash" }]] | ||
} |
67 changes: 67 additions & 0 deletions
67
.../fixtures/typescript/types-arrow-function-babel-7/array-pattern-with-es-tuple/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,67 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":29,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":29,"index":29}}, | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":29,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":29,"index":29}}, | ||
"sourceType": "module", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "TSTypeAliasDeclaration", | ||
"start":0,"end":29,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":29,"index":29}}, | ||
"id": { | ||
"type": "Identifier", | ||
"start":5,"end":6,"loc":{"start":{"line":1,"column":5,"index":5},"end":{"line":1,"column":6,"index":6},"identifierName":"F"}, | ||
"name": "F" | ||
}, | ||
"typeAnnotation": { | ||
"type": "TSFunctionType", | ||
"start":9,"end":29,"loc":{"start":{"line":1,"column":9,"index":9},"end":{"line":1,"column":29,"index":29}}, | ||
"parameters": [ | ||
{ | ||
"type": "ArrayPattern", | ||
"start":10,"end":22,"loc":{"start":{"line":1,"column":10,"index":10},"end":{"line":1,"column":22,"index":22}}, | ||
"elements": [ | ||
{ | ||
"type": "AssignmentPattern", | ||
"start":12,"end":20,"loc":{"start":{"line":1,"column":12,"index":12},"end":{"line":1,"column":20,"index":20}}, | ||
"left": { | ||
"type": "Identifier", | ||
"start":12,"end":13,"loc":{"start":{"line":1,"column":12,"index":12},"end":{"line":1,"column":13,"index":13},"identifierName":"x"}, | ||
"name": "x" | ||
}, | ||
"right": { | ||
"type": "TupleExpression", | ||
"start":16,"end":20,"loc":{"start":{"line":1,"column":16,"index":16},"end":{"line":1,"column":20,"index":20}}, | ||
"elements": [ | ||
{ | ||
"type": "NumericLiteral", | ||
"start":18,"end":19,"loc":{"start":{"line":1,"column":18,"index":18},"end":{"line":1,"column":19,"index":19}}, | ||
"extra": { | ||
"rawValue": 0, | ||
"raw": "0" | ||
}, | ||
"value": 0 | ||
} | ||
] | ||
} | ||
} | ||
] | ||
} | ||
], | ||
"typeAnnotation": { | ||
"type": "TSTypeAnnotation", | ||
"start":24,"end":29,"loc":{"start":{"line":1,"column":24,"index":24},"end":{"line":1,"column":29,"index":29}}, | ||
"typeAnnotation": { | ||
"type": "TSTypeLiteral", | ||
"start":27,"end":29,"loc":{"start":{"line":1,"column":27,"index":27},"end":{"line":1,"column":29,"index":29}}, | ||
"members": [] | ||
} | ||
} | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...t/fixtures/typescript/types-arrow-function-babel-7/invalid-incomplete-array-like/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 @@ | ||
type F = ([ |
3 changes: 3 additions & 0 deletions
3
...xtures/typescript/types-arrow-function-babel-7/invalid-incomplete-array-like/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 @@ | ||
{ | ||
"throws": "Unexpected token (1:11)" | ||
} |
1 change: 1 addition & 0 deletions
1
.../fixtures/typescript/types-arrow-function-babel-7/invalid-incomplete-object-like/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 @@ | ||
type F = ({ |
3 changes: 3 additions & 0 deletions
3
...tures/typescript/types-arrow-function-babel-7/invalid-incomplete-object-like/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 @@ | ||
{ | ||
"throws": "Unexpected token (1:11)" | ||
} |
1 change: 1 addition & 0 deletions
1
...t/fixtures/typescript/types-arrow-function-babel-7/object-pattern-with-es-record/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 @@ | ||
type F = ({ x = #{} }) => {} |
12 changes: 12 additions & 0 deletions
12
...xtures/typescript/types-arrow-function-babel-7/object-pattern-with-es-record/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,12 @@ | ||
{ | ||
"sourceType": "module", | ||
"plugins": [ | ||
"typescript", | ||
[ | ||
"recordAndTuple", | ||
{ | ||
"syntaxType": "hash" | ||
} | ||
] | ||
] | ||
} |
72 changes: 72 additions & 0 deletions
72
...ixtures/typescript/types-arrow-function-babel-7/object-pattern-with-es-record/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,72 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":28,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":28,"index":28}}, | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":28,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":28,"index":28}}, | ||
"sourceType": "module", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "TSTypeAliasDeclaration", | ||
"start":0,"end":28,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":28,"index":28}}, | ||
"id": { | ||
"type": "Identifier", | ||
"start":5,"end":6,"loc":{"start":{"line":1,"column":5,"index":5},"end":{"line":1,"column":6,"index":6},"identifierName":"F"}, | ||
"name": "F" | ||
}, | ||
"typeAnnotation": { | ||
"type": "TSFunctionType", | ||
"start":9,"end":28,"loc":{"start":{"line":1,"column":9,"index":9},"end":{"line":1,"column":28,"index":28}}, | ||
"parameters": [ | ||
{ | ||
"type": "ObjectPattern", | ||
"start":10,"end":21,"loc":{"start":{"line":1,"column":10,"index":10},"end":{"line":1,"column":21,"index":21}}, | ||
"properties": [ | ||
{ | ||
"type": "ObjectProperty", | ||
"start":12,"end":19,"loc":{"start":{"line":1,"column":12,"index":12},"end":{"line":1,"column":19,"index":19}}, | ||
"key": { | ||
"type": "Identifier", | ||
"start":12,"end":13,"loc":{"start":{"line":1,"column":12,"index":12},"end":{"line":1,"column":13,"index":13},"identifierName":"x"}, | ||
"name": "x" | ||
}, | ||
"computed": false, | ||
"method": false, | ||
"shorthand": true, | ||
"value": { | ||
"type": "AssignmentPattern", | ||
"start":12,"end":19,"loc":{"start":{"line":1,"column":12,"index":12},"end":{"line":1,"column":19,"index":19}}, | ||
"left": { | ||
"type": "Identifier", | ||
"start":12,"end":13,"loc":{"start":{"line":1,"column":12,"index":12},"end":{"line":1,"column":13,"index":13},"identifierName":"x"}, | ||
"name": "x" | ||
}, | ||
"right": { | ||
"type": "RecordExpression", | ||
"start":16,"end":19,"loc":{"start":{"line":1,"column":16,"index":16},"end":{"line":1,"column":19,"index":19}}, | ||
"properties": [] | ||
} | ||
}, | ||
"extra": { | ||
"shorthand": true | ||
} | ||
} | ||
] | ||
} | ||
], | ||
"typeAnnotation": { | ||
"type": "TSTypeAnnotation", | ||
"start":23,"end":28,"loc":{"start":{"line":1,"column":23,"index":23},"end":{"line":1,"column":28,"index":28}}, | ||
"typeAnnotation": { | ||
"type": "TSTypeLiteral", | ||
"start":26,"end":28,"loc":{"start":{"line":1,"column":26,"index":26},"end":{"line":1,"column":28,"index":28}}, | ||
"members": [] | ||
} | ||
} | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...st/fixtures/typescript/types-arrow-function-babel-7/object-pattern-with-template/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 @@ | ||
type F = ({ x = `${0}` }) => {} |
106 changes: 106 additions & 0 deletions
106
...fixtures/typescript/types-arrow-function-babel-7/object-pattern-with-template/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,106 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":31,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":31,"index":31}}, | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":31,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":31,"index":31}}, | ||
"sourceType": "module", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "TSTypeAliasDeclaration", | ||
"start":0,"end":31,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":31,"index":31}}, | ||
"id": { | ||
"type": "Identifier", | ||
"start":5,"end":6,"loc":{"start":{"line":1,"column":5,"index":5},"end":{"line":1,"column":6,"index":6},"identifierName":"F"}, | ||
"name": "F" | ||
}, | ||
"typeAnnotation": { | ||
"type": "TSFunctionType", | ||
"start":9,"end":31,"loc":{"start":{"line":1,"column":9,"index":9},"end":{"line":1,"column":31,"index":31}}, | ||
"parameters": [ | ||
{ | ||
"type": "ObjectPattern", | ||
"start":10,"end":24,"loc":{"start":{"line":1,"column":10,"index":10},"end":{"line":1,"column":24,"index":24}}, | ||
"properties": [ | ||
{ | ||
"type": "ObjectProperty", | ||
"start":12,"end":22,"loc":{"start":{"line":1,"column":12,"index":12},"end":{"line":1,"column":22,"index":22}}, | ||
"key": { | ||
"type": "Identifier", | ||
"start":12,"end":13,"loc":{"start":{"line":1,"column":12,"index":12},"end":{"line":1,"column":13,"index":13},"identifierName":"x"}, | ||
"name": "x" | ||
}, | ||
"computed": false, | ||
"method": false, | ||
"shorthand": true, | ||
"value": { | ||
"type": "AssignmentPattern", | ||
"start":12,"end":22,"loc":{"start":{"line":1,"column":12,"index":12},"end":{"line":1,"column":22,"index":22}}, | ||
"left": { | ||
"type": "Identifier", | ||
"start":12,"end":13,"loc":{"start":{"line":1,"column":12,"index":12},"end":{"line":1,"column":13,"index":13},"identifierName":"x"}, | ||
"name": "x" | ||
}, | ||
"right": { | ||
"type": "TemplateLiteral", | ||
"start":16,"end":22,"loc":{"start":{"line":1,"column":16,"index":16},"end":{"line":1,"column":22,"index":22}}, | ||
"expressions": [ | ||
{ | ||
"type": "TSLiteralType", | ||
"start":19,"end":20,"loc":{"start":{"line":1,"column":19,"index":19},"end":{"line":1,"column":20,"index":20}}, | ||
"literal": { | ||
"type": "NumericLiteral", | ||
"start":19,"end":20,"loc":{"start":{"line":1,"column":19,"index":19},"end":{"line":1,"column":20,"index":20}}, | ||
"extra": { | ||
"rawValue": 0, | ||
"raw": "0" | ||
}, | ||
"value": 0 | ||
} | ||
} | ||
], | ||
"quasis": [ | ||
{ | ||
"type": "TemplateElement", | ||
"start":17,"end":17,"loc":{"start":{"line":1,"column":17,"index":17},"end":{"line":1,"column":17,"index":17}}, | ||
"value": { | ||
"raw": "", | ||
"cooked": "" | ||
}, | ||
"tail": false | ||
}, | ||
{ | ||
"type": "TemplateElement", | ||
"start":21,"end":21,"loc":{"start":{"line":1,"column":21,"index":21},"end":{"line":1,"column":21,"index":21}}, | ||
"value": { | ||
"raw": "", | ||
"cooked": "" | ||
}, | ||
"tail": true | ||
} | ||
] | ||
} | ||
}, | ||
"extra": { | ||
"shorthand": true | ||
} | ||
} | ||
] | ||
} | ||
], | ||
"typeAnnotation": { | ||
"type": "TSTypeAnnotation", | ||
"start":26,"end":31,"loc":{"start":{"line":1,"column":26,"index":26},"end":{"line":1,"column":31,"index":31}}, | ||
"typeAnnotation": { | ||
"type": "TSTypeLiteral", | ||
"start":29,"end":31,"loc":{"start":{"line":1,"column":29,"index":29},"end":{"line":1,"column":31,"index":31}}, | ||
"members": [] | ||
} | ||
} | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
packages/babel-parser/test/fixtures/typescript/types-arrow-function-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,5 @@ | ||
{ | ||
"sourceType": "module", | ||
"plugins": ["typescript"], | ||
"BABEL_8_BREAKING": false | ||
} |
1 change: 1 addition & 0 deletions
1
...parser/test/fixtures/typescript/types-arrow-function/array-pattern-with-es-tuple/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 @@ | ||
type F = ([ x = #[0] ]) => {} |
4 changes: 4 additions & 0 deletions
4
...er/test/fixtures/typescript/types-arrow-function/array-pattern-with-es-tuple/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,4 @@ | ||
{ | ||
"sourceType": "module", | ||
"plugins": ["typescript", ["recordAndTuple", { "syntaxType": "hash" }]] | ||
} |
Oops, something went wrong.