[typescript] parsing template literal as type (#9748)

This commit is contained in:
Tan Li Hau
2019-03-26 06:21:11 +08:00
committed by Nicolò Ribaudo
parent 444daf9224
commit 2867bbf195
6 changed files with 179 additions and 1 deletions

View File

@@ -0,0 +1 @@
let x: `foo`;

View File

@@ -0,0 +1,154 @@
{
"type": "File",
"start": 0,
"end": 13,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 13
}
},
"program": {
"type": "Program",
"start": 0,
"end": 13,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 13
}
},
"sourceType": "module",
"interpreter": null,
"body": [
{
"type": "VariableDeclaration",
"start": 0,
"end": 13,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 13
}
},
"declarations": [
{
"type": "VariableDeclarator",
"start": 4,
"end": 12,
"loc": {
"start": {
"line": 1,
"column": 4
},
"end": {
"line": 1,
"column": 12
}
},
"id": {
"type": "Identifier",
"start": 4,
"end": 12,
"loc": {
"start": {
"line": 1,
"column": 4
},
"end": {
"line": 1,
"column": 12
},
"identifierName": "x"
},
"name": "x",
"typeAnnotation": {
"type": "TSTypeAnnotation",
"start": 5,
"end": 12,
"loc": {
"start": {
"line": 1,
"column": 5
},
"end": {
"line": 1,
"column": 12
}
},
"typeAnnotation": {
"type": "TSLiteralType",
"start": 7,
"end": 12,
"loc": {
"start": {
"line": 1,
"column": 7
},
"end": {
"line": 1,
"column": 12
}
},
"literal": {
"type": "TemplateLiteral",
"start": 7,
"end": 12,
"loc": {
"start": {
"line": 1,
"column": 7
},
"end": {
"line": 1,
"column": 12
}
},
"expressions": [],
"quasis": [
{
"type": "TemplateElement",
"start": 8,
"end": 11,
"loc": {
"start": {
"line": 1,
"column": 8
},
"end": {
"line": 1,
"column": 11
}
},
"value": {
"raw": "foo",
"cooked": "foo"
},
"tail": true
}
]
}
}
}
},
"init": null
}
],
"kind": "let"
}
],
"directives": []
}
}

View File

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

View File

@@ -0,0 +1,7 @@
{
"sourceType": "module",
"plugins": [
"typescript"
],
"throws": "Template literal types cannot have any substitution (1:14)"
}