Use TSImportType.source (#18319)
This commit is contained in:
1 parent
138f92764a
commit
864bb7c042
6 files changed
+22
-30
No files matched your search
@@ -186,11 +186,6 @@ function clean(original, cloned, parent) {
|
|||||||
cloned.type = "TSNonNullExpression";
|
cloned.type = "TSNonNullExpression";
|
||||||
cloned.expression.type = "ChainExpression";
|
cloned.expression.type = "ChainExpression";
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://github.com/prettier/prettier/pull/18316
|
|
||||||
if (original.type === "TSImportType") {
|
|
||||||
delete cloned.source;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
clean.ignoredProperties = ignoredProperties;
|
clean.ignoredProperties = ignoredProperties;
|
||||||
|
|||||||
@@ -151,6 +151,15 @@ function postprocess(ast, options) {
|
|||||||
node.options = node.attributes;
|
node.options = node.attributes;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
// https://github.com/babel/babel/issues/17506
|
||||||
|
// https://github.com/oxc-project/oxc/issues/16074
|
||||||
|
case "TSImportType":
|
||||||
|
if (!node.source && node.argument.type === "TSLiteralType") {
|
||||||
|
node.source = node.argument.literal;
|
||||||
|
delete node.argument;
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* c8 ignore next 3 */
|
/* c8 ignore next 3 */
|
||||||
|
|||||||
@@ -108,10 +108,14 @@ function printCallExpression(path, options, print) {
|
|||||||
function printCallee(path, print) {
|
function printCallee(path, print) {
|
||||||
const { node } = path;
|
const { node } = path;
|
||||||
|
|
||||||
if (node.type === "ImportExpression" || node.type === "TSImportType") {
|
if (node.type === "ImportExpression") {
|
||||||
return `import${node.phase ? `.${node.phase}` : ""}`;
|
return `import${node.phase ? `.${node.phase}` : ""}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (node.type === "TSImportType") {
|
||||||
|
return "import";
|
||||||
|
}
|
||||||
|
|
||||||
if (node.type === "TSExternalModuleReference") {
|
if (node.type === "TSExternalModuleReference") {
|
||||||
return "require";
|
return "require";
|
||||||
}
|
}
|
||||||
@@ -152,18 +156,7 @@ function isSimpleModuleImport(path) {
|
|||||||
|
|
||||||
const args = getCallArguments(node);
|
const args = getCallArguments(node);
|
||||||
|
|
||||||
if (args.length !== 1 || hasComment(args[0])) {
|
return args.length === 1 && isStringLiteral(args[0]) && !hasComment(args[0]);
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
let source = args[0];
|
|
||||||
|
|
||||||
// TODO: remove this once https://github.com/typescript-eslint/typescript-eslint/issues/11583 get fixed
|
|
||||||
if (node.type === "TSImportType" && source.type === "TSLiteralType") {
|
|
||||||
source = source.literal;
|
|
||||||
}
|
|
||||||
|
|
||||||
return isStringLiteral(source);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function isCommonsJsOrAmdModuleDefinition(path) {
|
function isCommonsJsOrAmdModuleDefinition(path) {
|
||||||
|
|||||||
@@ -44,8 +44,9 @@ const excludeVisitorKeys = {
|
|||||||
ExportAllDeclaration: ["assertions"],
|
ExportAllDeclaration: ["assertions"],
|
||||||
ImportDeclaration: ["assertions"],
|
ImportDeclaration: ["assertions"],
|
||||||
|
|
||||||
// https://github.com/prettier/prettier/pull/18316
|
// https://github.com/babel/babel/issues/17506
|
||||||
TSImportType: ["source"],
|
// https://github.com/oxc-project/oxc/issues/16074
|
||||||
|
TSImportType: ["argument"],
|
||||||
};
|
};
|
||||||
|
|
||||||
// https://github.com/babel/babel/issues/17524
|
// https://github.com/babel/babel/issues/17524
|
||||||
|
|||||||
@@ -875,7 +875,7 @@ function getCallArguments(node) {
|
|||||||
|
|
||||||
let args;
|
let args;
|
||||||
if (node.type === "ImportExpression" || node.type === "TSImportType") {
|
if (node.type === "ImportExpression" || node.type === "TSImportType") {
|
||||||
args = [node.type === "ImportExpression" ? node.source : node.argument];
|
args = [node.source];
|
||||||
|
|
||||||
if (node.options) {
|
if (node.options) {
|
||||||
args.push(node.options);
|
args.push(node.options);
|
||||||
@@ -901,10 +901,7 @@ function iterateCallArgumentsPath(path, iteratee) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (node.type === "ImportExpression" || node.type === "TSImportType") {
|
if (node.type === "ImportExpression" || node.type === "TSImportType") {
|
||||||
path.call(
|
path.call(() => iteratee(path, 0), "source");
|
||||||
() => iteratee(path, 0),
|
|
||||||
node.type === "ImportExpression" ? "source" : "argument",
|
|
||||||
);
|
|
||||||
|
|
||||||
if (node.options) {
|
if (node.options) {
|
||||||
path.call(() => iteratee(path, 1), "options");
|
path.call(() => iteratee(path, 1), "options");
|
||||||
@@ -925,10 +922,7 @@ function getCallArgumentSelector(node, index) {
|
|||||||
|
|
||||||
if (node.type === "ImportExpression" || node.type === "TSImportType") {
|
if (node.type === "ImportExpression" || node.type === "TSImportType") {
|
||||||
if (index === 0 || index === (node.options ? -2 : -1)) {
|
if (index === 0 || index === (node.options ? -2 : -1)) {
|
||||||
return [
|
return [...selectors, "source"];
|
||||||
...selectors,
|
|
||||||
node.type === "ImportExpression" ? "source" : "argument",
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
if (node.options && (index === 1 || index === -1)) {
|
if (node.options && (index === 1 || index === -1)) {
|
||||||
return [...selectors, "options"];
|
return [...selectors, "options"];
|
||||||
|
|||||||
@@ -892,9 +892,9 @@ exports[`visitor keys estree 1`] = `
|
|||||||
"moduleReference",
|
"moduleReference",
|
||||||
],
|
],
|
||||||
"TSImportType": [
|
"TSImportType": [
|
||||||
"argument",
|
|
||||||
"options",
|
"options",
|
||||||
"qualifier",
|
"qualifier",
|
||||||
|
"source",
|
||||||
"typeArguments",
|
"typeArguments",
|
||||||
],
|
],
|
||||||
"TSIndexSignature": [
|
"TSIndexSignature": [
|
||||||
|
|||||||
Reference in new issue
Block a user