Skip to content

Commit 4f74fbf

Browse files
fiskermysticatea
authored andcommittedDec 23, 2019
🐛 fix crash on dynamic import with identifier (#201)
1 parent 972f828 commit 4f74fbf

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed
 

‎lib/util/visit-import.js

+10
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@ module.exports = function visitImport(
4242
"ImportExpression",
4343
]](node) {
4444
const sourceNode = node.source
45+
46+
// skip `import(foo)`
47+
if (
48+
node.type === "ImportExpression" &&
49+
sourceNode &&
50+
sourceNode.type !== "Literal"
51+
) {
52+
return
53+
}
54+
4555
const name = sourceNode && stripImportPathParams(sourceNode.value)
4656
if (name && (includeCore || !resolve.isCore(name))) {
4757
targets.push(new ImportTarget(sourceNode, name, options))

‎tests/lib/rules/no-missing-import.js

+11
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,17 @@ ruleTester.run("no-missing-import", rule, {
166166
options: [{ resolvePaths: ["tests"] }],
167167
env: { node: true },
168168
},
169+
170+
// import()
171+
...(DynamicImportSupported
172+
? [
173+
{
174+
filename: fixture("test.js"),
175+
code: "function f() { import(foo) }",
176+
parserOptions: { ecmaVersion: 2020 },
177+
},
178+
]
179+
: []),
169180
],
170181
invalid: [
171182
{

0 commit comments

Comments
 (0)
Please sign in to comment.