Skip to content

Comments

BridgeJS: Fix static method and constructor codegen dropping default parameter values#669

Merged
kateinoigakukun merged 1 commit intoswiftwasm:mainfrom
PassiveLogic:kr/fix-static-method-default-values
Feb 21, 2026
Merged

BridgeJS: Fix static method and constructor codegen dropping default parameter values#669
kateinoigakukun merged 1 commit intoswiftwasm:mainfrom
PassiveLogic:kr/fix-static-method-default-values

Conversation

@krodak
Copy link
Member

@krodak krodak commented Feb 20, 2026

Overview

Three codegen paths in BridgeJSLink.swift constructed JS parameter lists by joining parameter names directly, ignoring default values. This caused a mismatch where .d.ts declarations correctly marked defaulted parameters as optional (?), but the generated .js omitted the defaults - so calling e.g. MathOperations.subtract(10) from TypeScript would compile but pass undefined at runtime instead of the Swift default.

1. renderEnumStaticFunction and 2. renderStaticMethodForExportObject both used parameters.map { $0.name }.joined(separator: ", ") instead of DefaultValueUtils.formatParameterList(parameters). The fix applies the same pattern already used by constructor codegen and import-side method codegen.

3. Global namespace constructor .d.ts rendering manually formatted constructor parameters without checking param.hasDefault, so the ? marker was missing. Added the optional suffix check inline.

Before:

subtract: function(a, b) {

After:

subtract: function(a, b = 5.0) {

Added an E2E test that calls MathOperations.subtract(10.0) (omitting the defaulted b parameter) and asserts it returns 5.0.

@krodak krodak self-assigned this Feb 20, 2026
@krodak krodak force-pushed the kr/fix-static-method-default-values branch from 4ae9e79 to c702ac2 Compare February 20, 2026 17:35
@kateinoigakukun kateinoigakukun merged commit 97933a2 into swiftwasm:main Feb 21, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants