diff --git a/packages/core/integration-tests/test/integration/scope-hoisting/es6/export-undefined/a.js b/packages/core/integration-tests/test/integration/scope-hoisting/es6/export-undefined/a.js new file mode 100644 index 00000000000..eb53777b1b3 --- /dev/null +++ b/packages/core/integration-tests/test/integration/scope-hoisting/es6/export-undefined/a.js @@ -0,0 +1 @@ +export {Test}; diff --git a/packages/core/integration-tests/test/scope-hoisting.js b/packages/core/integration-tests/test/scope-hoisting.js index d40a48f2ea2..53c95f0477f 100644 --- a/packages/core/integration-tests/test/scope-hoisting.js +++ b/packages/core/integration-tests/test/scope-hoisting.js @@ -276,6 +276,23 @@ describe('scope hoisting', function() { assert.deepEqual(output, ['test']); }); + it('throws a meaningful error on undefined exports', async function() { + let threw = false; + try { + await bundle( + path.join( + __dirname, + '/integration/scope-hoisting/es6/export-undefined/a.js' + ) + ); + } catch (err) { + threw = true; + assert.equal(err.message, "export 'Test' is not defined"); + } + + assert(threw); + }); + it('supports import default CommonJS interop', async function() { let b = await bundle( path.join( diff --git a/packages/core/parcel-bundler/src/scope-hoisting/hoist.js b/packages/core/parcel-bundler/src/scope-hoisting/hoist.js index 0f5b9af08b0..27f6bfe3352 100644 --- a/packages/core/parcel-bundler/src/scope-hoisting/hoist.js +++ b/packages/core/parcel-bundler/src/scope-hoisting/hoist.js @@ -533,7 +533,11 @@ function addExport(asset, path, local, exported) { asset.cacheData.exports[exported.name] = identifier.name; } - rename(scope, local.name, identifier.name); + try { + rename(scope, local.name, identifier.name); + } catch (e) { + throw new Error('export ' + e.message); + } constantViolations.forEach(path => path.insertAfter(t.cloneDeep(assignNode))); } diff --git a/packages/core/parcel-bundler/src/scope-hoisting/renamer.js b/packages/core/parcel-bundler/src/scope-hoisting/renamer.js index 1b9d90f3d6b..fd6d61f70d3 100644 --- a/packages/core/parcel-bundler/src/scope-hoisting/renamer.js +++ b/packages/core/parcel-bundler/src/scope-hoisting/renamer.js @@ -7,6 +7,10 @@ function rename(scope, oldName, newName) { let binding = scope.getBinding(oldName); + if (!binding) { + throw new Error("'" + oldName + "' is not defined"); + } + // Rename all constant violations for (let violation of binding.constantViolations) { let bindingIds = violation.getBindingIdentifierPaths(true, false);