Add missing tests for TypeScript syntax errors (#12103)
* Add missing tests for index signatures with modifiers * Add missing test for import type
This commit is contained in:
parent
1334bc99e0
commit
0d32e3fc36
7
packages/babel-parser/test/fixtures/typescript/class/modifiers-index-signatures/input.ts
vendored
Normal file
7
packages/babel-parser/test/fixtures/typescript/class/modifiers-index-signatures/input.ts
vendored
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
class C {
|
||||||
|
abstract [key: string]: string;
|
||||||
|
static [key: string]: string;
|
||||||
|
private [key: string]: string;
|
||||||
|
public [key: string]: string;
|
||||||
|
protected [key: string]: string;
|
||||||
|
}
|
||||||
175
packages/babel-parser/test/fixtures/typescript/class/modifiers-index-signatures/output.json
vendored
Normal file
175
packages/babel-parser/test/fixtures/typescript/class/modifiers-index-signatures/output.json
vendored
Normal file
@ -0,0 +1,175 @@
|
|||||||
|
{
|
||||||
|
"type": "File",
|
||||||
|
"start":0,"end":177,"loc":{"start":{"line":1,"column":0},"end":{"line":7,"column":1}},
|
||||||
|
"errors": [
|
||||||
|
"SyntaxError: Index signatures cannot have the 'abstract' modifier (2:2)",
|
||||||
|
"SyntaxError: Index signatures cannot have the 'static' modifier (3:2)",
|
||||||
|
"SyntaxError: Index signatures cannot have an accessibility modifier ('private') (4:2)",
|
||||||
|
"SyntaxError: Index signatures cannot have an accessibility modifier ('public') (5:2)",
|
||||||
|
"SyntaxError: Index signatures cannot have an accessibility modifier ('protected') (6:2)"
|
||||||
|
],
|
||||||
|
"program": {
|
||||||
|
"type": "Program",
|
||||||
|
"start":0,"end":177,"loc":{"start":{"line":1,"column":0},"end":{"line":7,"column":1}},
|
||||||
|
"sourceType": "module",
|
||||||
|
"interpreter": null,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "ClassDeclaration",
|
||||||
|
"start":0,"end":177,"loc":{"start":{"line":1,"column":0},"end":{"line":7,"column":1}},
|
||||||
|
"id": {
|
||||||
|
"type": "Identifier",
|
||||||
|
"start":6,"end":7,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":7},"identifierName":"C"},
|
||||||
|
"name": "C"
|
||||||
|
},
|
||||||
|
"superClass": null,
|
||||||
|
"body": {
|
||||||
|
"type": "ClassBody",
|
||||||
|
"start":8,"end":177,"loc":{"start":{"line":1,"column":8},"end":{"line":7,"column":1}},
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "TSIndexSignature",
|
||||||
|
"start":12,"end":43,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":33}},
|
||||||
|
"abstract": true,
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "Identifier",
|
||||||
|
"start":22,"end":33,"loc":{"start":{"line":2,"column":12},"end":{"line":2,"column":23},"identifierName":"key"},
|
||||||
|
"name": "key",
|
||||||
|
"typeAnnotation": {
|
||||||
|
"type": "TSTypeAnnotation",
|
||||||
|
"start":25,"end":33,"loc":{"start":{"line":2,"column":15},"end":{"line":2,"column":23}},
|
||||||
|
"typeAnnotation": {
|
||||||
|
"type": "TSStringKeyword",
|
||||||
|
"start":27,"end":33,"loc":{"start":{"line":2,"column":17},"end":{"line":2,"column":23}}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"typeAnnotation": {
|
||||||
|
"type": "TSTypeAnnotation",
|
||||||
|
"start":34,"end":42,"loc":{"start":{"line":2,"column":24},"end":{"line":2,"column":32}},
|
||||||
|
"typeAnnotation": {
|
||||||
|
"type": "TSStringKeyword",
|
||||||
|
"start":36,"end":42,"loc":{"start":{"line":2,"column":26},"end":{"line":2,"column":32}}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "TSIndexSignature",
|
||||||
|
"start":46,"end":75,"loc":{"start":{"line":3,"column":2},"end":{"line":3,"column":31}},
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "Identifier",
|
||||||
|
"start":54,"end":65,"loc":{"start":{"line":3,"column":10},"end":{"line":3,"column":21},"identifierName":"key"},
|
||||||
|
"name": "key",
|
||||||
|
"typeAnnotation": {
|
||||||
|
"type": "TSTypeAnnotation",
|
||||||
|
"start":57,"end":65,"loc":{"start":{"line":3,"column":13},"end":{"line":3,"column":21}},
|
||||||
|
"typeAnnotation": {
|
||||||
|
"type": "TSStringKeyword",
|
||||||
|
"start":59,"end":65,"loc":{"start":{"line":3,"column":15},"end":{"line":3,"column":21}}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"typeAnnotation": {
|
||||||
|
"type": "TSTypeAnnotation",
|
||||||
|
"start":66,"end":74,"loc":{"start":{"line":3,"column":22},"end":{"line":3,"column":30}},
|
||||||
|
"typeAnnotation": {
|
||||||
|
"type": "TSStringKeyword",
|
||||||
|
"start":68,"end":74,"loc":{"start":{"line":3,"column":24},"end":{"line":3,"column":30}}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "TSIndexSignature",
|
||||||
|
"start":78,"end":108,"loc":{"start":{"line":4,"column":2},"end":{"line":4,"column":32}},
|
||||||
|
"accessibility": "private",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "Identifier",
|
||||||
|
"start":87,"end":98,"loc":{"start":{"line":4,"column":11},"end":{"line":4,"column":22},"identifierName":"key"},
|
||||||
|
"name": "key",
|
||||||
|
"typeAnnotation": {
|
||||||
|
"type": "TSTypeAnnotation",
|
||||||
|
"start":90,"end":98,"loc":{"start":{"line":4,"column":14},"end":{"line":4,"column":22}},
|
||||||
|
"typeAnnotation": {
|
||||||
|
"type": "TSStringKeyword",
|
||||||
|
"start":92,"end":98,"loc":{"start":{"line":4,"column":16},"end":{"line":4,"column":22}}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"typeAnnotation": {
|
||||||
|
"type": "TSTypeAnnotation",
|
||||||
|
"start":99,"end":107,"loc":{"start":{"line":4,"column":23},"end":{"line":4,"column":31}},
|
||||||
|
"typeAnnotation": {
|
||||||
|
"type": "TSStringKeyword",
|
||||||
|
"start":101,"end":107,"loc":{"start":{"line":4,"column":25},"end":{"line":4,"column":31}}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "TSIndexSignature",
|
||||||
|
"start":111,"end":140,"loc":{"start":{"line":5,"column":2},"end":{"line":5,"column":31}},
|
||||||
|
"accessibility": "public",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "Identifier",
|
||||||
|
"start":119,"end":130,"loc":{"start":{"line":5,"column":10},"end":{"line":5,"column":21},"identifierName":"key"},
|
||||||
|
"name": "key",
|
||||||
|
"typeAnnotation": {
|
||||||
|
"type": "TSTypeAnnotation",
|
||||||
|
"start":122,"end":130,"loc":{"start":{"line":5,"column":13},"end":{"line":5,"column":21}},
|
||||||
|
"typeAnnotation": {
|
||||||
|
"type": "TSStringKeyword",
|
||||||
|
"start":124,"end":130,"loc":{"start":{"line":5,"column":15},"end":{"line":5,"column":21}}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"typeAnnotation": {
|
||||||
|
"type": "TSTypeAnnotation",
|
||||||
|
"start":131,"end":139,"loc":{"start":{"line":5,"column":22},"end":{"line":5,"column":30}},
|
||||||
|
"typeAnnotation": {
|
||||||
|
"type": "TSStringKeyword",
|
||||||
|
"start":133,"end":139,"loc":{"start":{"line":5,"column":24},"end":{"line":5,"column":30}}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "TSIndexSignature",
|
||||||
|
"start":143,"end":175,"loc":{"start":{"line":6,"column":2},"end":{"line":6,"column":34}},
|
||||||
|
"accessibility": "protected",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "Identifier",
|
||||||
|
"start":154,"end":165,"loc":{"start":{"line":6,"column":13},"end":{"line":6,"column":24},"identifierName":"key"},
|
||||||
|
"name": "key",
|
||||||
|
"typeAnnotation": {
|
||||||
|
"type": "TSTypeAnnotation",
|
||||||
|
"start":157,"end":165,"loc":{"start":{"line":6,"column":16},"end":{"line":6,"column":24}},
|
||||||
|
"typeAnnotation": {
|
||||||
|
"type": "TSStringKeyword",
|
||||||
|
"start":159,"end":165,"loc":{"start":{"line":6,"column":18},"end":{"line":6,"column":24}}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"typeAnnotation": {
|
||||||
|
"type": "TSTypeAnnotation",
|
||||||
|
"start":166,"end":174,"loc":{"start":{"line":6,"column":25},"end":{"line":6,"column":33}},
|
||||||
|
"typeAnnotation": {
|
||||||
|
"type": "TSStringKeyword",
|
||||||
|
"start":168,"end":174,"loc":{"start":{"line":6,"column":27},"end":{"line":6,"column":33}}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"directives": []
|
||||||
|
}
|
||||||
|
}
|
||||||
3
packages/babel-parser/test/fixtures/typescript/types/import-type-dynamic-errors/input.ts
vendored
Normal file
3
packages/babel-parser/test/fixtures/typescript/types/import-type-dynamic-errors/input.ts
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
type X = import(3);
|
||||||
|
type Y = import(`Foo`);
|
||||||
|
type Z = import(Y);
|
||||||
87
packages/babel-parser/test/fixtures/typescript/types/import-type-dynamic-errors/output.json
vendored
Normal file
87
packages/babel-parser/test/fixtures/typescript/types/import-type-dynamic-errors/output.json
vendored
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
{
|
||||||
|
"type": "File",
|
||||||
|
"start":0,"end":63,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":19}},
|
||||||
|
"errors": [
|
||||||
|
"SyntaxError: Argument in a type import must be a string literal (1:16)",
|
||||||
|
"SyntaxError: Argument in a type import must be a string literal (2:16)",
|
||||||
|
"SyntaxError: Argument in a type import must be a string literal (3:16)"
|
||||||
|
],
|
||||||
|
"program": {
|
||||||
|
"type": "Program",
|
||||||
|
"start":0,"end":63,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":19}},
|
||||||
|
"sourceType": "module",
|
||||||
|
"interpreter": null,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "TSTypeAliasDeclaration",
|
||||||
|
"start":0,"end":19,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":19}},
|
||||||
|
"id": {
|
||||||
|
"type": "Identifier",
|
||||||
|
"start":5,"end":6,"loc":{"start":{"line":1,"column":5},"end":{"line":1,"column":6},"identifierName":"X"},
|
||||||
|
"name": "X"
|
||||||
|
},
|
||||||
|
"typeAnnotation": {
|
||||||
|
"type": "TSImportType",
|
||||||
|
"start":9,"end":18,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":18}},
|
||||||
|
"argument": {
|
||||||
|
"type": "NumericLiteral",
|
||||||
|
"start":16,"end":17,"loc":{"start":{"line":1,"column":16},"end":{"line":1,"column":17}},
|
||||||
|
"extra": {
|
||||||
|
"rawValue": 3,
|
||||||
|
"raw": "3"
|
||||||
|
},
|
||||||
|
"value": 3
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "TSTypeAliasDeclaration",
|
||||||
|
"start":20,"end":43,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":23}},
|
||||||
|
"id": {
|
||||||
|
"type": "Identifier",
|
||||||
|
"start":25,"end":26,"loc":{"start":{"line":2,"column":5},"end":{"line":2,"column":6},"identifierName":"Y"},
|
||||||
|
"name": "Y"
|
||||||
|
},
|
||||||
|
"typeAnnotation": {
|
||||||
|
"type": "TSImportType",
|
||||||
|
"start":29,"end":42,"loc":{"start":{"line":2,"column":9},"end":{"line":2,"column":22}},
|
||||||
|
"argument": {
|
||||||
|
"type": "TemplateLiteral",
|
||||||
|
"start":36,"end":41,"loc":{"start":{"line":2,"column":16},"end":{"line":2,"column":21}},
|
||||||
|
"expressions": [],
|
||||||
|
"quasis": [
|
||||||
|
{
|
||||||
|
"type": "TemplateElement",
|
||||||
|
"start":37,"end":40,"loc":{"start":{"line":2,"column":17},"end":{"line":2,"column":20}},
|
||||||
|
"value": {
|
||||||
|
"raw": "Foo",
|
||||||
|
"cooked": "Foo"
|
||||||
|
},
|
||||||
|
"tail": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "TSTypeAliasDeclaration",
|
||||||
|
"start":44,"end":63,"loc":{"start":{"line":3,"column":0},"end":{"line":3,"column":19}},
|
||||||
|
"id": {
|
||||||
|
"type": "Identifier",
|
||||||
|
"start":49,"end":50,"loc":{"start":{"line":3,"column":5},"end":{"line":3,"column":6},"identifierName":"Z"},
|
||||||
|
"name": "Z"
|
||||||
|
},
|
||||||
|
"typeAnnotation": {
|
||||||
|
"type": "TSImportType",
|
||||||
|
"start":53,"end":62,"loc":{"start":{"line":3,"column":9},"end":{"line":3,"column":18}},
|
||||||
|
"argument": {
|
||||||
|
"type": "Identifier",
|
||||||
|
"start":60,"end":61,"loc":{"start":{"line":3,"column":16},"end":{"line":3,"column":17},"identifierName":"Y"},
|
||||||
|
"name": "Y"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"directives": []
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user