Skip to content
This repository has been archived by the owner on May 19, 2018. It is now read-only.

Commit

Permalink
Fix export extensions handling of TS declare keyword (#757)
Browse files Browse the repository at this point in the history
  • Loading branch information
existentialism authored and hzoo committed Oct 14, 2017
1 parent 0fbf3a6 commit 60ea39a
Show file tree
Hide file tree
Showing 5 changed files with 524 additions and 22 deletions.
40 changes: 19 additions & 21 deletions src/plugins/typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Loading

0 comments on commit 60ea39a

Please sign in to comment.