|
24 | 24 | /// }
|
25 | 25 | /// ```
|
26 | 26 | ///
|
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 |
32 | 28 | ///
|
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: |
41 | 30 | ///
|
42 | 31 | /// ```swift
|
43 | 32 | /// // Export a function to JavaScript with a custom namespace
|
44 | 33 | /// @JS("__Swift.Foundation.UUID") public func create() -> String {
|
45 | 34 | /// UUID().uuidString
|
46 | 35 | /// }
|
47 |
| -/// |
| 36 | +/// |
48 | 37 | /// // Export a class with a custom namespace (note that each method needs to specify the namespace)
|
49 | 38 | /// @JS("Utils.Greeters") class Greeter {
|
50 | 39 | /// var name: String
|
51 | 40 | ///
|
52 | 41 | /// @JS("Utils.Greeters") init(name: String) {
|
53 | 42 | /// self.name = name
|
54 | 43 | /// }
|
55 |
| -/// |
| 44 | +/// |
56 | 45 | /// @JS("Utils.Greeters") func greet() -> String {
|
57 | 46 | /// return "Hello, " + self.name + "!"
|
58 | 47 | /// }
|
59 |
| -/// |
| 48 | +/// |
60 | 49 | /// @JS("Utils.Greeters") func changeName(name: String) {
|
61 | 50 | /// self.name = name
|
62 | 51 | /// }
|
@@ -93,9 +82,15 @@ public macro JS() = Builtin.ExternalMacro
|
93 | 82 | /// const uuid = new globalThis.__Swift.Foundation.UUID.create(); // "1A83F0E0-F7F2-4FD1-8873-01A68CF79AF4"
|
94 | 83 | /// ```
|
95 | 84 | ///
|
| 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 | +/// |
96 | 91 | /// - Parameter namespace: A dot-separated string that defines the namespace hierarchy in JavaScript.
|
97 | 92 | /// Each segment becomes a nested object in the resulting JavaScript structure.
|
98 | 93 | ///
|
99 | 94 | /// - Important: This feature is still experimental. No API stability is guaranteed, and the API may change in future releases.
|
100 | 95 | @attached(peer)
|
101 |
| -public macro JS(_ namespace: String) = Builtin.ExternalMacro |
| 96 | +public macro JS(namespace: String? = nil) = Builtin.ExternalMacro |
0 commit comments