[ts] Add support for template interpolations in types (#12131)

Co-authored-by: Brian Ng <bng412@gmail.com>
This commit is contained in:
Nicolò Ribaudo
2020-10-14 20:15:42 +02:00
committed by GitHub
parent 9f40d6fcd0
commit 3fd963fdc8
10 changed files with 106 additions and 19 deletions

View File

@@ -1,9 +1,6 @@
{
"type": "File",
"start":0,"end":20,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":20}},
"errors": [
"SyntaxError: Template literal types cannot have any substitution (1:14)"
],
"program": {
"type": "Program",
"start":0,"end":20,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":20}},
@@ -32,9 +29,13 @@
"start":7,"end":19,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":19}},
"expressions": [
{
"type": "Identifier",
"start":14,"end":17,"loc":{"start":{"line":1,"column":14},"end":{"line":1,"column":17},"identifierName":"bar"},
"name": "bar"
"type": "TSTypeReference",
"start":14,"end":17,"loc":{"start":{"line":1,"column":14},"end":{"line":1,"column":17}},
"typeName": {
"type": "Identifier",
"start":14,"end":17,"loc":{"start":{"line":1,"column":14},"end":{"line":1,"column":17},"identifierName":"bar"},
"name": "bar"
}
}
],
"quasis": [

View File

@@ -0,0 +1 @@
let x: `foo-${bar + baz}`;

View File

@@ -0,0 +1,3 @@
{
"throws": "Unexpected token, expected \"}\" (1:18)"
}

View File

@@ -0,0 +1 @@
let x: `foo-${infer bar}`;

View File

@@ -0,0 +1,73 @@
{
"type": "File",
"start":0,"end":26,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":26}},
"program": {
"type": "Program",
"start":0,"end":26,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":26}},
"sourceType": "module",
"interpreter": null,
"body": [
{
"type": "VariableDeclaration",
"start":0,"end":26,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":26}},
"declarations": [
{
"type": "VariableDeclarator",
"start":4,"end":25,"loc":{"start":{"line":1,"column":4},"end":{"line":1,"column":25}},
"id": {
"type": "Identifier",
"start":4,"end":25,"loc":{"start":{"line":1,"column":4},"end":{"line":1,"column":25},"identifierName":"x"},
"name": "x",
"typeAnnotation": {
"type": "TSTypeAnnotation",
"start":5,"end":25,"loc":{"start":{"line":1,"column":5},"end":{"line":1,"column":25}},
"typeAnnotation": {
"type": "TSLiteralType",
"start":7,"end":25,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":25}},
"literal": {
"type": "TemplateLiteral",
"start":7,"end":25,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":25}},
"expressions": [
{
"type": "TSInferType",
"start":14,"end":23,"loc":{"start":{"line":1,"column":14},"end":{"line":1,"column":23}},
"typeParameter": {
"type": "TSTypeParameter",
"start":20,"end":23,"loc":{"start":{"line":1,"column":20},"end":{"line":1,"column":23}},
"name": "bar"
}
}
],
"quasis": [
{
"type": "TemplateElement",
"start":8,"end":12,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":12}},
"value": {
"raw": "foo-",
"cooked": "foo-"
},
"tail": false
},
{
"type": "TemplateElement",
"start":24,"end":24,"loc":{"start":{"line":1,"column":24},"end":{"line":1,"column":24}},
"value": {
"raw": "",
"cooked": ""
},
"tail": true
}
]
}
}
}
},
"init": null
}
],
"kind": "let"
}
],
"directives": []
}
}