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

Commit 7461462

Browse files
ikatyangJamesHenry
authored andcommitted
Fix: remove unnecessary TypeRef wrapper for ImportType (fixes #507) (#508)
1 parent 615325b commit 7461462

File tree

8 files changed

+1269
-1
lines changed

8 files changed

+1269
-1
lines changed

lib/ast-node-types.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ module.exports = {
113113
TSEnumMember: "TSEnumMember",
114114
TSExportAssignment: "TSExportAssignment",
115115
TSExportKeyword: "TSExportKeyword",
116+
TSImportType: "TSImportType",
117+
TSLiteralType: "TSLiteralType",
116118
TSIndexSignature: "TSIndexSignature",
117119
TSInterfaceBody: "TSInterfaceBody",
118120
TSInterfaceDeclaration: "TSInterfaceDeclaration",

lib/convert.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ module.exports = function convert(config) {
154154
loc: nodeUtils.getLoc(typeArgument, ast)
155155
};
156156
}
157+
if (typeArgument.kind === SyntaxKind.ImportType) {
158+
return convert({ node: typeArgument, parent: null, ast, additionalOptions });
159+
}
157160
return {
158161
type: AST_NODE_TYPES.TSTypeReference,
159162
range: [
@@ -2141,6 +2144,16 @@ module.exports = function convert(config) {
21412144
result.typeAnnotation.range = result.typeAnnotation.typeAnnotation.range;
21422145
break;
21432146

2147+
case SyntaxKind.ImportType:
2148+
Object.assign(result, {
2149+
type: AST_NODE_TYPES.TSImportType,
2150+
isTypeOf: !!node.isTypeOf,
2151+
parameter: convertChild(node.argument),
2152+
qualifier: convertChild(node.qualifier),
2153+
typeParameters: node.typeArguments ? convertTypeArgumentsToTypeParameters(node.typeArguments) : null
2154+
});
2155+
break;
2156+
21442157
case SyntaxKind.EnumDeclaration: {
21452158
Object.assign(result, {
21462159
type: AST_NODE_TYPES.TSEnumDeclaration,

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
"typescript": "*"
6363
},
6464
"jest": {
65+
"testEnvironment": "node",
6566
"testRegex": "tests/lib/.+\\.js$",
6667
"testPathIgnorePatterns": [],
6768
"collectCoverage": true,

tests/ast-alignment/fixtures-to-test.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,12 @@ let fixturePatternConfigsToTest = [
422422
"class-with-private-parameter-properties",
423423
"class-with-protected-parameter-properties",
424424
"class-with-public-parameter-properties",
425-
"class-with-readonly-parameter-properties"
425+
"class-with-readonly-parameter-properties",
426+
/**
427+
* Not yet supported in Babylon https://github.com/babel/babel/issues/7749
428+
*/
429+
"import-type",
430+
"import-type-with-type-parameters-in-type-reference"
426431
],
427432
parseWithSourceTypeModule: [
428433
"export-named-enum",

tests/ast-alignment/jest.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"use strict";
22

33
module.exports = {
4+
testEnvironment: "node",
45
testRegex: "spec\\.js$"
56
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
type X = A<import("").B<any>>;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
type A = typeof import('A');
2+
type B = import("B").X<Y>;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy