Skip to content

Commit

Permalink
🐛 fix crash on dynamic import with identifier (#201)
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker authored and mysticatea committed Dec 23, 2019
1 parent 972f828 commit 4f74fbf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/util/visit-import.js
Expand Up @@ -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))
Expand Down
11 changes: 11 additions & 0 deletions tests/lib/rules/no-missing-import.js
Expand Up @@ -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: [
{
Expand Down

0 comments on commit 4f74fbf

Please sign in to comment.