Skip to content

Commit bea9442

Browse files
authoredOct 12, 2021
Fix named export with different export name for wrapped assets (#7052)
1 parent 2175e1b commit bea9442

File tree

6 files changed

+38
-4
lines changed

6 files changed

+38
-4
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import {foo} from './b';
2+
3+
output = foo;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
var bar = module && 2;
2+
export {bar as foo};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import {foo} from './b';
2+
3+
output = foo;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
var bar = 2;
2+
export {bar as foo};

‎packages/core/integration-tests/test/scope-hoisting.js

+23
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,29 @@ describe('scope hoisting', function() {
123123
assert.equal(output, 2);
124124
});
125125

126+
it('supports named exports of variables with a different name', async function() {
127+
let b = await bundle(
128+
path.join(
129+
__dirname,
130+
'/integration/scope-hoisting/es6/named-export-variable-rename/a.js',
131+
),
132+
);
133+
134+
let output = await run(b);
135+
assert.equal(output, 2);
136+
});
137+
it('supports named exports of variables with a different name when wrapped', async function() {
138+
let b = await bundle(
139+
path.join(
140+
__dirname,
141+
'/integration/scope-hoisting/es6/named-export-variable-rename-wrapped/a.js',
142+
),
143+
);
144+
145+
let output = await run(b);
146+
assert.equal(output, 2);
147+
});
148+
126149
it('supports renaming non-ASCII identifiers', async function() {
127150
let b = await bundle(
128151
path.join(

‎packages/transformers/js/core/src/hoist.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -268,14 +268,15 @@ impl<'a> Fold for Hoist<'a> {
268268
// A variable will appear only once in the `exports` mapping but
269269
// could be exported multiple times with different names.
270270
// Find the original exported name, and remap.
271-
let orig_exported = self.collect.exports.get(&id).unwrap();
272271
let id = if self.collect.should_wrap {
273-
Ident::new(orig_exported.clone(), DUMMY_SP)
272+
id.0
274273
} else {
275-
self.get_export_ident(DUMMY_SP, orig_exported)
274+
self
275+
.get_export_ident(DUMMY_SP, self.collect.exports.get(&id).unwrap())
276+
.sym
276277
};
277278
self.exported_symbols.push(ExportedSymbol {
278-
local: id.sym,
279+
local: id,
279280
exported,
280281
loc: SourceLocation::from(&self.collect.source_map, named.span),
281282
});

0 commit comments

Comments
 (0)
Please sign in to comment.