Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

BridgeJS: Macro extension to define namespace#405

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

@krodak
Copy link
Member

@krodakkrodak commentedAug 14, 2025
edited
Loading

Introduction

This PR adds namespace-based convention support to the BridgeJS@JS macro, which enables creating TypeScript namespaces that are accessible globally in JavaScript, while maintaining direct export access.

Reasoning

Change allows up to align better with existing code conventions, but we believe it could be useful for others as well, without breaking any existing functionality

Feature example

New@JS(namespace: "my.namespace") macro

Example Swift code:

@JS(namespace:"__Swift.Foundation.UUID.create")func createUUID()->String{UUID().uuidString}@JS(namespace:"__Swift.Foundation.UUID.validate")func validateUUID(_ uuid:String)->Bool{UUID(uuidString: uuid)!=nil}

Generated TypeScript:

export{};declare global{namespace__Swift{namespaceFoundation{namespaceUUID{functioncreate():string;functionvalidate(uuid:string):boolean;}}}}exporttypeExports={create():string;validate(uuid:string):boolean;}

Testing

Included new tests withinNamespaces.swift

Copy link
Member

@kateinoigakukunkateinoigakukun left a comment

Choose a reason for hiding this comment

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

Thanks for the PR, much appreciated!

I have a couple of questions:

  1. For something like:

    @JS("__Swift.Foundation")classUUID{@JS("__Swift.Foundation")func uuidString()->String{Foundation.UUID().uuidString}}

    Do we actually need the namespace attribute on uuidString here? It seems that namespace on method decl is currently ignored. For such cases where namespace has no effect, it might be less confusing to emit an error or warning. In other words, how about restricting namespace parameter only for top-level declarations?

  2. About thepublic macro JS(_ namespace: String) interface:
    To keep it simple but extensible, how about changing it topublic macro JS(namespace: String? = nil)?. Using a labeled parameter leaves room for adding more String parameters in the future. Also since macros can have default arguments, we probably don't need to have a dedicated overload. This would allow us to document both@JS and@JS(namespace:) together in a single DocC page.

krodak reacted with thumbs up emoji
@krodak
Copy link
MemberAuthor

@kateinoigakukun sounds good, thanks for valuable feedback 🙇🏼‍♂️

  • added warnings for non-top-level namespaces on functions and init
    • aligned examples and tests to reflect that
  • merged macros; was considering this, but wanted to avoid changing existing one, if you are fine with that, I think it's nicer this way 👌🏻
  • added example to existing docc documentation now that you mentioned this 🙏🏻
  • fixed swiftformat issues, added to pre-commit hooks, so hopefully won't break CI again
  • cleaned up commits a bit to prefix withBridgeJS

BridgeJS: fix: run swiftformatBridgeJS: chore: extend docc documentaion with namespace example
Copy link
Member

@kateinoigakukunkateinoigakukun left a comment

Choose a reason for hiding this comment

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

Thanks!

@kateinoigakukunkateinoigakukun merged commit5a553c4 intoswiftwasm:mainAug 15, 2025
13 of 16 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@kateinoigakukunkateinoigakukunkateinoigakukun approved these changes

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@krodak@kateinoigakukun

[8]ページ先頭

©2009-2025 Movatter.jp