Skip to content

Commit

Permalink
Fix wrong does not export error because of missing symbols (parcel-…
Browse files Browse the repository at this point in the history
  • Loading branch information
mischnic authored and bhovhannes committed Dec 23, 2021
1 parent 7b01ca1 commit 763b20d
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 8 deletions.
@@ -0,0 +1,3 @@
import { x } from './b.js';

output = x;
@@ -0,0 +1,4 @@
export { x as y } from './c.js'

export const x = 'foobar';

@@ -0,0 +1 @@
export const x = 'xyz';
12 changes: 12 additions & 0 deletions packages/core/integration-tests/test/scope-hoisting.js
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
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 763b20d

Please sign in to comment.