From 58a034871bcaa7abe30065f9b9f9a5417b1d389b Mon Sep 17 00:00:00 2001 From: Niklas Mischkulnig Date: Sat, 12 Jan 2019 19:20:40 +0100 Subject: [PATCH] reexporting + renaming when scopehoisting (#2491) --- .../scope-hoisting/es6/re-export-renamed/a.js | 3 +++ .../scope-hoisting/es6/re-export-renamed/b.js | 3 +++ .../scope-hoisting/es6/re-export-renamed/c.js | 1 + .../core/integration-tests/test/scope-hoisting.js | 12 ++++++++++++ .../parcel-bundler/src/scope-hoisting/renamer.js | 5 +++++ 5 files changed, 24 insertions(+) create mode 100644 packages/core/integration-tests/test/integration/scope-hoisting/es6/re-export-renamed/a.js create mode 100644 packages/core/integration-tests/test/integration/scope-hoisting/es6/re-export-renamed/b.js create mode 100644 packages/core/integration-tests/test/integration/scope-hoisting/es6/re-export-renamed/c.js diff --git a/packages/core/integration-tests/test/integration/scope-hoisting/es6/re-export-renamed/a.js b/packages/core/integration-tests/test/integration/scope-hoisting/es6/re-export-renamed/a.js new file mode 100644 index 00000000000..1077b636aca --- /dev/null +++ b/packages/core/integration-tests/test/integration/scope-hoisting/es6/re-export-renamed/a.js @@ -0,0 +1,3 @@ +import { x } from './b.js'; + +output = x; diff --git a/packages/core/integration-tests/test/integration/scope-hoisting/es6/re-export-renamed/b.js b/packages/core/integration-tests/test/integration/scope-hoisting/es6/re-export-renamed/b.js new file mode 100644 index 00000000000..154372df193 --- /dev/null +++ b/packages/core/integration-tests/test/integration/scope-hoisting/es6/re-export-renamed/b.js @@ -0,0 +1,3 @@ +export const x = 'foobar'; + +export { x as y } from './c.js' diff --git a/packages/core/integration-tests/test/integration/scope-hoisting/es6/re-export-renamed/c.js b/packages/core/integration-tests/test/integration/scope-hoisting/es6/re-export-renamed/c.js new file mode 100644 index 00000000000..0190dbd267f --- /dev/null +++ b/packages/core/integration-tests/test/integration/scope-hoisting/es6/re-export-renamed/c.js @@ -0,0 +1 @@ +export const x = 'xyz'; diff --git a/packages/core/integration-tests/test/scope-hoisting.js b/packages/core/integration-tests/test/scope-hoisting.js index 139397dcf07..16f90cb5e4b 100644 --- a/packages/core/integration-tests/test/scope-hoisting.js +++ b/packages/core/integration-tests/test/scope-hoisting.js @@ -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( diff --git a/packages/core/parcel-bundler/src/scope-hoisting/renamer.js b/packages/core/parcel-bundler/src/scope-hoisting/renamer.js index 00ec7ae66b1..1b9d90f3d6b 100644 --- a/packages/core/parcel-bundler/src/scope-hoisting/renamer.js +++ b/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; @@ -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; }