Fix export extensions handling of TS declare keyword (#757)
This commit is contained in:
parent
0fbf3a61fb
commit
60ea39aa70
@ -1191,20 +1191,29 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
return this.finishNode(node, "TSTypeParameterInstantiation");
|
||||
}
|
||||
|
||||
tsIsDeclarationStart(): boolean {
|
||||
if (this.match(tt.name)) {
|
||||
switch (this.state.value) {
|
||||
case "abstract":
|
||||
case "declare":
|
||||
case "enum":
|
||||
case "interface":
|
||||
case "module":
|
||||
case "namespace":
|
||||
case "type":
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// ======================================================
|
||||
// OVERRIDES
|
||||
// ======================================================
|
||||
|
||||
isExportDefaultSpecifier(): boolean {
|
||||
if (
|
||||
this.match(tt.name) &&
|
||||
(this.state.value === "type" ||
|
||||
this.state.value === "interface" ||
|
||||
this.state.value === "enum")
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.tsIsDeclarationStart()) return false;
|
||||
return super.isExportDefaultSpecifier();
|
||||
}
|
||||
|
||||
@ -1524,18 +1533,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
// export type
|
||||
// Should be true for anything parsed by `tsTryParseExportDeclaration`.
|
||||
shouldParseExportDeclaration(): boolean {
|
||||
if (this.match(tt.name)) {
|
||||
switch (this.state.value) {
|
||||
case "abstract":
|
||||
case "declare":
|
||||
case "enum":
|
||||
case "interface":
|
||||
case "module":
|
||||
case "namespace":
|
||||
case "type":
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (this.tsIsDeclarationStart()) return true;
|
||||
return super.shouldParseExportDeclaration();
|
||||
}
|
||||
|
||||
|
||||
7
test/fixtures/experimental/export-extensions/export-with-ts/actual.js
vendored
Normal file
7
test/fixtures/experimental/export-extensions/export-with-ts/actual.js
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
export abstract class A {}
|
||||
export declare interface B {}
|
||||
export enum C {}
|
||||
export interface D {}
|
||||
export module E {}
|
||||
export namespace F {}
|
||||
export type G = typeof foo;
|
||||
493
test/fixtures/experimental/export-extensions/export-with-ts/expected.json
vendored
Normal file
493
test/fixtures/experimental/export-extensions/export-with-ts/expected.json
vendored
Normal file
@ -0,0 +1,493 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start": 0,
|
||||
"end": 164,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 7,
|
||||
"column": 27
|
||||
}
|
||||
},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start": 0,
|
||||
"end": 164,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 7,
|
||||
"column": 27
|
||||
}
|
||||
},
|
||||
"sourceType": "module",
|
||||
"body": [
|
||||
{
|
||||
"type": "ExportNamedDeclaration",
|
||||
"start": 0,
|
||||
"end": 26,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 26
|
||||
}
|
||||
},
|
||||
"specifiers": [],
|
||||
"source": null,
|
||||
"declaration": {
|
||||
"type": "ClassDeclaration",
|
||||
"start": 7,
|
||||
"end": 26,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 7
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 26
|
||||
}
|
||||
},
|
||||
"abstract": true,
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start": 22,
|
||||
"end": 23,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 22
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 23
|
||||
},
|
||||
"identifierName": "A"
|
||||
},
|
||||
"name": "A"
|
||||
},
|
||||
"superClass": null,
|
||||
"body": {
|
||||
"type": "ClassBody",
|
||||
"start": 24,
|
||||
"end": 26,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 24
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 26
|
||||
}
|
||||
},
|
||||
"body": []
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "ExportNamedDeclaration",
|
||||
"start": 27,
|
||||
"end": 56,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 29
|
||||
}
|
||||
},
|
||||
"specifiers": [],
|
||||
"source": null,
|
||||
"declaration": {
|
||||
"type": "TSInterfaceDeclaration",
|
||||
"start": 42,
|
||||
"end": 56,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 15
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 29
|
||||
}
|
||||
},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start": 52,
|
||||
"end": 53,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 25
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 26
|
||||
},
|
||||
"identifierName": "B"
|
||||
},
|
||||
"name": "B"
|
||||
},
|
||||
"body": {
|
||||
"type": "TSInterfaceBody",
|
||||
"start": 54,
|
||||
"end": 56,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 27
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 29
|
||||
}
|
||||
},
|
||||
"body": []
|
||||
},
|
||||
"declare": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "ExportNamedDeclaration",
|
||||
"start": 57,
|
||||
"end": 73,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 3,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 16
|
||||
}
|
||||
},
|
||||
"specifiers": [],
|
||||
"source": null,
|
||||
"declaration": {
|
||||
"type": "TSEnumDeclaration",
|
||||
"start": 64,
|
||||
"end": 73,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 3,
|
||||
"column": 7
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 16
|
||||
}
|
||||
},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start": 69,
|
||||
"end": 70,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 3,
|
||||
"column": 12
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 13
|
||||
},
|
||||
"identifierName": "C"
|
||||
},
|
||||
"name": "C"
|
||||
},
|
||||
"members": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "ExportNamedDeclaration",
|
||||
"start": 74,
|
||||
"end": 95,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 4,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 4,
|
||||
"column": 21
|
||||
}
|
||||
},
|
||||
"specifiers": [],
|
||||
"source": null,
|
||||
"declaration": {
|
||||
"type": "TSInterfaceDeclaration",
|
||||
"start": 81,
|
||||
"end": 95,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 4,
|
||||
"column": 7
|
||||
},
|
||||
"end": {
|
||||
"line": 4,
|
||||
"column": 21
|
||||
}
|
||||
},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start": 91,
|
||||
"end": 92,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 4,
|
||||
"column": 17
|
||||
},
|
||||
"end": {
|
||||
"line": 4,
|
||||
"column": 18
|
||||
},
|
||||
"identifierName": "D"
|
||||
},
|
||||
"name": "D"
|
||||
},
|
||||
"body": {
|
||||
"type": "TSInterfaceBody",
|
||||
"start": 93,
|
||||
"end": 95,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 4,
|
||||
"column": 19
|
||||
},
|
||||
"end": {
|
||||
"line": 4,
|
||||
"column": 21
|
||||
}
|
||||
},
|
||||
"body": []
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "ExportNamedDeclaration",
|
||||
"start": 96,
|
||||
"end": 114,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 5,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 5,
|
||||
"column": 18
|
||||
}
|
||||
},
|
||||
"specifiers": [],
|
||||
"source": null,
|
||||
"declaration": {
|
||||
"type": "TSModuleDeclaration",
|
||||
"start": 103,
|
||||
"end": 114,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 5,
|
||||
"column": 7
|
||||
},
|
||||
"end": {
|
||||
"line": 5,
|
||||
"column": 18
|
||||
}
|
||||
},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start": 110,
|
||||
"end": 111,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 5,
|
||||
"column": 14
|
||||
},
|
||||
"end": {
|
||||
"line": 5,
|
||||
"column": 15
|
||||
},
|
||||
"identifierName": "E"
|
||||
},
|
||||
"name": "E"
|
||||
},
|
||||
"body": {
|
||||
"type": "TSModuleBlock",
|
||||
"start": 112,
|
||||
"end": 114,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 5,
|
||||
"column": 16
|
||||
},
|
||||
"end": {
|
||||
"line": 5,
|
||||
"column": 18
|
||||
}
|
||||
},
|
||||
"body": []
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "ExportNamedDeclaration",
|
||||
"start": 115,
|
||||
"end": 136,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 6,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 6,
|
||||
"column": 21
|
||||
}
|
||||
},
|
||||
"specifiers": [],
|
||||
"source": null,
|
||||
"declaration": {
|
||||
"type": "TSModuleDeclaration",
|
||||
"start": 122,
|
||||
"end": 136,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 6,
|
||||
"column": 7
|
||||
},
|
||||
"end": {
|
||||
"line": 6,
|
||||
"column": 21
|
||||
}
|
||||
},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start": 132,
|
||||
"end": 133,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 6,
|
||||
"column": 17
|
||||
},
|
||||
"end": {
|
||||
"line": 6,
|
||||
"column": 18
|
||||
},
|
||||
"identifierName": "F"
|
||||
},
|
||||
"name": "F"
|
||||
},
|
||||
"body": {
|
||||
"type": "TSModuleBlock",
|
||||
"start": 134,
|
||||
"end": 136,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 6,
|
||||
"column": 19
|
||||
},
|
||||
"end": {
|
||||
"line": 6,
|
||||
"column": 21
|
||||
}
|
||||
},
|
||||
"body": []
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "ExportNamedDeclaration",
|
||||
"start": 137,
|
||||
"end": 164,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 7,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 7,
|
||||
"column": 27
|
||||
}
|
||||
},
|
||||
"specifiers": [],
|
||||
"source": null,
|
||||
"declaration": {
|
||||
"type": "TSTypeAliasDeclaration",
|
||||
"start": 144,
|
||||
"end": 164,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 7,
|
||||
"column": 7
|
||||
},
|
||||
"end": {
|
||||
"line": 7,
|
||||
"column": 27
|
||||
}
|
||||
},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start": 149,
|
||||
"end": 150,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 7,
|
||||
"column": 12
|
||||
},
|
||||
"end": {
|
||||
"line": 7,
|
||||
"column": 13
|
||||
},
|
||||
"identifierName": "G"
|
||||
},
|
||||
"name": "G"
|
||||
},
|
||||
"typeAnnotation": {
|
||||
"type": "TSTypeQuery",
|
||||
"start": 153,
|
||||
"end": 163,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 7,
|
||||
"column": 16
|
||||
},
|
||||
"end": {
|
||||
"line": 7,
|
||||
"column": 26
|
||||
}
|
||||
},
|
||||
"exprName": {
|
||||
"type": "Identifier",
|
||||
"start": 160,
|
||||
"end": 163,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 7,
|
||||
"column": 23
|
||||
},
|
||||
"end": {
|
||||
"line": 7,
|
||||
"column": 26
|
||||
},
|
||||
"identifierName": "foo"
|
||||
},
|
||||
"name": "foo"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
4
test/fixtures/experimental/export-extensions/export-with-ts/options.json
vendored
Normal file
4
test/fixtures/experimental/export-extensions/export-with-ts/options.json
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"plugins": ["exportExtensions", "typescript"],
|
||||
"sourceType": "module"
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user