Skip to content

BridgeJS: Support custom exported type names - #23

Closed
krodak wants to merge 2 commits into
mainfrom
kr/export-type-names
Closed

krodak wants to merge 2 commits into
mainfrom
kr/export-type-names

Conversation

@krodak

@krodak krodak commented Sep 15, 2026

Copy link
Copy Markdown
Collaborator

Overview

Extend the @JS("name") support for functions, methods, and properties added in swiftwasm/JavaScriptKit#801 to exported classes, structs, enums, and protocols. Swift wrappers can keep implementation-specific names while presenting a cleaner JavaScript and TypeScript API.

@JS("Counter") class InternalCounter {
    @JS var value: Int

    @JS init(value: Int) {
        self.value = value
    }
}

JavaScript constructs this class through new exports.Counter(1), and TypeScript uses the generated Counter interface. Swift still uses InternalCounter.

The skeleton keeps Swift identities and ABI namespaces separate from public names and namespace paths. The linker uses public names in constructors, signatures, callbacks, default arguments, enum value objects, and nested exports. Renaming a parent does not change descendant Swift thunk symbols.

Nested types also inherit an enclosing class or struct's explicit namespace, matching namespace enums. This applies to unrenamed declarations too; nested types cannot specify their own namespace.

A name override cannot be combined with @JS(as:): renaming changes the API spelling, not its representation or memory-management semantics. Constructors remain instance-owned, and pointer-identity behavior is unchanged.

Cross-declaration collision diagnostics intentionally remain out of scope, matching existing export-name behavior. I'm happy to add them if needed.

Test Plan

  • ./Utilities/format.swift
  • swift test --package-path ./Plugins/BridgeJS --disable-experimental-prebuilts --scratch-path <isolated-build> with the default SwiftSyntax version and BRIDGEJS_OVERRIDE_SWIFT_SYNTAX_VERSION set to 601.0.0, 602.0.0, and 603.0.0, each in a separate build directory.
  • ./Utilities/bridge-js-generate.sh
  • npm run check:bridgejs-dts
  • npm run test:runtime
  • make unittest BUILD_SYSTEM=native SWIFT_SDK_ID=swift-6.3.1-RELEASE_wasm

@krodak
krodak force-pushed the kr/export-type-names branch from 27272e9 to 1711b35 Compare September 15, 2026 13:17
@krodak krodak closed this Sep 16, 2026
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.

1 participant