fix(parser): throw error with wrong typescript 'export declare' (#12684)
This commit is contained in:
1
packages/babel-parser/test/fixtures/typescript/export/declare-invalid/input.ts
vendored
Normal file
1
packages/babel-parser/test/fixtures/typescript/export/declare-invalid/input.ts
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export declare foo;
|
||||
7
packages/babel-parser/test/fixtures/typescript/export/declare-invalid/options.json
vendored
Normal file
7
packages/babel-parser/test/fixtures/typescript/export/declare-invalid/options.json
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"sourceType": "module",
|
||||
"plugins": [
|
||||
"typescript"
|
||||
],
|
||||
"throws": "'export declare' must be followed by an ambient declaration. (1:15)"
|
||||
}
|
||||
@@ -6,3 +6,5 @@ export declare type T = number;
|
||||
export declare module M {}
|
||||
export declare namespace N {}
|
||||
export declare enum foo {}
|
||||
export declare var bar: string;
|
||||
export declare var _bar;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":238,"loc":{"start":{"line":1,"column":0},"end":{"line":8,"column":26}},
|
||||
"start":0,"end":295,"loc":{"start":{"line":1,"column":0},"end":{"line":10,"column":24}},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":238,"loc":{"start":{"line":1,"column":0},"end":{"line":8,"column":26}},
|
||||
"start":0,"end":295,"loc":{"start":{"line":1,"column":0},"end":{"line":10,"column":24}},
|
||||
"sourceType": "module",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
@@ -195,6 +195,64 @@
|
||||
"members": [],
|
||||
"declare": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "ExportNamedDeclaration",
|
||||
"start":239,"end":270,"loc":{"start":{"line":9,"column":0},"end":{"line":9,"column":31}},
|
||||
"exportKind": "type",
|
||||
"specifiers": [],
|
||||
"source": null,
|
||||
"declaration": {
|
||||
"type": "VariableDeclaration",
|
||||
"start":246,"end":270,"loc":{"start":{"line":9,"column":7},"end":{"line":9,"column":31}},
|
||||
"declarations": [
|
||||
{
|
||||
"type": "VariableDeclarator",
|
||||
"start":258,"end":269,"loc":{"start":{"line":9,"column":19},"end":{"line":9,"column":30}},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start":258,"end":269,"loc":{"start":{"line":9,"column":19},"end":{"line":9,"column":30},"identifierName":"bar"},
|
||||
"name": "bar",
|
||||
"typeAnnotation": {
|
||||
"type": "TSTypeAnnotation",
|
||||
"start":261,"end":269,"loc":{"start":{"line":9,"column":22},"end":{"line":9,"column":30}},
|
||||
"typeAnnotation": {
|
||||
"type": "TSStringKeyword",
|
||||
"start":263,"end":269,"loc":{"start":{"line":9,"column":24},"end":{"line":9,"column":30}}
|
||||
}
|
||||
}
|
||||
},
|
||||
"init": null
|
||||
}
|
||||
],
|
||||
"kind": "var",
|
||||
"declare": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "ExportNamedDeclaration",
|
||||
"start":271,"end":295,"loc":{"start":{"line":10,"column":0},"end":{"line":10,"column":24}},
|
||||
"exportKind": "type",
|
||||
"specifiers": [],
|
||||
"source": null,
|
||||
"declaration": {
|
||||
"type": "VariableDeclaration",
|
||||
"start":278,"end":295,"loc":{"start":{"line":10,"column":7},"end":{"line":10,"column":24}},
|
||||
"declarations": [
|
||||
{
|
||||
"type": "VariableDeclarator",
|
||||
"start":290,"end":294,"loc":{"start":{"line":10,"column":19},"end":{"line":10,"column":23}},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start":290,"end":294,"loc":{"start":{"line":10,"column":19},"end":{"line":10,"column":23},"identifierName":"_bar"},
|
||||
"name": "_bar"
|
||||
},
|
||||
"init": null
|
||||
}
|
||||
],
|
||||
"kind": "var",
|
||||
"declare": true
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
|
||||
1
packages/babel-parser/test/fixtures/typescript/export/double-declare/input.ts
vendored
Normal file
1
packages/babel-parser/test/fixtures/typescript/export/double-declare/input.ts
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export declare declare var name;
|
||||
7
packages/babel-parser/test/fixtures/typescript/export/double-declare/options.json
vendored
Normal file
7
packages/babel-parser/test/fixtures/typescript/export/double-declare/options.json
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"sourceType": "module",
|
||||
"plugins": [
|
||||
"typescript"
|
||||
],
|
||||
"throws": "'export declare' must be followed by an ambient declaration. (1:15)"
|
||||
}
|
||||
Reference in New Issue
Block a user