Skip to content

Commit

Permalink
reexporting + renaming when scopehoisting (#2491)
Browse files Browse the repository at this point in the history
  • Loading branch information
mischnic authored and devongovett committed Jan 12, 2019
1 parent 6566e16 commit 58a0348
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 0 deletions.
@@ -0,0 +1,3 @@
import { x } from './b.js';

output = x;
@@ -0,0 +1,3 @@
export const x = 'foobar';

export { x as y } from './c.js'
@@ -0,0 +1 @@
export const x = 'xyz';
12 changes: 12 additions & 0 deletions packages/core/integration-tests/test/scope-hoisting.js
Expand Up @@ -321,6 +321,18 @@ describe('scope hoisting', function() {
assert.deepEqual(output, 'foobar');
});

it('supports requiring a re-exported and renamed ES6 import', async function() {
let b = await bundle(
path.join(
__dirname,
'/integration/scope-hoisting/es6/re-export-renamed/a.js'
)
);

let output = await run(b);
assert.deepEqual(output, 'foobar');
});

it('keeps side effects by default', async function() {
let b = await bundle(
path.join(
Expand Down
5 changes: 5 additions & 0 deletions packages/core/parcel-bundler/src/scope-hoisting/renamer.js
@@ -1,3 +1,5 @@
const t = require('@babel/types');

function rename(scope, oldName, newName) {
if (oldName === newName) {
return;
Expand All @@ -19,6 +21,9 @@ function rename(scope, oldName, newName) {

// Rename all references
for (let path of binding.referencePaths) {
if (t.isExportSpecifier(path.parent) && path.parentPath.parent.source) {
continue;
}
if (path.node.name === oldName) {
path.node.name = newName;
}
Expand Down

0 comments on commit 58a0348

Please sign in to comment.