Skip to content

BridgeJS: Correctly emit @JS methods in extensions#694

Open
wfltaylor wants to merge 5 commits intoswiftwasm:mainfrom
wfltaylor:extensions
Open

BridgeJS: Correctly emit @JS methods in extensions#694
wfltaylor wants to merge 5 commits intoswiftwasm:mainfrom
wfltaylor:extensions

Conversation

@wfltaylor
Copy link

Currently, code generation for @js extension methods is broken: the @_cdecl wrapper misses the self parameter.

Copy link
Member

@kateinoigakukun kateinoigakukun left a comment

Choose a reason for hiding this comment

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

Nice catch! Can you add more test cases to cover class, struct and enum in snapshot tests and runtimr tests?

@wfltaylor
Copy link
Author

Nice catch! Can you add more test cases to cover class, struct and enum in snapshot tests and runtimr tests?

I’ve added some runtime tests and some more snapshot tests.

@krodak
Copy link
Member

krodak commented Mar 11, 2026

@wfltaylor this is great 🙌🏻 would you resolving CI issues?

Also, if that's not a trouble to ask, could we get some addition on support for extension mentioned in Documentation.docc ? 🙏🏻

The best place to document extension support is in the existing per-type articles under Sources/JavaScriptKit/Documentation.docc/Articles/BridgeJS/Exporting-Swift/, maybe in `Exporting-Swift-Class.md - add a section (e.g., "Adding Members via Extensions") after the main example showing that @js func/@js var/@js static func can be added in extension Greeter { ... } blocks, including cross-file. Update the "Supported Features" table to include "Extension methods/properties" as supported.
Then in Exporting-Swift-Struct.md, Exporting-Swift-Enum.md we could just mention in in Supported Features table?

Worth noting that extensions must target @JS-annotated types from the same module, and that the extension block itself does not need @js - only the individual members do

@krodak
Copy link
Member

krodak commented Mar 11, 2026

@wfltaylor hey, hope you don't mind - I pushed a commit fixing the CI issues and adding the docs/diagnostics improvements I mentioned in the review 🙌🏻

Here's what's in there:

  • Updated SwiftStruct.js/.d.ts snapshots (they were stale - had DataPoint.distanceFromOrigin() from an older draft and were missing Vector2D)
  • Fixed Tests/prelude.mjs - structs use exports.Vector2D.init() not new exports.Vector2D()
  • Ran the formatter on JSClosure+AsyncTests.swift
  • Added extension docs to the Exporting-Swift-Class.md article + updated supported features tables in Class/Struct/Enum docs
  • Added a protocol extension diagnostic in resolveExtension() - gives a clear error instead of generic "Unsupported type"
  • Added a doc comment about the namespace collision limitation on resolveExtension()

CI is green on all jobs 🟢

@krodak krodak requested a review from kateinoigakukun March 11, 2026 12:22
@wfltaylor
Copy link
Author

@wfltaylor hey, hope you don't mind - I pushed a commit fixing the CI issues and adding the docs/diagnostics improvements I mentioned in the review 🙌🏻

Here's what's in there:

  • Updated SwiftStruct.js/.d.ts snapshots (they were stale - had DataPoint.distanceFromOrigin() from an older draft and were missing Vector2D)
  • Fixed Tests/prelude.mjs - structs use exports.Vector2D.init() not new exports.Vector2D()
  • Ran the formatter on JSClosure+AsyncTests.swift
  • Added extension docs to the Exporting-Swift-Class.md article + updated supported features tables in Class/Struct/Enum docs
  • Added a protocol extension diagnostic in resolveExtension() - gives a clear error instead of generic "Unsupported type"
  • Added a doc comment about the namespace collision limitation on resolveExtension()

CI is green on all jobs 🟢

Thank you! Apologies about the testing issues, I’ve had a few problems running the runtime tests locally (I think I’ve figured it out now). Changes all look good to me.

@krodak krodak self-requested a review March 11, 2026 12:37
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