Skip to content

Commit

Permalink
Fix named export with different export name for wrapped assets (#7052)
Browse files Browse the repository at this point in the history
  • Loading branch information
mischnic committed Oct 12, 2021
1 parent 2175e1b commit bea9442
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 4 deletions.
@@ -0,0 +1,3 @@
import {foo} from './b';

output = foo;
@@ -0,0 +1,2 @@
var bar = module && 2;
export {bar as foo};
@@ -0,0 +1,3 @@
import {foo} from './b';

output = foo;
@@ -0,0 +1,2 @@
var bar = 2;
export {bar as foo};
23 changes: 23 additions & 0 deletions packages/core/integration-tests/test/scope-hoisting.js
Expand Up @@ -123,6 +123,29 @@ describe('scope hoisting', function() {
assert.equal(output, 2);
});

it('supports named exports of variables with a different name', async function() {
let b = await bundle(
path.join(
__dirname,
'/integration/scope-hoisting/es6/named-export-variable-rename/a.js',
),
);

let output = await run(b);
assert.equal(output, 2);
});
it('supports named exports of variables with a different name when wrapped', async function() {
let b = await bundle(
path.join(
__dirname,
'/integration/scope-hoisting/es6/named-export-variable-rename-wrapped/a.js',
),
);

let output = await run(b);
assert.equal(output, 2);
});

it('supports renaming non-ASCII identifiers', async function() {
let b = await bundle(
path.join(
Expand Down
9 changes: 5 additions & 4 deletions packages/transformers/js/core/src/hoist.rs
Expand Up @@ -268,14 +268,15 @@ impl<'a> Fold for Hoist<'a> {
// A variable will appear only once in the `exports` mapping but
// could be exported multiple times with different names.
// Find the original exported name, and remap.
let orig_exported = self.collect.exports.get(&id).unwrap();
let id = if self.collect.should_wrap {
Ident::new(orig_exported.clone(), DUMMY_SP)
id.0
} else {
self.get_export_ident(DUMMY_SP, orig_exported)
self
.get_export_ident(DUMMY_SP, self.collect.exports.get(&id).unwrap())
.sym
};
self.exported_symbols.push(ExportedSymbol {
local: id.sym,
local: id,
exported,
loc: SourceLocation::from(&self.collect.source_map, named.span),
});
Expand Down

0 comments on commit bea9442

Please sign in to comment.