Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wrong does not export error because of missing symbols #7432

Merged
merged 2 commits into from
Dec 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { x } from './b.js';

output = x;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export { x as y } from './c.js'

export const x = 'foobar';

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const x = 'xyz';
12 changes: 12 additions & 0 deletions packages/core/integration-tests/test/scope-hoisting.js
Original file line number Diff line number Diff line change
Expand Up @@ -1039,6 +1039,18 @@ describe('scope hoisting', function () {
assert.deepEqual(output, 'foobar');
});

it('supports requiring a re-exported and renamed ES6 import (reversed order)', async function () {
let b = await bundle(
path.join(
__dirname,
'/integration/scope-hoisting/es6/re-export-renamed2/a.js',
),
);

let output = await run(b);
assert.deepEqual(output, 'foobar');
});

it('supports requiring a re-exported and renamed ES6 namespace import', async function () {
let b = await bundle(
path.join(
Expand Down
58 changes: 50 additions & 8 deletions packages/transformers/js/core/src/hoist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1406,10 +1406,12 @@ impl Visit for Collect {
source,
},
);
self
.exports_locals
.entry(named.orig.sym.clone())
.or_insert_with(|| exported.sym.clone());
if node.src.is_none() {
self
.exports_locals
.entry(named.orig.sym.clone())
.or_insert_with(|| exported.sym.clone());
}
}
ExportSpecifier::Default(default) => {
self.exports.insert(
Expand All @@ -1420,10 +1422,12 @@ impl Visit for Collect {
source,
},
);
self
.exports_locals
.entry(default.exported.sym.clone())
.or_insert_with(|| js_word!("default"));
if node.src.is_none() {
self
.exports_locals
.entry(default.exported.sym.clone())
.or_insert_with(|| js_word!("default"));
}
}
ExportSpecifier::Namespace(namespace) => {
self.exports.insert(
Expand Down Expand Up @@ -2267,6 +2271,16 @@ mod tests {
}};
}

macro_rules! assert_eq_exported_symbols {
($m: expr, $match: expr) => {{
let mut map = HashMap::new();
for sym in $m {
map.insert(sym.exported, sym.local);
}
assert_eq!(map, $match);
}};
}

macro_rules! assert_eq_set {
($m: expr, $match: expr) => {{
let mut map = HashSet::new();
Expand Down Expand Up @@ -3383,6 +3397,34 @@ mod tests {
import "abc:bar";
"#}
);

let (_collect, code, hoist) = parse(
r#"
export { settings as siteSettings } from "./settings";
export const settings = "hi";
"#,
);

assert_eq!(
code,
indoc! {r#"
import "abc:./settings";
const $abc$export$a5a6e0b888b2c992 = "hi";
"#}
);

assert_eq_exported_symbols!(
hoist.exported_symbols,
map! {
w!("settings") => w!("$abc$export$a5a6e0b888b2c992")
}
);
assert_eq_imported_symbols!(
hoist.re_exports,
map! {
w!("siteSettings") => (w!("./settings"), w!("settings"))
}
);
}

#[test]
Expand Down