Skip to content
This repository has been archived by the owner on Apr 9, 2020. It is now read-only.

Commit

Permalink
Skip transforms for the files defining imports supplied to them
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon committed Sep 3, 2015
1 parent 97f4b6a commit 6d662ba
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,15 @@ export default function ({ Plugin, types: t }) {
const { target, imports = [], locals = [] } = targetOptions;
const { filename } = file.opts;

function isSameAsFileBeingProcessed(importPath) {
const { dir, base, ext, name } = path.parse(resolvePath(importPath, filename));
return dir === '.' && name === path.parse(filename).name;
}

if (imports.some(isSameAsFileBeingProcessed)) {
return;
}

return [id, t.variableDeclaration('var', [
t.variableDeclarator(id,
t.callExpression(file.addImport(resolvePath(target, filename)), [
Expand Down Expand Up @@ -272,7 +281,7 @@ export default function ({ Plugin, types: t }) {
// Import transformation functions and initialize them
const initTransformCalls = allTransformOptions.map(transformOptions =>
defineInitTransformCall(scope, file, recordsId, transformOptions)
);
).filter(Boolean);
const initTransformIds = initTransformCalls.map(c => c[0]);
const initTransformVars = initTransformCalls.map(c => c[1]);

Expand Down

0 comments on commit 6d662ba

Please sign in to comment.