Skip to content

Commit ab1ef56

Browse files
authored
fix: treeshaking of local package references (#128)
1 parent 4f792ec commit ab1ef56

File tree

1 file changed

+7
-1
lines changed
  • crates/spidermonkey-embedding-splicer/src

1 file changed

+7
-1
lines changed

crates/spidermonkey-embedding-splicer/src/bindgen.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ struct JsBindgen<'a> {
8383
esm_bindgen: EsmBindgen,
8484
local_names: LocalNames,
8585

86+
local_package_name: String,
87+
8688
resolve: &'a Resolve,
8789
world: WorldId,
8890
sizes: SizeAlign,
@@ -133,6 +135,7 @@ pub fn componentize_bindgen(
133135
guest_exports: &Vec<String>,
134136
features: Vec<Features>,
135137
) -> Result<Componentization> {
138+
let local_package_name = resolve.id_of_name(resolve.worlds[id].package.unwrap(), "");
136139
let mut bindgen = JsBindgen {
137140
src: Source::default(),
138141
esm_bindgen: EsmBindgen::default(),
@@ -143,6 +146,7 @@ pub fn componentize_bindgen(
143146
sizes: SizeAlign::default(),
144147
memory: "$memory".to_string(),
145148
realloc: "$realloc".to_string(),
149+
local_package_name,
146150
exports: Vec::new(),
147151
imports: Vec::new(),
148152
resource_directions: HashMap::new(),
@@ -521,7 +525,9 @@ impl JsBindgen<'_> {
521525
fn imports_bindgen(&mut self, guest_imports: &Vec<String>) {
522526
for (key, impt) in &self.resolve.worlds[self.world].imports {
523527
let import_name = self.resolve.name_world_key(key);
524-
if !guest_imports.contains(&import_name) {
528+
if !guest_imports.contains(&import_name)
529+
&& !import_name.starts_with(&self.local_package_name)
530+
{
525531
continue;
526532
}
527533
match &impt {

0 commit comments

Comments
 (0)