Skip to content

BridgeJS: Support custom exported type names - #814

Merged
krodak merged 2 commits into
swiftwasm:mainfrom
PassiveLogic:kr/export-type-names
Sep 16, 2026
Merged

krodak merged 2 commits into
swiftwasm:mainfrom
PassiveLogic:kr/export-type-names

Conversation

@krodak

@krodak krodak commented Sep 16, 2026

Copy link
Copy Markdown
Member

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.

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 self-assigned this Sep 16, 2026
@krodak
krodak merged commit 53e8cc1 into swiftwasm:main Sep 16, 2026
16 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