Skip to content

Commit 7461462

Browse files
ikatyangJamesHenry
authored andcommitted
Fix: remove unnecessary TypeRef wrapper for ImportType (fixes eslint#507) (eslint#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

+2
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

+13
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

+1
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

+6-1
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

+1
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
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
type X = A<import("").B<any>>;
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)