Skip to content

BridgeJS: Fix name collision for same-named nested structs#744

Merged
krodak merged 1 commit into
swiftwasm:mainfrom
PassiveLogic:kr/fix-nested-struct-name-collision
May 13, 2026
Merged

BridgeJS: Fix name collision for same-named nested structs#744
krodak merged 1 commit into
swiftwasm:mainfrom
PassiveLogic:kr/fix-nested-struct-name-collision

Conversation

@krodak
Copy link
Copy Markdown
Member

@krodak krodak commented May 11, 2026

Overview

Follow-up to #735. When two different parent types both have a nested struct with the same short name (e.g., User.Stats and Player.Stats), the generated JavaScript produces duplicate const declarations and overwrites the same structHelpers.Stats key, causing a SyntaxError at parse time.

1. JS struct helpers use abiName (underscore-separated) for unique internal keys. structHelpers.User_Stats and structHelpers.Player_Stats instead of both being structHelpers.Stats. This covers helper factories, registration, and all structHelpers.<name>.lower/lift() call sites in both BridgeJSLink.swift and JSGlueGen.swift.

2. TypeScript declarations use TS namespaces for nested struct interfaces. Instead of export interface User_Stats, the .d.ts now emits:

export namespace User {
    export interface Stats { ... }
}

This matches the existing namespace pattern used for enums and keeps the public API hierarchical. The NamespaceBuilder was extended to handle structs alongside enums/classes. Struct-only namespace nodes are excluded from the Exports type to avoid duplicate keys.

3. tsType for .swiftStruct returns the dotted name directly (e.g., User.Stats), which TypeScript resolves through the namespace. Non-nested structs are unaffected.

4. E2e runtime test added. NestedStructGroupA.Metadata and NestedStructGroupB.Metadata (two same-named structs under different namespace enums) are roundtripped through JS to verify no data corruption from helper key collision.

@krodak krodak force-pushed the kr/fix-nested-struct-name-collision branch from adf1074 to d0939f0 Compare May 11, 2026 16:08
@krodak krodak self-assigned this May 11, 2026
@krodak krodak requested a review from kateinoigakukun May 11, 2026 16:50
@krodak krodak force-pushed the kr/fix-nested-struct-name-collision branch from d0939f0 to 871815e Compare May 13, 2026 09:46
@krodak krodak marked this pull request as draft May 13, 2026 10:31
@krodak krodak force-pushed the kr/fix-nested-struct-name-collision branch from 871815e to 8a0f54e Compare May 13, 2026 10:44
@krodak krodak marked this pull request as ready for review May 13, 2026 11:06
@krodak krodak enabled auto-merge May 13, 2026 11:45
@krodak krodak merged commit 0aeed7b into swiftwasm:main May 13, 2026
13 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.

3 participants