Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

re-exporting and renaming when scopehoisting #2491

Merged
merged 1 commit into from Jan 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -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