Skip to content

Commit

Permalink
Throw meaningful error on undefined exports (#2693)
Browse files Browse the repository at this point in the history
  • Loading branch information
mischnic authored and devongovett committed Mar 6, 2019
1 parent 03fdcfd commit 2a55296
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
@@ -0,0 +1 @@
export {Test};
17 changes: 17 additions & 0 deletions packages/core/integration-tests/test/scope-hoisting.js
Expand Up @@ -288,6 +288,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(
Expand Down
6 changes: 5 additions & 1 deletion packages/core/parcel-bundler/src/scope-hoisting/hoist.js
Expand Up @@ -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)));
}
Expand Down
4 changes: 4 additions & 0 deletions packages/core/parcel-bundler/src/scope-hoisting/renamer.js
Expand Up @@ -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);
Expand Down

0 comments on commit 2a55296

Please sign in to comment.