Skip to content

Commit

Permalink
fix: dynamic import & add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aladdin-add committed Apr 12, 2021
1 parent 8424548 commit 1dfde11
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion utils/moduleVisitor.js
Expand Up @@ -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;

Expand Down Expand Up @@ -83,6 +93,7 @@ exports.default = function visitModules(visitor, options) {
'ImportDeclaration': checkSource,
'ExportNamedDeclaration': checkSource,
'ExportAllDeclaration': checkSource,
'CallExpression': checkImportCall,
'ImportExpression': checkImportCall,
});
}
Expand Down

0 comments on commit 1dfde11

Please sign in to comment.