Skip to content

Conversation

@kateinoigakukun
Copy link
Member

…s) end-to-end in BridgeJS.

- `Plugins/BridgeJS/Sources/BridgeJSCore/ImportSwiftMacros.swift`: collect top-level `@JSGetter` vars into the imported skeleton instead of erroring.
- `Plugins/BridgeJS/Sources/BridgeJSSkeleton/BridgeJSSkeleton.swift`: add `ImportedFileSkeleton.globalGetters` (+ Codable backward-compat) and make `ImportedGetterSkeleton.abiName(context:)` accept `nil`.
- `Plugins/BridgeJS/Sources/BridgeJSCore/ImportTS.swift`: generate Swift thunks for global getters as `_$<name>_get()` calling the wasm import `bjs_<name>_get`.
- `Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift`: generate JS import glue for global getters as `imports["<name>"]` and emit `readonly <name>: <type>` in `Imports`.
- Added test+snapshots: `Plugins/BridgeJS/Tests/BridgeJSToolTests/ImportMacroInputs/GlobalGetter.swift`, `Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalGetter.ImportMacros.js`, `Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalGetter.ImportMacros.d.ts`.
- `Plugins/BridgeJS/Package.swift`: exclude `ImportMacroInputs` from being compiled as test sources.

Run: `swift test --package-path ./Plugins/BridgeJS`

To bind actual globals, pass `globalThis` as the `imports` object on the JS side (so the generated glue reads `imports["console"]`, `imports["document"]`, etc.).
Copy link
Member

@MaxDesiatov MaxDesiatov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks.

@MaxDesiatov MaxDesiatov added the enhancement New feature or request label Jan 21, 2026
@kateinoigakukun kateinoigakukun merged commit 724e62e into swiftwasm:main Jan 21, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants