diff --git a/packages/build/src/babel-plugin-bare-specifiers.ts b/packages/build/src/babel-plugin-bare-specifiers.ts index c7b3e0cd1..3eae9bc6d 100644 --- a/packages/build/src/babel-plugin-bare-specifiers.ts +++ b/packages/build/src/babel-plugin-bare-specifiers.ts @@ -14,7 +14,7 @@ import dynamicImportSyntax from '@babel/plugin-syntax-dynamic-import'; import {NodePath} from '@babel/traverse'; -import {CallExpression, ExportAllDeclaration, ExportNamedDeclaration, ImportDeclaration} from 'babel-types'; +import {CallExpression, ExportAllDeclaration, ExportNamedDeclaration, ImportDeclaration, Program} from 'babel-types'; import {resolve} from 'polymer-analyzer/lib/javascript/resolve-specifier-node'; const isPathSpecifier = (s: string) => /^\.{0,2}\//.test(s); @@ -35,23 +35,26 @@ export const resolveBareSpecifiers = ( inherits: dynamicImportSyntax, visitor: { - CallExpression(path: NodePath) { - const node = path.node; - if (node.callee.type as string === 'Import') { - const specifierArg = node.arguments[0]; - if (specifierArg.type !== 'StringLiteral') { - // Should never happen - return; + Program(path: NodePath) { + path.traverse({ + CallExpression(path: NodePath) { + if (path.node.callee.type as string === 'Import') { + const specifierArg = path.node.arguments[0]; + if (specifierArg.type !== 'StringLiteral') { + // Should never happen + return; + } + const specifier = specifierArg.value; + specifierArg.value = maybeResolve( + specifier, + filePath, + isComponentRequest, + packageName, + componentDir, + rootDir); + } } - const specifier = specifierArg.value; - specifierArg.value = maybeResolve( - specifier, - filePath, - isComponentRequest, - packageName, - componentDir, - rootDir); - } + }); }, 'ImportDeclaration|ExportNamedDeclaration|ExportAllDeclaration'( path: NodePath) {