Skip to content

Commit e91edce

Browse files
committed
BridgeJS: fix: unify macros to avoid duplication
1 parent 1561681 commit e91edce

File tree

1 file changed

+12
-17
lines changed

1 file changed

+12
-17
lines changed

Sources/JavaScriptKit/Macros.swift

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,39 +24,28 @@
2424
/// }
2525
/// ```
2626
///
27-
/// When you build your project with the BridgeJS plugin, these declarations will be
28-
/// accessible from JavaScript, and TypeScript declaration files (`.d.ts`) will be
29-
/// automatically generated to provide type safety.
30-
///
31-
/// For detailed usage information, see the article <doc:Exporting-Swift-to-JavaScript>.
27+
/// If you prefer to access through namespace-based syntax, you can use `namespace` parameter
3228
///
33-
/// - Important: This feature is still experimental. No API stability is guaranteed, and the API may change in future releases.
34-
@attached(peer)
35-
public macro JS() = Builtin.ExternalMacro
36-
37-
/// A macro that exposes Swift functions, classes, and methods to JavaScript.
38-
/// Additionally defines namespaces defined by `namespace` parameter
39-
///
40-
/// Apply this macro to Swift declarations that you want to make callable from JavaScript:
29+
/// Example:
4130
///
4231
/// ```swift
4332
/// // Export a function to JavaScript with a custom namespace
4433
/// @JS("__Swift.Foundation.UUID") public func create() -> String {
4534
/// UUID().uuidString
4635
/// }
47-
///
36+
///
4837
/// // Export a class with a custom namespace (note that each method needs to specify the namespace)
4938
/// @JS("Utils.Greeters") class Greeter {
5039
/// var name: String
5140
///
5241
/// @JS("Utils.Greeters") init(name: String) {
5342
/// self.name = name
5443
/// }
55-
///
44+
///
5645
/// @JS("Utils.Greeters") func greet() -> String {
5746
/// return "Hello, " + self.name + "!"
5847
/// }
59-
///
48+
///
6049
/// @JS("Utils.Greeters") func changeName(name: String) {
6150
/// self.name = name
6251
/// }
@@ -93,9 +82,15 @@ public macro JS() = Builtin.ExternalMacro
9382
/// const uuid = new globalThis.__Swift.Foundation.UUID.create(); // "1A83F0E0-F7F2-4FD1-8873-01A68CF79AF4"
9483
/// ```
9584
///
85+
/// When you build your project with the BridgeJS plugin, these declarations will be
86+
/// accessible from JavaScript, and TypeScript declaration files (`.d.ts`) will be
87+
/// automatically generated to provide type safety.
88+
///
89+
/// For detailed usage information, see the article <doc:Exporting-Swift-to-JavaScript>.
90+
///
9691
/// - Parameter namespace: A dot-separated string that defines the namespace hierarchy in JavaScript.
9792
/// Each segment becomes a nested object in the resulting JavaScript structure.
9893
///
9994
/// - Important: This feature is still experimental. No API stability is guaranteed, and the API may change in future releases.
10095
@attached(peer)
101-
public macro JS(_ namespace: String) = Builtin.ExternalMacro
96+
public macro JS(namespace: String? = nil) = Builtin.ExternalMacro

0 commit comments

Comments
 (0)