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 5 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
12 changes: 12 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,15 @@ module.exports = function convert(config) {
result.typeAnnotation.range = result.typeAnnotation.typeAnnotation.range;
break;

case SyntaxKind.ImportType:
Object.assign(result, {
type: AST_NODE_TYPES.TSImportType,
parameter: convertChild(node.argument),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I renamed the argument to parameter since it looks like the naming convention here.

qualifier: convertChild(node.qualifier),
typeParameters: convertTypeArgumentsToTypeParameters(node.typeArguments)
});
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
6 changes: 5 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,11 @@ 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-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>>;
Loading