diff --git a/lib/util/visit-import.js b/lib/util/visit-import.js index 7379f852..905e5bda 100644 --- a/lib/util/visit-import.js +++ b/lib/util/visit-import.js @@ -42,6 +42,16 @@ module.exports = function visitImport( "ImportExpression", ]](node) { const sourceNode = node.source + + // skip `import(foo)` + if ( + node.type === "ImportExpression" && + sourceNode && + sourceNode.type !== "Literal" + ) { + return + } + const name = sourceNode && stripImportPathParams(sourceNode.value) if (name && (includeCore || !resolve.isCore(name))) { targets.push(new ImportTarget(sourceNode, name, options)) diff --git a/tests/lib/rules/no-missing-import.js b/tests/lib/rules/no-missing-import.js index 9ee1271c..b8ff1f15 100644 --- a/tests/lib/rules/no-missing-import.js +++ b/tests/lib/rules/no-missing-import.js @@ -166,6 +166,17 @@ ruleTester.run("no-missing-import", rule, { options: [{ resolvePaths: ["tests"] }], env: { node: true }, }, + + // import() + ...(DynamicImportSupported + ? [ + { + filename: fixture("test.js"), + code: "function f() { import(foo) }", + parserOptions: { ecmaVersion: 2020 }, + }, + ] + : []), ], invalid: [ {