Skip to content

Commit

Permalink
fix: Prevent double application of the transform (#176)
Browse files Browse the repository at this point in the history
  • Loading branch information
fatfisz authored and tleunen committed Jun 12, 2017
1 parent e25fc96 commit feefe9e
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.DS_Store
node_modules/
/node_modules/
npm-debug.log
lib/
coverage/
5 changes: 5 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,12 @@ export function mapPathString(nodePath, state) {

const modulePath = getRealPath(nodePath.node.value, state);
if (modulePath) {
if (nodePath.node.pathResolved) {
return;
}

nodePath.replaceWith(state.types.stringLiteral(modulePath));
nodePath.node.pathResolved = true;
}
}

Expand Down
56 changes: 56 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,62 @@ describe('module-resolver', () => {
});
});
});

describe('multiple alias application', () => {
it('should resolve the cyclic alias only once', () => {
const fileName = path.resolve('test/testproject/src/app.js');
const cycleAliasTransformerOpts = {
babelrc: false,
plugins: [
[plugin, {
alias: {
first: 'second',
second: 'first',
},
}],
[plugin, {
alias: {
first: 'second',
second: 'first',
},
}],
],
filename: fileName,
};

testWithImport(
'first',
'second',
cycleAliasTransformerOpts,
);
});

it('should resolve the prefix alias only once', () => {
const fileName = path.resolve('test/testproject/src/app.js');
const cycleAliasTransformerOpts = {
babelrc: false,
plugins: [
[plugin, {
alias: {
prefix: 'prefix/lib',
},
}],
[plugin, {
alias: {
prefix: 'prefix/lib',
},
}],
],
filename: fileName,
};

testWithImport(
'prefix/test',
'prefix/lib/test',
cycleAliasTransformerOpts,
);
});
});
});

describe('with custom cwd', () => {
Expand Down
Empty file.
Empty file.

0 comments on commit feefe9e

Please sign in to comment.