Skip to content

Commit

Permalink
Merge pull request #3404 from btopro/master
Browse files Browse the repository at this point in the history
[polymer-build] #3402 resolveBareSpecifiers must be a Program
  • Loading branch information
usergenic authored Apr 25, 2019
2 parents e898dea + e53d1c5 commit 9e990ae
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions packages/build/src/babel-plugin-bare-specifiers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -35,23 +35,26 @@ export const resolveBareSpecifiers = (
inherits: dynamicImportSyntax,

visitor: {
CallExpression(path: NodePath<CallExpression>) {
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<Program>) {
path.traverse({
CallExpression(path: NodePath<CallExpression>) {
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<HasSpecifier>) {
Expand Down

0 comments on commit 9e990ae

Please sign in to comment.