Skip to content

Commit e8e84a3

Browse files
committed
Remove __exports map on the web target
This is no longe rneeded now that we precisely track what needs to be exported for an imported item, so all the imports are hooked up correctly elsewhere without the need for the `__exports` map.
1 parent 3e28e6e commit e8e84a3

File tree

1 file changed

+2
-46
lines changed
  • crates/cli-support/src/js

1 file changed

+2
-46
lines changed

crates/cli-support/src/js/mod.rs

Lines changed: 2 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ impl<'a> Context<'a> {
142142
OutputMode::Bundler { .. }
143143
| OutputMode::Node {
144144
experimental_modules: true,
145-
} => {
145+
}
146+
| OutputMode::Web => {
146147
if contents.starts_with("function") {
147148
let body = &contents[8..];
148149
if export_name == definition_name {
@@ -161,50 +162,6 @@ impl<'a> Context<'a> {
161162
format!("export const {} = {};\n", export_name, contents)
162163
}
163164
}
164-
OutputMode::Web => {
165-
// In web mode there's no need to export the internals of
166-
// wasm-bindgen as we're not using the module itself as the
167-
// import object but rather the `__exports` map we'll be
168-
// initializing below.
169-
let export = if export_name.starts_with("__wbindgen")
170-
|| export_name.starts_with("__wbg_")
171-
|| export_name.starts_with("__widl_")
172-
{
173-
""
174-
} else {
175-
"export "
176-
};
177-
if contents.starts_with("function") {
178-
let body = &contents[8..];
179-
if export_name == definition_name {
180-
format!(
181-
"{}function {name}{}\n__exports.{name} = {name}",
182-
export,
183-
body,
184-
name = export_name,
185-
)
186-
} else {
187-
format!(
188-
"{}function {defname}{}\n__exports.{name} = {defname}",
189-
export,
190-
body,
191-
name = export_name,
192-
defname = definition_name,
193-
)
194-
}
195-
} else if contents.starts_with("class") {
196-
assert_eq!(export_name, definition_name);
197-
format!("{}{}\n", export, contents)
198-
} else {
199-
assert_eq!(export_name, definition_name);
200-
format!(
201-
"{}const {name} = {};\n__exports.{name} = {name};",
202-
export,
203-
contents,
204-
name = export_name
205-
)
206-
}
207-
}
208165
};
209166
self.global(&global);
210167
Ok(())
@@ -366,7 +323,6 @@ impl<'a> Context<'a> {
366323
// expose the same initialization function as `--target no-modules`
367324
// as the default export of the module.
368325
OutputMode::Web => {
369-
self.imports_post.push_str("const __exports = {};\n");
370326
self.imports_post.push_str("let wasm;\n");
371327
init = self.gen_init(needs_manual_start);
372328
footer.push_str("export default init;\n");

0 commit comments

Comments
 (0)