@babel/generator: Add emit and builder for TSImportType (#9309)
This commit is contained in:
parent
2cc0376756
commit
4c2f8d9337
@ -476,6 +476,21 @@ export function TSModuleBlock(node) {
|
||||
this.tsPrintBraced(node.body, node);
|
||||
}
|
||||
|
||||
export function TSImportType(node) {
|
||||
const { argument, qualifier, typeParameters } = node;
|
||||
this.word("import");
|
||||
this.token("(");
|
||||
this.print(argument, node);
|
||||
this.token(")");
|
||||
if (qualifier) {
|
||||
this.token(".");
|
||||
this.print(qualifier, node);
|
||||
}
|
||||
if (typeParameters) {
|
||||
this.print(typeParameters, node);
|
||||
}
|
||||
}
|
||||
|
||||
export function TSImportEqualsDeclaration(node) {
|
||||
const { isExport, id, moduleReference } = node;
|
||||
if (isExport) {
|
||||
|
||||
3
packages/babel-generator/test/fixtures/typescript/types-import-type/input.js
vendored
Normal file
3
packages/babel-generator/test/fixtures/typescript/types-import-type/input.js
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
let x: typeof import('./x');
|
||||
let Y: import('./y').Y;
|
||||
let z: import("/z").foo.bar<string>;
|
||||
3
packages/babel-generator/test/fixtures/typescript/types-import-type/output.js
vendored
Normal file
3
packages/babel-generator/test/fixtures/typescript/types-import-type/output.js
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
let x: typeof import('./x');
|
||||
let Y: import('./y').Y;
|
||||
let z: import("/z").foo.bar<string>;
|
||||
@ -185,7 +185,7 @@ defineType("TSTypeQuery", {
|
||||
aliases: ["TSType"],
|
||||
visitor: ["exprName"],
|
||||
fields: {
|
||||
exprName: validateType("TSEntityName"),
|
||||
exprName: validateType(["TSEntityName", "TSImportType"]),
|
||||
},
|
||||
});
|
||||
|
||||
@ -405,6 +405,16 @@ defineType("TSModuleBlock", {
|
||||
},
|
||||
});
|
||||
|
||||
defineType("TSImportType", {
|
||||
aliases: ["TSType"],
|
||||
visitor: ["argument", "qualifier", "typeParameters"],
|
||||
fields: {
|
||||
argument: validateType("StringLiteral"),
|
||||
qualifier: validateOptionalType("TSEntityName"),
|
||||
typeParameters: validateOptionalType("TSTypeParameterInstantiation"),
|
||||
},
|
||||
});
|
||||
|
||||
defineType("TSImportEqualsDeclaration", {
|
||||
aliases: ["Statement"],
|
||||
visitor: ["id", "moduleReference"],
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user