Skip to content

Commit

Permalink
Add "exportKind: type" when needed with TS (#11157)
Browse files Browse the repository at this point in the history
* Add "exportKind: type" to TS type export declratation

Co-authored-by: Henry Zhu <smiley.we@gmail.com>
Co-authored-by: Hu谩ng J霉nli脿ng <jlhwung@gmail.com>
Co-authored-by: Siddhant N Trivedi <sidntrivedi012@gmail.com>

* Add test to @babel/generator

Co-authored-by: Henry Zhu <hi@henryzoo.com>
Co-authored-by: Hu谩ng J霉nli脿ng <jlhwung@gmail.com>
Co-authored-by: Siddhant N Trivedi <sidntrivedi012@gmail.com>
  • Loading branch information
4 people committed Feb 26, 2020
1 parent e9ba981 commit ee1639a
Show file tree
Hide file tree
Showing 13 changed files with 766 additions and 16 deletions.
@@ -0,0 +1,2 @@
export interface A {}
export type B = string;
@@ -0,0 +1,2 @@
export interface A {}
export type B = string;
8 changes: 8 additions & 0 deletions packages/babel-parser/src/plugins/typescript/index.js
Expand Up @@ -2127,6 +2127,14 @@ export default (superClass: Class<Parser>): Class<Parser> =>
if (!declaration) {
declaration = super.parseExportDeclaration(node);
}
if (
declaration &&
(declaration.type === "TSInterfaceDeclaration" ||
declaration.type === "TSTypeAliasDeclaration" ||
isDeclare)
) {
node.exportKind = "type";
}

if (declaration && isDeclare) {
// Reset location to include `declare` in range
Expand Down
Expand Up @@ -111,7 +111,7 @@
"column": 29
}
},
"exportKind": "value",
"exportKind": "type",
"specifiers": [],
"source": null,
"declaration": {
Expand Down Expand Up @@ -229,7 +229,7 @@
"column": 21
}
},
"exportKind": "value",
"exportKind": "type",
"specifiers": [],
"source": null,
"declaration": {
Expand Down Expand Up @@ -427,7 +427,7 @@
"column": 27
}
},
"exportKind": "value",
"exportKind": "type",
"specifiers": [],
"source": null,
"declaration": {
Expand Down
Expand Up @@ -43,7 +43,7 @@
"column": 30
}
},
"exportKind": "value",
"exportKind": "type",
"specifiers": [],
"source": null,
"declaration": {
Expand Down
Expand Up @@ -43,7 +43,7 @@
"column": 31
}
},
"exportKind": "value",
"exportKind": "type",
"specifiers": [],
"source": null,
"declaration": {
Expand Down Expand Up @@ -143,7 +143,7 @@
"column": 34
}
},
"exportKind": "value",
"exportKind": "type",
"specifiers": [],
"source": null,
"declaration": {
Expand Down Expand Up @@ -227,7 +227,7 @@
"column": 25
}
},
"exportKind": "value",
"exportKind": "type",
"specifiers": [],
"source": null,
"declaration": {
Expand Down Expand Up @@ -295,7 +295,7 @@
"column": 29
}
},
"exportKind": "value",
"exportKind": "type",
"specifiers": [],
"source": null,
"declaration": {
Expand Down Expand Up @@ -362,7 +362,7 @@
"column": 31
}
},
"exportKind": "value",
"exportKind": "type",
"specifiers": [],
"source": null,
"declaration": {
Expand Down Expand Up @@ -428,7 +428,7 @@
"column": 26
}
},
"exportKind": "value",
"exportKind": "type",
"specifiers": [],
"source": null,
"declaration": {
Expand Down Expand Up @@ -495,7 +495,7 @@
"column": 29
}
},
"exportKind": "value",
"exportKind": "type",
"specifiers": [],
"source": null,
"declaration": {
Expand Down Expand Up @@ -562,7 +562,7 @@
"column": 26
}
},
"exportKind": "value",
"exportKind": "type",
"specifiers": [],
"source": null,
"declaration": {
Expand Down
@@ -0,0 +1,4 @@
export type A = 2;
export interface B {}
export declare function a(): string;
export declare var b: string;

0 comments on commit ee1639a

Please sign in to comment.