diff --git a/packages/core/parcel-bundler/src/scope-hoisting/hoist.js b/packages/core/parcel-bundler/src/scope-hoisting/hoist.js index afc01e49be5..0f5b9af08b0 100644 --- a/packages/core/parcel-bundler/src/scope-hoisting/hoist.js +++ b/packages/core/parcel-bundler/src/scope-hoisting/hoist.js @@ -51,6 +51,8 @@ function hasSideEffects(asset, {sideEffects} = asset._package) { module.exports = { Program: { enter(path, asset) { + path.scope.crawl(); + asset.cacheData.imports = asset.cacheData.imports || Object.create(null); asset.cacheData.exports = asset.cacheData.exports || Object.create(null); asset.cacheData.wildcards = asset.cacheData.wildcards || []; diff --git a/packages/core/parcel-bundler/src/scope-hoisting/renamer.js b/packages/core/parcel-bundler/src/scope-hoisting/renamer.js index 288e9adbb37..00ec7ae66b1 100644 --- a/packages/core/parcel-bundler/src/scope-hoisting/renamer.js +++ b/packages/core/parcel-bundler/src/scope-hoisting/renamer.js @@ -25,9 +25,9 @@ function rename(scope, oldName, newName) { } // Rename binding identifier, and update scope. - binding.identifier.name = newName; + scope.removeOwnBinding(oldName); scope.bindings[newName] = binding; - delete scope.bindings[oldName]; + binding.identifier.name = newName; } module.exports = rename; diff --git a/packages/core/parcel-bundler/test/integration/scope-hoisting/es6/jsx-pragma/.babelrc b/packages/core/parcel-bundler/test/integration/scope-hoisting/es6/jsx-pragma/.babelrc new file mode 100644 index 00000000000..0223e4695b6 --- /dev/null +++ b/packages/core/parcel-bundler/test/integration/scope-hoisting/es6/jsx-pragma/.babelrc @@ -0,0 +1,3 @@ +{ + "plugins": ["@babel/plugin-transform-react-jsx"] +} \ No newline at end of file diff --git a/packages/core/parcel-bundler/test/integration/scope-hoisting/es6/jsx-pragma/a.js b/packages/core/parcel-bundler/test/integration/scope-hoisting/es6/jsx-pragma/a.js new file mode 100644 index 00000000000..63092ed7dcc --- /dev/null +++ b/packages/core/parcel-bundler/test/integration/scope-hoisting/es6/jsx-pragma/a.js @@ -0,0 +1,3 @@ +import React from "./react.js"; + +output = Test; diff --git a/packages/core/parcel-bundler/test/integration/scope-hoisting/es6/jsx-pragma/react.js b/packages/core/parcel-bundler/test/integration/scope-hoisting/es6/jsx-pragma/react.js new file mode 100644 index 00000000000..080d1ea7edf --- /dev/null +++ b/packages/core/parcel-bundler/test/integration/scope-hoisting/es6/jsx-pragma/react.js @@ -0,0 +1,9 @@ +// mock for React.createElement + +export default { + createElement(type, props, children){ + return { + type, props, children + }; + } +} \ No newline at end of file diff --git a/packages/core/parcel-bundler/test/integration/scope-hoisting/es6/rename-superclass/a.js b/packages/core/parcel-bundler/test/integration/scope-hoisting/es6/rename-superclass/a.js new file mode 100644 index 00000000000..6e183773093 --- /dev/null +++ b/packages/core/parcel-bundler/test/integration/scope-hoisting/es6/rename-superclass/a.js @@ -0,0 +1,5 @@ +import Superclass from './b'; + +class Test extends Superclass {} + +output = new Test().parentMethod(); diff --git a/packages/core/parcel-bundler/test/integration/scope-hoisting/es6/rename-superclass/b.js b/packages/core/parcel-bundler/test/integration/scope-hoisting/es6/rename-superclass/b.js new file mode 100644 index 00000000000..f3d0194fcd5 --- /dev/null +++ b/packages/core/parcel-bundler/test/integration/scope-hoisting/es6/rename-superclass/b.js @@ -0,0 +1,5 @@ +export default class Superclass { + parentMethod(){ + return 2; + } +} diff --git a/packages/core/parcel-bundler/test/scope-hoisting.js b/packages/core/parcel-bundler/test/scope-hoisting.js index f54d6949763..5a37bda97d8 100644 --- a/packages/core/parcel-bundler/test/scope-hoisting.js +++ b/packages/core/parcel-bundler/test/scope-hoisting.js @@ -89,6 +89,17 @@ describe('scope hoisting', function() { assert.equal(output, 2); }); + it('supports renaming superclass identifiers', async function() { + let b = await bundle( + path.join( + __dirname, + '/integration/scope-hoisting/es6/rename-superclass/a.js' + ) + ); + let output = await run(b); + assert.equal(output, 2); + }); + it('supports renaming imports', async function() { let b = await bundle( path.join( @@ -446,6 +457,19 @@ describe('scope hoisting', function() { assert.deepEqual(output, 'bar'); }); + it('should support the jsx pragma', async function() { + let b = await bundle( + path.join(__dirname, '/integration/scope-hoisting/es6/jsx-pragma/a.js') + ); + + let output = await run(b); + assert.deepEqual(output, { + children: 'Test', + props: null, + type: 'span' + }); + }); + it('should not nameclash with internal variables', async function() { let b = await bundle( path.join(__dirname, '/integration/scope-hoisting/es6/name-clash/a.js')