Skip to content

Commit 3c40492

Browse files
authored
exhausively match JSImportName (#2090)
1 parent 4900732 commit 3c40492

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2097,7 +2097,19 @@ impl<'a> Context<'a> {
20972097
fn prestore_global_import_identifiers(&mut self) -> Result<(), Error> {
20982098
for import in self.aux.import_map.values() {
20992099
let js = match import {
2100-
AuxImport::Value(AuxValue::Bare(js)) => js,
2100+
AuxImport::Value(AuxValue::Bare(js))
2101+
| AuxImport::Value(AuxValue::ClassGetter(js, ..))
2102+
| AuxImport::Value(AuxValue::Getter(js, ..))
2103+
| AuxImport::Value(AuxValue::ClassSetter(js, ..))
2104+
| AuxImport::Value(AuxValue::Setter(js, ..))
2105+
| AuxImport::ValueWithThis(js, ..)
2106+
| AuxImport::Instanceof(js)
2107+
| AuxImport::Static(js)
2108+
| AuxImport::StructuralClassGetter(js, ..)
2109+
| AuxImport::StructuralClassSetter(js, ..)
2110+
| AuxImport::IndexingGetterOfClass(js)
2111+
| AuxImport::IndexingSetterOfClass(js)
2112+
| AuxImport::IndexingDeleterOfClass(js) => js,
21012113
_ => continue,
21022114
};
21032115
if let JsImportName::Global { .. } = js.name {

tests/wasm/imports.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@ exports.Math = {
132132
func_from_module_math: (a) => a * 2
133133
}
134134

135+
exports.Number = {
136+
func_from_module_number: () => 3.0
137+
}
138+
135139
exports.same_name_from_import = (a) => a * 3;
136140

137141
exports.same_js_namespace_from_module = {

tests/wasm/imports.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ extern "C" {
7373
#[wasm_bindgen(js_namespace = Math)]
7474
fn func_from_module_math(a: i32) -> i32;
7575

76+
#[wasm_bindgen(js_namespace = Number)]
77+
fn func_from_module_number() -> f64;
78+
7679
#[wasm_bindgen(js_name = "same_name_from_import")]
7780
fn same_name_from_import_1(s: i32) -> i32;
7881

@@ -95,6 +98,10 @@ extern "C" {
9598

9699
#[wasm_bindgen(js_namespace = Math, js_name = "sqrt")]
97100
fn func_from_global_math(s: f64) -> f64;
101+
102+
type Number;
103+
#[wasm_bindgen(getter, static_method_of = Number, js_name = "NAN")]
104+
fn static_getter_from_global_number() -> f64;
98105
}
99106

100107
#[wasm_bindgen_test]
@@ -301,7 +308,11 @@ fn func_from_global_and_module_same_js_namespace() {
301308
assert_eq!(func_from_global_math(4.0), 2.0);
302309
assert_eq!(func_from_module_math(2), 4);
303310
}
304-
311+
#[wasm_bindgen_test]
312+
fn getter_from_global_and_module_same_name() {
313+
assert!(Number::static_getter_from_global_number().is_nan());
314+
assert_eq!(func_from_module_number(), 3.0);
315+
}
305316
#[wasm_bindgen_test]
306317
fn func_from_two_modules_same_js_name() {
307318
assert_eq!(same_name_from_import_1(1), 3);

0 commit comments

Comments
 (0)