Skip to content

Commit

Permalink
fix: invalid names in import object
Browse files Browse the repository at this point in the history
This prepares the ground for when TypeScript will have
support for "Arbitrary module namespace
identifier names":
microsoft/TypeScript#40594
  • Loading branch information
eduardomourar committed Feb 15, 2023
1 parent 7800c38 commit c54c4f5
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 85 deletions.
105 changes: 28 additions & 77 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Expand Up @@ -21,6 +21,6 @@ wasmprinter = "0.2.51"
wasmparser = "0.101.0"
wasm-encoder = "0.24.0"
wat = "1.0.59"
wit-bindgen-guest-rust = { git = 'https://github.com/bytecodealliance/wit-bindgen', default-features = false, features = ['macros'] }
wit-bindgen = { git = 'https://github.com/bytecodealliance/wit-bindgen', default-features = false, features = ['macros'] }
wit-component = { version = "0.7.0", features = ['dummy-module'] }
wit-parser = "0.6.1"
2 changes: 1 addition & 1 deletion crates/js-component-bindgen-component/Cargo.toml
Expand Up @@ -15,7 +15,7 @@ heck = { workspace = true }
clap = { workspace = true, optional = true }
js-component-bindgen = { path = "../js-component-bindgen", features = ['raw-bindgen'] }
wasmtime-environ = { workspace = true, features = ['component-model'] }
wit-bindgen-guest-rust = { workspace = true, features = ['default'] }
wit-bindgen = { workspace = true, features = ['default'] }
wit-component = { workspace = true }
wit-parser = { workspace = true }
indexmap = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion crates/js-component-bindgen-component/src/lib.rs
Expand Up @@ -28,7 +28,7 @@ macro_rules! uwriteln {
};
}

wit_bindgen_guest_rust::generate!("js-component-bindgen");
wit_bindgen::generate!("js-component-bindgen");

use crate::exports::*;

Expand Down
2 changes: 1 addition & 1 deletion crates/js-component-bindgen/Cargo.toml
Expand Up @@ -17,7 +17,7 @@ anyhow = { workspace = true }
heck = { workspace = true }
clap = { workspace = true, optional = true }
wasmtime-environ = { workspace = true, features = ['component-model'] }
wit-bindgen-guest-rust = { workspace = true, features = ['default'] }
wit-bindgen = { workspace = true, features = ['default'] }
wit-component = { workspace = true }
wit-parser = { workspace = true }
indexmap = { workspace = true }
Expand Down
19 changes: 17 additions & 2 deletions crates/js-component-bindgen/src/bindgen.rs
Expand Up @@ -406,10 +406,11 @@ impl JsBindgen {
files,
AbiVariant::GuestImport,
);
let camel = name.to_upper_camel_case();
let upper_camel = name.to_upper_camel_case();
let lower_camel = name.to_lower_camel_case();
uwriteln!(
self.import_object,
"export const {name}: typeof {camel}Imports;"
"declare const {lower_camel}: typeof {upper_camel}Imports;"
);
}

Expand Down Expand Up @@ -509,6 +510,20 @@ impl JsBindgen {
WorldItem::Type(_) => unimplemented!("type imports"),
}
}
// We will be following the ECMA262 normative:
// https://github.com/tc39/ecma262/pull/2154
uwriteln!(self.import_object, "export {{");
for (name, import) in world.imports.iter() {
match import {
WorldItem::Function(_) => {}
WorldItem::Interface(_) => {
let camel = name.to_lower_camel_case();
uwriteln!(self.import_object, "{camel} as '{name}',");
}
WorldItem::Type(_) => {}
}
}
uwriteln!(self.import_object, "}};");
if !funcs.is_empty() {
self.import_funcs(resolve, id, &funcs, files);
}
Expand Down
2 changes: 1 addition & 1 deletion crates/wasm-tools-component/Cargo.toml
Expand Up @@ -15,6 +15,6 @@ wasmparser = { workspace = true }
wasmprinter = { workspace = true }
wasm-encoder = { workspace = true }
wat = { workspace = true }
wit-bindgen-guest-rust = { workspace = true, features = ['default'] }
wit-bindgen = { workspace = true, features = ['default'] }
wit-component = { workspace = true }
wit-parser = { workspace = true }
2 changes: 1 addition & 1 deletion crates/wasm-tools-component/src/lib.rs
Expand Up @@ -4,7 +4,7 @@ use wasmparser;
use wit_component::{ComponentEncoder, DecodedWasm, DocumentPrinter, StringEncoding};
use wit_parser::{Resolve, UnresolvedPackage};

wit_bindgen_guest_rust::generate!("wasm-tools");
wit_bindgen::generate!("wasm-tools");

struct WasmToolsJs;

Expand Down

0 comments on commit c54c4f5

Please sign in to comment.