Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mischnic committed Dec 11, 2021
1 parent 839ffba commit d18a239
Showing 1 changed file with 50 additions and 8 deletions.
58 changes: 50 additions & 8 deletions packages/transformers/js/core/src/hoist.rs
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

0 comments on commit d18a239

Please sign in to comment.