BridgeJS: support jsName for imported bindings#526
Merged
Conversation
…arget non-Swift/quoted JS property names (`Sources/JavaScriptKit/Macros.swift`). - Plumbed `jsName` through the imported-property IR (`Plugins/BridgeJS/Sources/BridgeJSSkeleton/BridgeJSSkeleton.swift`) and extraction (`Plugins/BridgeJS/Sources/BridgeJSCore/SwiftToSkeleton.swift`). - Updated TS→Swift generation to no longer drop quoted/invalid TS property names; it now emits Swift-safe identifiers plus `@JSGetter(jsName: ...)` / `@JSSetter(jsName: ...)` as needed (`Plugins/BridgeJS/Sources/TS2Swift/JavaScript/src/processor.js`). - Updated JS glue + generated `.d.ts` to use bracket property access and quote invalid TS property keys (`Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift`). - Updated snapshots; `swift test --package-path ./Plugins/BridgeJS` now passes (requires `npm ci` at repo root to provide `typescript`).
…erty name is a normal identifier, falling back to bracket access only when needed. - Implementation: `Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift` - Updated snapshots (including `Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/InvalidPropertyNames.Import.js:215`) - `swift test --package-path ./Plugins/BridgeJS` passes
- Updated macro APIs: `Sources/JavaScriptKit/Macros.swift` - Plumbed `jsName` through the imported skeleton + Swift parser: `Plugins/BridgeJS/Sources/BridgeJSSkeleton/BridgeJSSkeleton.swift`, `Plugins/BridgeJS/Sources/BridgeJSCore/SwiftToSkeleton.swift` - Updated JS glue + generated `.d.ts` to use the JS names (dot access when possible, bracket access when needed): `Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift` - Updated TS→Swift generator to emit `@JSClass(jsName: ...)` / `@JSFunction(jsName: ...)` when it has to sanitize names: `Plugins/BridgeJS/Sources/TS2Swift/JavaScript/src/processor.js` - Added coverage for a renamed class + quoted method name: `Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/InvalidPropertyNames.d.ts` (snapshots refreshed; `swift test --package-path ./Plugins/BridgeJS` passes)
…ecl`, then again via `visitStructuredType` when the same type showed up in `seenTypes`), which caused the duplicate `_Weird` interface in `InvalidPropertyNames.Import.d.ts`. - Change: `Plugins/BridgeJS/Sources/TS2Swift/JavaScript/src/processor.js` now records emitted class names in `emittedStructuredTypeNames` so the structured-type pass skips them. - Snapshots refreshed; `swift test --package-path ./Plugins/BridgeJS` passes.
…ass`. - Added new import API + XCTest: `Tests/BridgeJSRuntimeTests/bridge-js.d.ts`, `Tests/BridgeJSRuntimeTests/ImportAPITests.swift` - Wired JS-side implementations: `Tests/prelude.mjs` - Regenerated pre-generated files: `./Utilities/bridge-js-generate.sh` (updated `Tests/BridgeJSRuntimeTests/Generated/*`) - Verified: `SWIFT_SDK_ID=DEVELOPMENT-SNAPSHOT-2025-11-03-a-wasm32-unknown-wasip1 make unittest` passes
krodak
approved these changes
Jan 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Some JS APIs can’t be expressed as valid Swift identifiers (e.g. "method-with-dashes", "$Foo").
Plumb jsName through BridgeJS import generation for JSGetter/JSSetter/JSFunction/JSClass, teach TS2Swift to emit it when sanitizing names, and add runtime coverage for the new mappings.