-
-
Notifications
You must be signed in to change notification settings - Fork 55
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BridgeJS: Macro extension to define namespace #405
Conversation
There was a problem hiding this 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:
-
For something like:
@JS("__Swift.Foundation") class UUID { @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?
-
About the
public 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.
7a2de9f
to
fff2554
Compare
fff2554
to
43a88d4
Compare
@kateinoigakukun sounds good, thanks for valuable feedback 🙇🏼♂️
|
BridgeJS: fix: run swiftformat BridgeJS: chore: extend docc documentaion with namespace example
43a88d4
to
e701702
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
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")
macroExample Swift code:
Generated TypeScript:
Testing
Included new tests within
Namespaces.swift