Skip to content

Commit

Permalink
feat: set kind type for exported type alias/interface decls
Browse files Browse the repository at this point in the history
  • Loading branch information
bradzacher committed Mar 9, 2020
1 parent e129d73 commit 390ba8a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
5 changes: 4 additions & 1 deletion packages/typescript-estree/src/convert.ts
Expand Up @@ -172,12 +172,15 @@ export class Converter {
range: [exportKeyword.getStart(this.ast), result.range[1]],
});
} else {
const isType =
result.type === AST_NODE_TYPES.TSInterfaceDeclaration ||
result.type === AST_NODE_TYPES.TSTypeAliasDeclaration;
return this.createNode<TSESTree.ExportNamedDeclaration>(node, {
type: AST_NODE_TYPES.ExportNamedDeclaration,
declaration: result,
specifiers: [],
source: null,
exportKind: 'value',
exportKind: isType ? 'type' : 'value',
range: [exportKeyword.getStart(this.ast), result.range[1]],
});
}
Expand Down
22 changes: 18 additions & 4 deletions packages/typescript-estree/tests/ast-alignment/utils.ts
Expand Up @@ -252,20 +252,34 @@ export function preprocessBabylonAST(ast: BabelTypes.File): any {
* TS 3.8 import/export type
* babel coming soon https://github.com/babel/babel/pull/11171
*/
ExportNamedDeclaration(node) {
ExportNamedDeclaration(node: any) {
/**
* TS 3.8: export type
*/
if (!node.exportKind) {
node.exportKind = 'value';
if (
node.declaration?.type === AST_NODE_TYPES.TSTypeAliasDeclaration ||
node.declaration?.type === AST_NODE_TYPES.TSInterfaceDeclaration
) {
node.exportKind = 'type';
} else {
node.exportKind = 'value';
}
}
},
ExportAllDeclaration(node) {
ExportAllDeclaration(node: any) {
/**
* TS 3.8: export type
*/
if (!node.exportKind) {
node.exportKind = 'value';
if (
node.declaration?.type === AST_NODE_TYPES.TSTypeAliasDeclaration ||
node.declaration?.type === AST_NODE_TYPES.TSInterfaceDeclaration
) {
node.exportKind = 'type';
} else {
node.exportKind = 'value';
}
}
},
ImportDeclaration(node) {
Expand Down
Expand Up @@ -4476,7 +4476,7 @@ Object {
],
"type": "TSInterfaceDeclaration",
},
"exportKind": "value",
"exportKind": "type",
"loc": Object {
"end": Object {
"column": 1,
Expand Down Expand Up @@ -98017,7 +98017,7 @@ Object {
],
},
},
"exportKind": "value",
"exportKind": "type",
"loc": Object {
"end": Object {
"column": 40,
Expand Down Expand Up @@ -98346,7 +98346,7 @@ Object {
"type": "TSFunctionType",
},
},
"exportKind": "value",
"exportKind": "type",
"loc": Object {
"end": Object {
"column": 47,
Expand Down Expand Up @@ -98731,7 +98731,7 @@ Object {
"type": "TSTypeLiteral",
},
},
"exportKind": "value",
"exportKind": "type",
"loc": Object {
"end": Object {
"column": 2,
Expand Down Expand Up @@ -151165,7 +151165,7 @@ Object {
],
"type": "TSInterfaceDeclaration",
},
"exportKind": "value",
"exportKind": "type",
"loc": Object {
"end": Object {
"column": 9,
Expand Down

0 comments on commit 390ba8a

Please sign in to comment.