-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Babel 8] Create TSTemplateLiteralType (#17066)
* breaking: create TSTemplateLiteralType * update test fixtures * ignore TSTemplateLiteralType in printer test * purge failing prettier tests * rename expressions to types * fix: generate TSLiteralType when the template does not contain types * restore template literals transform * update test fixtures * define TSTemplateLiteralType for Babel 7 Since the generator requires the types information * refactor: extract _printTemplate helper * Apply template literal range fixes to TSTemplateLiteralType
- Loading branch information
Showing
32 changed files
with
553 additions
and
128 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
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
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
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
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
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
packages/babel-parser/test/fixtures/typescript/types/literal-string-1-babel-7/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 @@ | ||
let x: `foo`; |
3 changes: 3 additions & 0 deletions
3
packages/babel-parser/test/fixtures/typescript/types/literal-string-1-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,3 @@ | ||
{ | ||
"BABEL_8_BREAKING": false | ||
} |
57 changes: 57 additions & 0 deletions
57
packages/babel-parser/test/fixtures/typescript/types/literal-string-1-babel-7/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,57 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":13,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":13,"index":13}}, | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":13,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":13,"index":13}}, | ||
"sourceType": "module", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "VariableDeclaration", | ||
"start":0,"end":13,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":13,"index":13}}, | ||
"declarations": [ | ||
{ | ||
"type": "VariableDeclarator", | ||
"start":4,"end":12,"loc":{"start":{"line":1,"column":4,"index":4},"end":{"line":1,"column":12,"index":12}}, | ||
"id": { | ||
"type": "Identifier", | ||
"start":4,"end":12,"loc":{"start":{"line":1,"column":4,"index":4},"end":{"line":1,"column":12,"index":12},"identifierName":"x"}, | ||
"name": "x", | ||
"typeAnnotation": { | ||
"type": "TSTypeAnnotation", | ||
"start":5,"end":12,"loc":{"start":{"line":1,"column":5,"index":5},"end":{"line":1,"column":12,"index":12}}, | ||
"typeAnnotation": { | ||
"type": "TSLiteralType", | ||
"start":7,"end":12,"loc":{"start":{"line":1,"column":7,"index":7},"end":{"line":1,"column":12,"index":12}}, | ||
"literal": { | ||
"type": "TemplateLiteral", | ||
"start":7,"end":12,"loc":{"start":{"line":1,"column":7,"index":7},"end":{"line":1,"column":12,"index":12}}, | ||
"expressions": [], | ||
"quasis": [ | ||
{ | ||
"type": "TemplateElement", | ||
"start":8,"end":11,"loc":{"start":{"line":1,"column":8,"index":8},"end":{"line":1,"column":11,"index":11}}, | ||
"value": { | ||
"raw": "foo", | ||
"cooked": "foo" | ||
}, | ||
"tail": true | ||
} | ||
] | ||
} | ||
} | ||
} | ||
}, | ||
"init": null | ||
} | ||
], | ||
"kind": "let" | ||
} | ||
], | ||
"directives": [], | ||
"extra": { | ||
"topLevelAwait": false | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/babel-parser/test/fixtures/typescript/types/literal-string-1/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 @@ | ||
{ | ||
"BABEL_8_BREAKING": true | ||
} |
1 change: 1 addition & 0 deletions
1
packages/babel-parser/test/fixtures/typescript/types/literal-string-2-babel-7/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 @@ | ||
let x: `foo-${bar}`; |
3 changes: 3 additions & 0 deletions
3
packages/babel-parser/test/fixtures/typescript/types/literal-string-2-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,3 @@ | ||
{ | ||
"BABEL_8_BREAKING": false | ||
} |
76 changes: 76 additions & 0 deletions
76
packages/babel-parser/test/fixtures/typescript/types/literal-string-2-babel-7/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,76 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":20,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":20,"index":20}}, | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":20,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":20,"index":20}}, | ||
"sourceType": "module", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "VariableDeclaration", | ||
"start":0,"end":20,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":20,"index":20}}, | ||
"declarations": [ | ||
{ | ||
"type": "VariableDeclarator", | ||
"start":4,"end":19,"loc":{"start":{"line":1,"column":4,"index":4},"end":{"line":1,"column":19,"index":19}}, | ||
"id": { | ||
"type": "Identifier", | ||
"start":4,"end":19,"loc":{"start":{"line":1,"column":4,"index":4},"end":{"line":1,"column":19,"index":19},"identifierName":"x"}, | ||
"name": "x", | ||
"typeAnnotation": { | ||
"type": "TSTypeAnnotation", | ||
"start":5,"end":19,"loc":{"start":{"line":1,"column":5,"index":5},"end":{"line":1,"column":19,"index":19}}, | ||
"typeAnnotation": { | ||
"type": "TSLiteralType", | ||
"start":7,"end":19,"loc":{"start":{"line":1,"column":7,"index":7},"end":{"line":1,"column":19,"index":19}}, | ||
"literal": { | ||
"type": "TemplateLiteral", | ||
"start":7,"end":19,"loc":{"start":{"line":1,"column":7,"index":7},"end":{"line":1,"column":19,"index":19}}, | ||
"expressions": [ | ||
{ | ||
"type": "TSTypeReference", | ||
"start":14,"end":17,"loc":{"start":{"line":1,"column":14,"index":14},"end":{"line":1,"column":17,"index":17}}, | ||
"typeName": { | ||
"type": "Identifier", | ||
"start":14,"end":17,"loc":{"start":{"line":1,"column":14,"index":14},"end":{"line":1,"column":17,"index":17},"identifierName":"bar"}, | ||
"name": "bar" | ||
} | ||
} | ||
], | ||
"quasis": [ | ||
{ | ||
"type": "TemplateElement", | ||
"start":8,"end":12,"loc":{"start":{"line":1,"column":8,"index":8},"end":{"line":1,"column":12,"index":12}}, | ||
"value": { | ||
"raw": "foo-", | ||
"cooked": "foo-" | ||
}, | ||
"tail": false | ||
}, | ||
{ | ||
"type": "TemplateElement", | ||
"start":18,"end":18,"loc":{"start":{"line":1,"column":18,"index":18},"end":{"line":1,"column":18,"index":18}}, | ||
"value": { | ||
"raw": "", | ||
"cooked": "" | ||
}, | ||
"tail": true | ||
} | ||
] | ||
} | ||
} | ||
} | ||
}, | ||
"init": null | ||
} | ||
], | ||
"kind": "let" | ||
} | ||
], | ||
"directives": [], | ||
"extra": { | ||
"topLevelAwait": false | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/babel-parser/test/fixtures/typescript/types/literal-string-2/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 @@ | ||
{ | ||
"BABEL_8_BREAKING": true | ||
} |
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
Oops, something went wrong.