From ae5dfbf890a898411be3f623329804d8234f4785 Mon Sep 17 00:00:00 2001 From: "s.vanriessen" Date: Mon, 13 Oct 2025 12:00:35 +0200 Subject: [PATCH 1/7] fix: duplicated function names for same interfaces and export --- .../src/bindgen.rs | 32 ++++++++++++++----- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/crates/spidermonkey-embedding-splicer/src/bindgen.rs b/crates/spidermonkey-embedding-splicer/src/bindgen.rs index a1216616..591c6162 100644 --- a/crates/spidermonkey-embedding-splicer/src/bindgen.rs +++ b/crates/spidermonkey-embedding-splicer/src/bindgen.rs @@ -172,11 +172,12 @@ pub fn componentize_bindgen( // consolidate import specifiers and generate wrappers // we do this separately because function index order matters let mut import_bindings = Vec::new(); - for (_, item) in bindgen.imports.iter() { + for (specifier, item) in bindgen.imports.iter() { // this import binding order matters - import_bindings.push(binding_name( + import_bindings.push(binding_name_import( &item.resource.func_name(&item.name), &item.iface_name, + specifier, )); } @@ -204,7 +205,7 @@ pub fn componentize_bindgen( let item = items.first().unwrap(); if let Some(resource) = resource { let export_name = resource.to_upper_camel_case(); - let binding_name = binding_name(&export_name, &item.iface_name); + let binding_name = binding_name_import(&export_name, &item.iface_name, &item.binding_name); if item.iface { specifier_list.push(format!("{export_name}: import_{binding_name}")); } else { @@ -213,13 +214,12 @@ pub fn componentize_bindgen( } else { for BindingItem { iface, - iface_name, name, + binding_name, .. } in items { let export_name = name.to_lower_camel_case(); - let binding_name = binding_name(&export_name, iface_name); if *iface { specifier_list.push(format!("{export_name}: import_{binding_name}")); } else { @@ -654,11 +654,11 @@ impl JsBindgen<'_> { let fn_name = func.item_name(); let fn_camel_name = fn_name.to_lower_camel_case(); - use binding_name as binding_name_fn; + use binding_name_import as binding_name_fn; let (binding_name, resource) = match &func.kind { FunctionKind::Freestanding => { - let binding_name = binding_name(&fn_camel_name, &iface_name); + let binding_name = binding_name_import(&fn_camel_name, &iface_name, &import_name); uwrite!(self.src, "\nfunction import_{binding_name}"); @@ -702,7 +702,7 @@ impl JsBindgen<'_> { func.params.len(), &format!( "$import_{}", - binding_name_fn(&resource.func_name(fn_name), &iface_name) + binding_name_fn(&resource.func_name(fn_name), &iface_name, import_name.as_str()) ), StringEncoding::UTF8, func, @@ -1294,6 +1294,22 @@ fn binding_name(func_name: &str, iface_name: &Option) -> String { } } +fn binding_name_import(func_name: &str, iface_name: &Option, import_name: &str) -> String { + let valid_import = import_name + .chars() + .map(|c| if c.is_alphanumeric() { c } else { '_' }) + .collect::(); + + if import_name != "<>" { + let s = valid_import.to_string(); + format!("{s}${func_name}") + } else if let Some(iface_name) = iface_name { + format!("{iface_name}${func_name}") + } else { + func_name.to_string() + } +} + /// Extract success and error types from a given optional type, if it is a Result pub fn get_result_types( resolve: &Resolve, From 2cf8384413cb6763be0b7bd03799f01ea80a3f8e Mon Sep 17 00:00:00 2001 From: "s.vanriessen" Date: Mon, 13 Oct 2025 13:23:42 +0200 Subject: [PATCH 2/7] chore: formatting --- crates/spidermonkey-embedding-splicer/src/bindgen.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/crates/spidermonkey-embedding-splicer/src/bindgen.rs b/crates/spidermonkey-embedding-splicer/src/bindgen.rs index 591c6162..8e937a32 100644 --- a/crates/spidermonkey-embedding-splicer/src/bindgen.rs +++ b/crates/spidermonkey-embedding-splicer/src/bindgen.rs @@ -205,7 +205,8 @@ pub fn componentize_bindgen( let item = items.first().unwrap(); if let Some(resource) = resource { let export_name = resource.to_upper_camel_case(); - let binding_name = binding_name_import(&export_name, &item.iface_name, &item.binding_name); + let binding_name = + binding_name_import(&export_name, &item.iface_name, &item.binding_name); if item.iface { specifier_list.push(format!("{export_name}: import_{binding_name}")); } else { @@ -702,7 +703,11 @@ impl JsBindgen<'_> { func.params.len(), &format!( "$import_{}", - binding_name_fn(&resource.func_name(fn_name), &iface_name, import_name.as_str()) + binding_name_fn( + &resource.func_name(fn_name), + &iface_name, + import_name.as_str() + ) ), StringEncoding::UTF8, func, From 806e83273bba5025cfb47d453b95d4a894275a0d Mon Sep 17 00:00:00 2001 From: "s.vanriessen" Date: Mon, 13 Oct 2025 13:42:03 +0200 Subject: [PATCH 3/7] chore: remove to string function on import string --- crates/spidermonkey-embedding-splicer/src/bindgen.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/spidermonkey-embedding-splicer/src/bindgen.rs b/crates/spidermonkey-embedding-splicer/src/bindgen.rs index 8e937a32..c16628b4 100644 --- a/crates/spidermonkey-embedding-splicer/src/bindgen.rs +++ b/crates/spidermonkey-embedding-splicer/src/bindgen.rs @@ -1306,8 +1306,7 @@ fn binding_name_import(func_name: &str, iface_name: &Option, import_name .collect::(); if import_name != "<>" { - let s = valid_import.to_string(); - format!("{s}${func_name}") + format!("{valid_import}${func_name}") } else if let Some(iface_name) = iface_name { format!("{iface_name}${func_name}") } else { From eddb29646b338ff3adeedca8ed1f1bbc42005808 Mon Sep 17 00:00:00 2001 From: "s.vanriessen" Date: Fri, 17 Oct 2025 09:53:33 +0200 Subject: [PATCH 4/7] tests: add duplicated function name test --- .../src/bindgen.rs | 9 +++---- test/bindings.js | 2 +- .../local:http-request-http.js | 3 +++ .../local:http-request-part-two-http.js | 3 +++ .../import-duplicated-interface/source.js | 13 +++++++++ .../cases/import-duplicated-interface/test.js | 18 +++++++++++++ .../local-http-request-part-two/package.wit | 6 +++++ .../wit/deps/local-http-request/package.wit | 6 +++++ .../import-duplicated-interface/wit/world.wit | 27 +++++++++++++++++++ 9 files changed, 81 insertions(+), 6 deletions(-) create mode 100644 test/cases/import-duplicated-interface/local:http-request-http.js create mode 100644 test/cases/import-duplicated-interface/local:http-request-part-two-http.js create mode 100644 test/cases/import-duplicated-interface/source.js create mode 100644 test/cases/import-duplicated-interface/test.js create mode 100644 test/cases/import-duplicated-interface/wit/deps/local-http-request-part-two/package.wit create mode 100644 test/cases/import-duplicated-interface/wit/deps/local-http-request/package.wit create mode 100644 test/cases/import-duplicated-interface/wit/world.wit diff --git a/crates/spidermonkey-embedding-splicer/src/bindgen.rs b/crates/spidermonkey-embedding-splicer/src/bindgen.rs index c16628b4..75c89e2f 100644 --- a/crates/spidermonkey-embedding-splicer/src/bindgen.rs +++ b/crates/spidermonkey-embedding-splicer/src/bindgen.rs @@ -1300,12 +1300,11 @@ fn binding_name(func_name: &str, iface_name: &Option) -> String { } fn binding_name_import(func_name: &str, iface_name: &Option, import_name: &str) -> String { - let valid_import = import_name - .chars() - .map(|c| if c.is_alphanumeric() { c } else { '_' }) - .collect::(); - if import_name != "<>" { + let valid_import = import_name + .chars() + .map(|c| if c.is_alphanumeric() { c } else { '_' }) + .collect::(); format!("{valid_import}${func_name}") } else if let Some(iface_name) = iface_name { format!("{iface_name}${func_name}") diff --git a/test/bindings.js b/test/bindings.js index c1650a2f..96b58450 100644 --- a/test/bindings.js +++ b/test/bindings.js @@ -96,7 +96,7 @@ suite('Bindings', async () => { for (let [impt] of imports) { if (impt.startsWith('wasi:')) continue; if (impt.startsWith('[')) impt = impt.slice(impt.indexOf(']') + 1); - let importName = impt.split('/').pop(); + let importName = impt.replace('/', '-'); if (importName === 'test') importName = 'imports'; map[impt] = `../../cases/${name}/${importName}.js`; } diff --git a/test/cases/import-duplicated-interface/local:http-request-http.js b/test/cases/import-duplicated-interface/local:http-request-http.js new file mode 100644 index 00000000..46526ebd --- /dev/null +++ b/test/cases/import-duplicated-interface/local:http-request-http.js @@ -0,0 +1,3 @@ +export function run(endpoint) { + return endpoint; +} diff --git a/test/cases/import-duplicated-interface/local:http-request-part-two-http.js b/test/cases/import-duplicated-interface/local:http-request-part-two-http.js new file mode 100644 index 00000000..46526ebd --- /dev/null +++ b/test/cases/import-duplicated-interface/local:http-request-part-two-http.js @@ -0,0 +1,3 @@ +export function run(endpoint) { + return endpoint; +} diff --git a/test/cases/import-duplicated-interface/source.js b/test/cases/import-duplicated-interface/source.js new file mode 100644 index 00000000..caeba15c --- /dev/null +++ b/test/cases/import-duplicated-interface/source.js @@ -0,0 +1,13 @@ +import * as $local$e1ab0bfa$1 from 'local:http-request/http'; +import * as $local$15f12255$1 from 'local:http-request-part-two/http'; + +export function call(parameters) { + console.log('call called with', parameters); + // $local$e1ab0bfa$1.import.run('http://example.com'); + // $local$15f12255$1.import.run('http://example.com'); + return parameters; +} + +export const actions = { + call, +}; diff --git a/test/cases/import-duplicated-interface/test.js b/test/cases/import-duplicated-interface/test.js new file mode 100644 index 00000000..d2788d82 --- /dev/null +++ b/test/cases/import-duplicated-interface/test.js @@ -0,0 +1,18 @@ +import { strictEqual } from 'node:assert'; + +export function test(instance, args) { + strictEqual( + instance['actions'].call({ + actionId: '123', + payload: { input: '' }, + }), + '' + ); + strictEqual( + instance['actions'].instance.call({ + actionId: '123', + payload: { input: '' }, + }), + 'http://example.com' + ); +} diff --git a/test/cases/import-duplicated-interface/wit/deps/local-http-request-part-two/package.wit b/test/cases/import-duplicated-interface/wit/deps/local-http-request-part-two/package.wit new file mode 100644 index 00000000..21b21508 --- /dev/null +++ b/test/cases/import-duplicated-interface/wit/deps/local-http-request-part-two/package.wit @@ -0,0 +1,6 @@ +package local:http-request-part-two; + +interface http { + run: func(endpoint: string) -> result; +} + diff --git a/test/cases/import-duplicated-interface/wit/deps/local-http-request/package.wit b/test/cases/import-duplicated-interface/wit/deps/local-http-request/package.wit new file mode 100644 index 00000000..32a2e73f --- /dev/null +++ b/test/cases/import-duplicated-interface/wit/deps/local-http-request/package.wit @@ -0,0 +1,6 @@ +package local:http-request; + +interface http { + run: func(endpoint: string) -> result; +} + diff --git a/test/cases/import-duplicated-interface/wit/world.wit b/test/cases/import-duplicated-interface/wit/world.wit new file mode 100644 index 00000000..2ecf6f1d --- /dev/null +++ b/test/cases/import-duplicated-interface/wit/world.wit @@ -0,0 +1,27 @@ +package local:custom; + +interface actions { + type json-string = string; + + record payload { + input: json-string, + } + + record input { + action-id: string, + payload: payload, + } + + record output { + %result: json-string, + } + + call: func(input: input) -> result; +} + +world main { + import local:http-request/http; + import local:http-request-part-two/http; + + export actions; +} \ No newline at end of file From 91866e40da0b57b7045c705fc1affcc28b3eaf8f Mon Sep 17 00:00:00 2001 From: "s.vanriessen" Date: Fri, 17 Oct 2025 14:56:46 +0200 Subject: [PATCH 5/7] test: add dup interface test --- test/bindings.js | 4 ++- .../local-hello-hello.js | 3 ++ .../local-hello-second-hello.js | 7 +++++ .../local:http-request-http.js | 3 -- .../local:http-request-part-two-http.js | 3 -- .../import-duplicated-interface/source.js | 23 +++++++------- .../cases/import-duplicated-interface/test.js | 17 ++++------ .../wit/deps/local-hello-second/hello.wit | 5 +++ .../wit/deps/local-hello/hello.wit | 5 +++ .../local-http-request-part-two/package.wit | 6 ---- .../wit/deps/local-http-request/package.wit | 6 ---- .../import-duplicated-interface/wit/world.wit | 31 +++++-------------- 12 files changed, 48 insertions(+), 65 deletions(-) create mode 100644 test/cases/import-duplicated-interface/local-hello-hello.js create mode 100644 test/cases/import-duplicated-interface/local-hello-second-hello.js delete mode 100644 test/cases/import-duplicated-interface/local:http-request-http.js delete mode 100644 test/cases/import-duplicated-interface/local:http-request-part-two-http.js create mode 100644 test/cases/import-duplicated-interface/wit/deps/local-hello-second/hello.wit create mode 100644 test/cases/import-duplicated-interface/wit/deps/local-hello/hello.wit delete mode 100644 test/cases/import-duplicated-interface/wit/deps/local-http-request-part-two/package.wit delete mode 100644 test/cases/import-duplicated-interface/wit/deps/local-http-request/package.wit diff --git a/test/bindings.js b/test/bindings.js index 96b58450..1154cfd5 100644 --- a/test/bindings.js +++ b/test/bindings.js @@ -96,7 +96,9 @@ suite('Bindings', async () => { for (let [impt] of imports) { if (impt.startsWith('wasi:')) continue; if (impt.startsWith('[')) impt = impt.slice(impt.indexOf(']') + 1); - let importName = impt.replace('/', '-'); + let importName = impt.split('/').pop(); + if (name === 'import-duplicated-interface') + importName = impt.replace('/', '-').replace(':', '-'); if (importName === 'test') importName = 'imports'; map[impt] = `../../cases/${name}/${importName}.js`; } diff --git a/test/cases/import-duplicated-interface/local-hello-hello.js b/test/cases/import-duplicated-interface/local-hello-hello.js new file mode 100644 index 00000000..6c521712 --- /dev/null +++ b/test/cases/import-duplicated-interface/local-hello-hello.js @@ -0,0 +1,3 @@ +export function hello(name) { + return `Hello 1.0.0, ${name}` +} diff --git a/test/cases/import-duplicated-interface/local-hello-second-hello.js b/test/cases/import-duplicated-interface/local-hello-second-hello.js new file mode 100644 index 00000000..eccacb91 --- /dev/null +++ b/test/cases/import-duplicated-interface/local-hello-second-hello.js @@ -0,0 +1,7 @@ +export function hello(name) { + if (name) { + return `Hello 2.0.0, ${name}` + } else { + return undefined + } +} diff --git a/test/cases/import-duplicated-interface/local:http-request-http.js b/test/cases/import-duplicated-interface/local:http-request-http.js deleted file mode 100644 index 46526ebd..00000000 --- a/test/cases/import-duplicated-interface/local:http-request-http.js +++ /dev/null @@ -1,3 +0,0 @@ -export function run(endpoint) { - return endpoint; -} diff --git a/test/cases/import-duplicated-interface/local:http-request-part-two-http.js b/test/cases/import-duplicated-interface/local:http-request-part-two-http.js deleted file mode 100644 index 46526ebd..00000000 --- a/test/cases/import-duplicated-interface/local:http-request-part-two-http.js +++ /dev/null @@ -1,3 +0,0 @@ -export function run(endpoint) { - return endpoint; -} diff --git a/test/cases/import-duplicated-interface/source.js b/test/cases/import-duplicated-interface/source.js index caeba15c..c36e3a37 100644 --- a/test/cases/import-duplicated-interface/source.js +++ b/test/cases/import-duplicated-interface/source.js @@ -1,13 +1,14 @@ -import * as $local$e1ab0bfa$1 from 'local:http-request/http'; -import * as $local$15f12255$1 from 'local:http-request-part-two/http'; +import { hello as hello1 } from 'local:hello/hello'; +import { hello as hello2 } from 'local:hello-second/hello'; -export function call(parameters) { - console.log('call called with', parameters); - // $local$e1ab0bfa$1.import.run('http://example.com'); - // $local$15f12255$1.import.run('http://example.com'); - return parameters; -} - -export const actions = { - call, +export const exports = { + hello(str) { + if (str === 'hello') { + return `world ${str} (${hello1('world')})`; + } + if (str === 'hello-second') { + return `world ${str} (${hello2('world')})`; + } + return `world unknown ${str}`; + }, }; diff --git a/test/cases/import-duplicated-interface/test.js b/test/cases/import-duplicated-interface/test.js index d2788d82..fbb270da 100644 --- a/test/cases/import-duplicated-interface/test.js +++ b/test/cases/import-duplicated-interface/test.js @@ -1,18 +1,13 @@ import { strictEqual } from 'node:assert'; -export function test(instance, args) { +export function test(instance) { strictEqual( - instance['actions'].call({ - actionId: '123', - payload: { input: '' }, - }), - '' + instance.exports.hello('hello'), + 'world hello (Hello 1.0.0, world)' ); strictEqual( - instance['actions'].instance.call({ - actionId: '123', - payload: { input: '' }, - }), - 'http://example.com' + instance.exports.hello('hello-second'), + 'world hello-second (Hello 2.0.0, world)' ); + strictEqual(instance.exports.hello('unknown'), 'world unknown unknown'); } diff --git a/test/cases/import-duplicated-interface/wit/deps/local-hello-second/hello.wit b/test/cases/import-duplicated-interface/wit/deps/local-hello-second/hello.wit new file mode 100644 index 00000000..390b7d4a --- /dev/null +++ b/test/cases/import-duplicated-interface/wit/deps/local-hello-second/hello.wit @@ -0,0 +1,5 @@ +package local:hello-second; + +interface hello { + hello: func(name: option) -> option; +} diff --git a/test/cases/import-duplicated-interface/wit/deps/local-hello/hello.wit b/test/cases/import-duplicated-interface/wit/deps/local-hello/hello.wit new file mode 100644 index 00000000..c5a662c4 --- /dev/null +++ b/test/cases/import-duplicated-interface/wit/deps/local-hello/hello.wit @@ -0,0 +1,5 @@ +package local:hello; + +interface hello { + hello: func(name: string) -> string; +} diff --git a/test/cases/import-duplicated-interface/wit/deps/local-http-request-part-two/package.wit b/test/cases/import-duplicated-interface/wit/deps/local-http-request-part-two/package.wit deleted file mode 100644 index 21b21508..00000000 --- a/test/cases/import-duplicated-interface/wit/deps/local-http-request-part-two/package.wit +++ /dev/null @@ -1,6 +0,0 @@ -package local:http-request-part-two; - -interface http { - run: func(endpoint: string) -> result; -} - diff --git a/test/cases/import-duplicated-interface/wit/deps/local-http-request/package.wit b/test/cases/import-duplicated-interface/wit/deps/local-http-request/package.wit deleted file mode 100644 index 32a2e73f..00000000 --- a/test/cases/import-duplicated-interface/wit/deps/local-http-request/package.wit +++ /dev/null @@ -1,6 +0,0 @@ -package local:http-request; - -interface http { - run: func(endpoint: string) -> result; -} - diff --git a/test/cases/import-duplicated-interface/wit/world.wit b/test/cases/import-duplicated-interface/wit/world.wit index 2ecf6f1d..8514dc97 100644 --- a/test/cases/import-duplicated-interface/wit/world.wit +++ b/test/cases/import-duplicated-interface/wit/world.wit @@ -1,27 +1,10 @@ -package local:custom; +package test:test; -interface actions { - type json-string = string; +world hello { + import local:hello/hello; + import local:hello-second/hello; - record payload { - input: json-string, - } - - record input { - action-id: string, - payload: payload, - } - - record output { - %result: json-string, - } - - call: func(input: input) -> result; + export exports: interface { + hello: func(name: string) -> string; + } } - -world main { - import local:http-request/http; - import local:http-request-part-two/http; - - export actions; -} \ No newline at end of file From 83715702a63d03f78acd857de8fe612e855bd619 Mon Sep 17 00:00:00 2001 From: "s.vanriessen" Date: Fri, 24 Oct 2025 09:36:50 +0200 Subject: [PATCH 6/7] test: replace import override to test file --- .../src/bindgen.rs | 16 ++++++++++++++++ test/bindings.js | 4 ++-- test/cases/import-duplicated-interface/test.js | 4 ++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/crates/spidermonkey-embedding-splicer/src/bindgen.rs b/crates/spidermonkey-embedding-splicer/src/bindgen.rs index 75c89e2f..d0146cf1 100644 --- a/crates/spidermonkey-embedding-splicer/src/bindgen.rs +++ b/crates/spidermonkey-embedding-splicer/src/bindgen.rs @@ -1299,7 +1299,23 @@ fn binding_name(func_name: &str, iface_name: &Option) -> String { } } +/// Determine the binding name of a given import +/// example wit: +/// package local:hello; +/// interface greeter { +/// greet(name: string): string; +/// } +/// word main { +/// export greeter; +/// } +/// +/// # Arguments +/// * `func_name` - function name (e.g. `greet`) +/// * `iface_name` - an interface name, if present (e.g. `greeter`) +/// * `import_name` - qualified import specifier (e.g. `local:hello`) +/// fn binding_name_import(func_name: &str, iface_name: &Option, import_name: &str) -> String { + // import_name is only valid when FunctionKind is Freestanding if import_name != "<>" { let valid_import = import_name .chars() diff --git a/test/bindings.js b/test/bindings.js index 1154cfd5..7d08c6b7 100644 --- a/test/bindings.js +++ b/test/bindings.js @@ -97,8 +97,8 @@ suite('Bindings', async () => { if (impt.startsWith('wasi:')) continue; if (impt.startsWith('[')) impt = impt.slice(impt.indexOf(']') + 1); let importName = impt.split('/').pop(); - if (name === 'import-duplicated-interface') - importName = impt.replace('/', '-').replace(':', '-'); + if (testcase.importNameOverride) + importName = testcase.importNameOverride(impt); if (importName === 'test') importName = 'imports'; map[impt] = `../../cases/${name}/${importName}.js`; } diff --git a/test/cases/import-duplicated-interface/test.js b/test/cases/import-duplicated-interface/test.js index fbb270da..8d559149 100644 --- a/test/cases/import-duplicated-interface/test.js +++ b/test/cases/import-duplicated-interface/test.js @@ -11,3 +11,7 @@ export function test(instance) { ); strictEqual(instance.exports.hello('unknown'), 'world unknown unknown'); } + +export function importNameOverride(importName) { + return importName.replace('/', '-').replace(':', '-'); +} \ No newline at end of file From 083082c948896d9f85243136fe5ddd7729a92b45 Mon Sep 17 00:00:00 2001 From: "s.vanriessen" Date: Fri, 24 Oct 2025 09:38:17 +0200 Subject: [PATCH 7/7] chore: rename binding name function --- .../src/bindgen.rs | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/crates/spidermonkey-embedding-splicer/src/bindgen.rs b/crates/spidermonkey-embedding-splicer/src/bindgen.rs index d0146cf1..e66a15e8 100644 --- a/crates/spidermonkey-embedding-splicer/src/bindgen.rs +++ b/crates/spidermonkey-embedding-splicer/src/bindgen.rs @@ -174,7 +174,7 @@ pub fn componentize_bindgen( let mut import_bindings = Vec::new(); for (specifier, item) in bindgen.imports.iter() { // this import binding order matters - import_bindings.push(binding_name_import( + import_bindings.push(generate_binding_name_import( &item.resource.func_name(&item.name), &item.iface_name, specifier, @@ -205,8 +205,11 @@ pub fn componentize_bindgen( let item = items.first().unwrap(); if let Some(resource) = resource { let export_name = resource.to_upper_camel_case(); - let binding_name = - binding_name_import(&export_name, &item.iface_name, &item.binding_name); + let binding_name = generate_binding_name_import( + &export_name, + &item.iface_name, + &item.binding_name, + ); if item.iface { specifier_list.push(format!("{export_name}: import_{binding_name}")); } else { @@ -655,11 +658,12 @@ impl JsBindgen<'_> { let fn_name = func.item_name(); let fn_camel_name = fn_name.to_lower_camel_case(); - use binding_name_import as binding_name_fn; + use generate_binding_name_import as binding_name_fn; let (binding_name, resource) = match &func.kind { FunctionKind::Freestanding => { - let binding_name = binding_name_import(&fn_camel_name, &iface_name, &import_name); + let binding_name = + generate_binding_name_import(&fn_camel_name, &iface_name, &import_name); uwrite!(self.src, "\nfunction import_{binding_name}"); @@ -1314,7 +1318,11 @@ fn binding_name(func_name: &str, iface_name: &Option) -> String { /// * `iface_name` - an interface name, if present (e.g. `greeter`) /// * `import_name` - qualified import specifier (e.g. `local:hello`) /// -fn binding_name_import(func_name: &str, iface_name: &Option, import_name: &str) -> String { +fn generate_binding_name_import( + func_name: &str, + iface_name: &Option, + import_name: &str, +) -> String { // import_name is only valid when FunctionKind is Freestanding if import_name != "<>" { let valid_import = import_name