diff --git a/tests/src/rules/no-unresolved.js b/tests/src/rules/no-unresolved.js index da7d4dc5ae..1975f0cd7a 100644 --- a/tests/src/rules/no-unresolved.js +++ b/tests/src/rules/no-unresolved.js @@ -141,6 +141,13 @@ function runResolverTests(resolver) { errors: ["Unable to resolve path to module './does-not-exist'."], }), + // refs: https://github.com/benmosher/eslint-plugin-import/issues/2024 + rest({ + code: 'import("./does-not-exist").then(() => {})', + parserOptions: { ecmaVersion: 2020 }, + errors: ["Unable to resolve path to module './does-not-exist'."], + }), + // commonjs setting rest({ code: 'var bar = require("./baz")', diff --git a/utils/moduleVisitor.js b/utils/moduleVisitor.js index 8466fa65e7..69269985bd 100644 --- a/utils/moduleVisitor.js +++ b/utils/moduleVisitor.js @@ -36,7 +36,17 @@ exports.default = function visitModules(visitor, options) { // for esmodule dynamic `import()` calls function checkImportCall(node) { - const modulePath = node.source; + let modulePath; + // refs https://github.com/estree/estree/blob/master/es2020.md#importexpression + if (node.type === 'ImportExpression') { + modulePath = node.source; + } else if (node.type === 'CallExpression') { + if (node.callee.type !== 'Import') return; + if (node.arguments.length !== 1) return; + + modulePath = node.arguments[0]; + } + if (modulePath.type !== 'Literal') return; if (typeof modulePath.value !== 'string') return; @@ -83,6 +93,7 @@ exports.default = function visitModules(visitor, options) { 'ImportDeclaration': checkSource, 'ExportNamedDeclaration': checkSource, 'ExportAllDeclaration': checkSource, + 'CallExpression': checkImportCall, 'ImportExpression': checkImportCall, }); }