Skip to content
This repository was archived by the owner on Jan 19, 2019. It is now read-only.

Fix: remove unnecessary TypeRef wrapper for ImportType (fixes #507) #508

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/ast-node-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ module.exports = {
TSEnumMember: "TSEnumMember",
TSExportAssignment: "TSExportAssignment",
TSExportKeyword: "TSExportKeyword",
TSImportType: "TSImportType",
TSLiteralType: "TSLiteralType",
TSIndexSignature: "TSIndexSignature",
TSInterfaceBody: "TSInterfaceBody",
TSInterfaceDeclaration: "TSInterfaceDeclaration",
Expand Down
13 changes: 13 additions & 0 deletions lib/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ module.exports = function convert(config) {
loc: nodeUtils.getLoc(typeArgument, ast)
};
}
if (typeArgument.kind === SyntaxKind.ImportType) {
return convert({ node: typeArgument, parent: null, ast, additionalOptions });
}
return {
type: AST_NODE_TYPES.TSTypeReference,
range: [
Expand Down Expand Up @@ -2141,6 +2144,16 @@ module.exports = function convert(config) {
result.typeAnnotation.range = result.typeAnnotation.typeAnnotation.range;
break;

case SyntaxKind.ImportType:
Object.assign(result, {
type: AST_NODE_TYPES.TSImportType,
isTypeOf: !!node.isTypeOf,
parameter: convertChild(node.argument),
qualifier: convertChild(node.qualifier),
typeParameters: node.typeArguments ? convertTypeArgumentsToTypeParameters(node.typeArguments) : null
});
break;

case SyntaxKind.EnumDeclaration: {
Object.assign(result, {
type: AST_NODE_TYPES.TSEnumDeclaration,
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"typescript": "*"
},
"jest": {
"testEnvironment": "node",
"testRegex": "tests/lib/.+\\.js$",
"testPathIgnorePatterns": [],
"collectCoverage": true,
Expand Down
7 changes: 6 additions & 1 deletion tests/ast-alignment/fixtures-to-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,12 @@ let fixturePatternConfigsToTest = [
"class-with-private-parameter-properties",
"class-with-protected-parameter-properties",
"class-with-public-parameter-properties",
"class-with-readonly-parameter-properties"
"class-with-readonly-parameter-properties",
/**
* Not yet supported in Babylon https://github.com/babel/babel/issues/7749
*/
"import-type",
"import-type-with-type-parameters-in-type-reference"
],
parseWithSourceTypeModule: [
"export-named-enum",
Expand Down
1 change: 1 addition & 0 deletions tests/ast-alignment/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use strict";

module.exports = {
testEnvironment: "node",
testRegex: "spec\\.js$"
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
type X = A<import("").B<any>>;
2 changes: 2 additions & 0 deletions tests/fixtures/typescript/basics/import-type.src.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
type A = typeof import('A');
type B = import("B").X<Y>;
Loading