Skip to content

Commit

Permalink
wasm2es6js: Fix handling of exported imports
Browse files Browse the repository at this point in the history
This commit fixes a case in `wasm2es6js` where if an imported function
was reexported it wasn't handled correctly. This doesn't have a direct
test but came up during the development of rustwasm#1002
  • Loading branch information
alexcrichton committed Nov 29, 2018
1 parent 8aac291 commit df4e4c6
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions crates/cli-support/src/wasm2es6js.rs
Expand Up @@ -58,7 +58,27 @@ pub fn typescript(module: &Module) -> String {
.unwrap_or(0);
for entry in i.entries() {
let idx = match *entry.internal() {
Internal::Function(i) => i - imported_functions,
Internal::Function(i) if i < imported_functions => {
*module.import_section()
.unwrap()
.entries()
.iter()
.filter_map(|f| {
match f.external() {
External::Function(i) => Some(i),
_ => None,
}
})
.nth(i as usize)
.unwrap()
}
Internal::Function(i) => {
let idx = i - imported_functions;
let functions = module
.function_section()
.expect("failed to find function section");
functions.entries()[idx as usize].type_ref()
}
Internal::Memory(_) => {
exports.push_str(&format!(
"export const {}: WebAssembly.Memory;\n",
Expand All @@ -76,11 +96,6 @@ pub fn typescript(module: &Module) -> String {
Internal::Global(_) => continue,
};

let functions = module
.function_section()
.expect("failed to find function section");
let idx = functions.entries()[idx as usize].type_ref();

let types = module
.type_section()
.expect("failed to find type section");
Expand Down

0 comments on commit df4e4c6

Please sign in to comment.