Skip to content

Commit edabb97

Browse files
BridgeJS: emit typed throws without extra space (#571)
1 parent bc61038 commit edabb97

File tree

5 files changed

+91
-91
lines changed

5 files changed

+91
-91
lines changed

Benchmarks/Sources/Generated/BridgeJS.Macros.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
@_spi(Experimental) @_spi(BridgeJS) import JavaScriptKit
88

9-
@JSFunction func benchmarkHelperNoop() throws (JSException) -> Void
9+
@JSFunction func benchmarkHelperNoop() throws(JSException) -> Void
1010

11-
@JSFunction func benchmarkHelperNoopWithNumber(_ n: Double) throws (JSException) -> Void
11+
@JSFunction func benchmarkHelperNoopWithNumber(_ n: Double) throws(JSException) -> Void
1212

13-
@JSFunction func benchmarkRunner(_ name: String, _ body: JSObject) throws (JSException) -> Void
13+
@JSFunction func benchmarkRunner(_ name: String, _ body: JSObject) throws(JSException) -> Void

Examples/PlayBridgeJS/Sources/PlayBridgeJS/Generated/BridgeJS.Macros.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
@_spi(Experimental) @_spi(BridgeJS) import JavaScriptKit
88

9-
@JSFunction func createTS2Swift() throws (JSException) -> TS2Swift
9+
@JSFunction func createTS2Swift() throws(JSException) -> TS2Swift
1010

1111
@JSClass struct TS2Swift {
12-
@JSFunction func convert(_ ts: String) throws (JSException) -> String
12+
@JSFunction func convert(_ ts: String) throws(JSException) -> String
1313
}

Plugins/BridgeJS/Sources/TS2Swift/JavaScript/src/processor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,7 @@ export class TypeProcessor {
874874
if (effects?.isAsync) {
875875
parts.push("async");
876876
}
877-
parts.push("throws (JSException)");
877+
parts.push("throws(JSException)");
878878
return parts.join(" ");
879879
}
880880

Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/__snapshots__/ts2swift.test.js.snap

Lines changed: 61 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ exports[`ts2swift > snapshots Swift output for ArrayParameter.d.ts > ArrayParame
99
1010
@_spi(Experimental) @_spi(BridgeJS) import JavaScriptKit
1111
12-
@JSFunction func checkArray(_ a: JSObject) throws (JSException) -> Void
12+
@JSFunction func checkArray(_ a: JSObject) throws(JSException) -> Void
1313
14-
@JSFunction func checkArrayWithLength(_ a: JSObject, _ b: Double) throws (JSException) -> Void
14+
@JSFunction func checkArrayWithLength(_ a: JSObject, _ b: Double) throws(JSException) -> Void
1515
16-
@JSFunction func checkArray(_ a: JSObject) throws (JSException) -> Void
16+
@JSFunction func checkArray(_ a: JSObject) throws(JSException) -> Void
1717
"
1818
`;
1919

@@ -26,19 +26,19 @@ exports[`ts2swift > snapshots Swift output for Async.d.ts > Async 1`] = `
2626
2727
@_spi(Experimental) @_spi(BridgeJS) import JavaScriptKit
2828
29-
@JSFunction func asyncReturnVoid() throws (JSException) -> JSPromise
29+
@JSFunction func asyncReturnVoid() throws(JSException) -> JSPromise
3030
31-
@JSFunction func asyncRoundTripInt(_ v: Double) throws (JSException) -> JSPromise
31+
@JSFunction func asyncRoundTripInt(_ v: Double) throws(JSException) -> JSPromise
3232
33-
@JSFunction func asyncRoundTripString(_ v: String) throws (JSException) -> JSPromise
33+
@JSFunction func asyncRoundTripString(_ v: String) throws(JSException) -> JSPromise
3434
35-
@JSFunction func asyncRoundTripBool(_ v: Bool) throws (JSException) -> JSPromise
35+
@JSFunction func asyncRoundTripBool(_ v: Bool) throws(JSException) -> JSPromise
3636
37-
@JSFunction func asyncRoundTripFloat(_ v: Double) throws (JSException) -> JSPromise
37+
@JSFunction func asyncRoundTripFloat(_ v: Double) throws(JSException) -> JSPromise
3838
39-
@JSFunction func asyncRoundTripDouble(_ v: Double) throws (JSException) -> JSPromise
39+
@JSFunction func asyncRoundTripDouble(_ v: Double) throws(JSException) -> JSPromise
4040
41-
@JSFunction func asyncRoundTripJSObject(_ v: JSObject) throws (JSException) -> JSPromise
41+
@JSFunction func asyncRoundTripJSObject(_ v: JSObject) throws(JSException) -> JSPromise
4242
"
4343
`;
4444

@@ -51,11 +51,11 @@ exports[`ts2swift > snapshots Swift output for Interface.d.ts > Interface 1`] =
5151
5252
@_spi(Experimental) @_spi(BridgeJS) import JavaScriptKit
5353
54-
@JSFunction func returnAnimatable() throws (JSException) -> Animatable
54+
@JSFunction func returnAnimatable() throws(JSException) -> Animatable
5555
5656
@JSClass struct Animatable {
57-
@JSFunction func animate(_ keyframes: JSObject, _ options: JSObject) throws (JSException) -> JSObject
58-
@JSFunction func getAnimations(_ options: JSObject) throws (JSException) -> JSObject
57+
@JSFunction func animate(_ keyframes: JSObject, _ options: JSObject) throws(JSException) -> JSObject
58+
@JSFunction func getAnimations(_ options: JSObject) throws(JSException) -> JSObject
5959
}
6060
"
6161
`;
@@ -69,42 +69,42 @@ exports[`ts2swift > snapshots Swift output for InvalidPropertyNames.d.ts > Inval
6969
7070
@_spi(Experimental) @_spi(BridgeJS) import JavaScriptKit
7171
72-
@JSFunction func createArrayBuffer() throws (JSException) -> ArrayBufferLike
72+
@JSFunction func createArrayBuffer() throws(JSException) -> ArrayBufferLike
7373
7474
@JSClass struct ArrayBufferLike {
7575
@JSGetter var byteLength: Double
76-
@JSFunction func slice(_ begin: Double, _ end: Double) throws (JSException) -> ArrayBufferLike
76+
@JSFunction func slice(_ begin: Double, _ end: Double) throws(JSException) -> ArrayBufferLike
7777
}
7878
79-
@JSFunction func createWeirdObject() throws (JSException) -> WeirdNaming
79+
@JSFunction func createWeirdObject() throws(JSException) -> WeirdNaming
8080
8181
@JSClass struct WeirdNaming {
8282
@JSGetter var normalProperty: String
83-
@JSSetter func setNormalProperty(_ value: String) throws (JSException)
83+
@JSSetter func setNormalProperty(_ value: String) throws(JSException)
8484
@JSGetter(jsName: "property-with-dashes") var property_with_dashes: Double
85-
@JSSetter(jsName: "property-with-dashes") func setProperty_with_dashes(_ value: Double) throws (JSException)
85+
@JSSetter(jsName: "property-with-dashes") func setProperty_with_dashes(_ value: Double) throws(JSException)
8686
@JSGetter(jsName: "123invalidStart") var _123invalidStart: Bool
87-
@JSSetter(jsName: "123invalidStart") func set_123invalidStart(_ value: Bool) throws (JSException)
87+
@JSSetter(jsName: "123invalidStart") func set_123invalidStart(_ value: Bool) throws(JSException)
8888
@JSGetter(jsName: "property with spaces") var property_with_spaces: String
89-
@JSSetter(jsName: "property with spaces") func setProperty_with_spaces(_ value: String) throws (JSException)
89+
@JSSetter(jsName: "property with spaces") func setProperty_with_spaces(_ value: String) throws(JSException)
9090
@JSGetter(jsName: "@specialChar") var _specialChar: Double
91-
@JSSetter(jsName: "@specialChar") func set_specialChar(_ value: Double) throws (JSException)
91+
@JSSetter(jsName: "@specialChar") func set_specialChar(_ value: Double) throws(JSException)
9292
@JSGetter var constructor: String
93-
@JSSetter func setConstructor(_ value: String) throws (JSException)
93+
@JSSetter func setConstructor(_ value: String) throws(JSException)
9494
@JSGetter var \`for\`: String
95-
@JSSetter func setFor(_ value: String) throws (JSException)
95+
@JSSetter func setFor(_ value: String) throws(JSException)
9696
@JSGetter var \`Any\`: String
97-
@JSSetter(jsName: "Any") func setAny(_ value: String) throws (JSException)
98-
@JSFunction func \`as\`() throws (JSException) -> Void
99-
@JSFunction func \`try\`() throws (JSException) -> Void
97+
@JSSetter(jsName: "Any") func setAny(_ value: String) throws(JSException)
98+
@JSFunction func \`as\`() throws(JSException) -> Void
99+
@JSFunction func \`try\`() throws(JSException) -> Void
100100
}
101101
102102
@JSClass(jsName: "$Weird") struct _Weird {
103-
@JSFunction init() throws (JSException)
104-
@JSFunction(jsName: "method-with-dashes") func method_with_dashes() throws (JSException) -> Void
103+
@JSFunction init() throws(JSException)
104+
@JSFunction(jsName: "method-with-dashes") func method_with_dashes() throws(JSException) -> Void
105105
}
106106
107-
@JSFunction func createWeirdClass() throws (JSException) -> _Weird
107+
@JSFunction func createWeirdClass() throws(JSException) -> _Weird
108108
"
109109
`;
110110
@@ -117,29 +117,29 @@ exports[`ts2swift > snapshots Swift output for MultipleImportedTypes.d.ts > Mult
117117
118118
@_spi(Experimental) @_spi(BridgeJS) import JavaScriptKit
119119
120-
@JSFunction func createDatabaseConnection(_ config: JSObject) throws (JSException) -> DatabaseConnection
120+
@JSFunction func createDatabaseConnection(_ config: JSObject) throws(JSException) -> DatabaseConnection
121121
122122
@JSClass struct DatabaseConnection {
123-
@JSFunction func connect(_ url: String) throws (JSException) -> Void
124-
@JSFunction func execute(_ query: String) throws (JSException) -> JSObject
123+
@JSFunction func connect(_ url: String) throws(JSException) -> Void
124+
@JSFunction func execute(_ query: String) throws(JSException) -> JSObject
125125
@JSGetter var isConnected: Bool
126126
@JSGetter var connectionTimeout: Double
127-
@JSSetter func setConnectionTimeout(_ value: Double) throws (JSException)
127+
@JSSetter func setConnectionTimeout(_ value: Double) throws(JSException)
128128
}
129129
130-
@JSFunction func createLogger(_ level: String) throws (JSException) -> Logger
130+
@JSFunction func createLogger(_ level: String) throws(JSException) -> Logger
131131
132132
@JSClass struct Logger {
133-
@JSFunction func log(_ message: String) throws (JSException) -> Void
134-
@JSFunction func error(_ message: String, _ error: JSObject) throws (JSException) -> Void
133+
@JSFunction func log(_ message: String) throws(JSException) -> Void
134+
@JSFunction func error(_ message: String, _ error: JSObject) throws(JSException) -> Void
135135
@JSGetter var level: String
136136
}
137137
138-
@JSFunction func getConfigManager() throws (JSException) -> ConfigManager
138+
@JSFunction func getConfigManager() throws(JSException) -> ConfigManager
139139
140140
@JSClass struct ConfigManager {
141-
@JSFunction func get(_ key: String) throws (JSException) -> JSObject
142-
@JSFunction func set(_ key: String, _ value: JSObject) throws (JSException) -> Void
141+
@JSFunction func get(_ key: String) throws(JSException) -> JSObject
142+
@JSFunction func set(_ key: String, _ value: JSObject) throws(JSException) -> Void
143143
@JSGetter var configPath: String
144144
}
145145
"
@@ -154,7 +154,7 @@ exports[`ts2swift > snapshots Swift output for PrimitiveParameters.d.ts > Primit
154154
155155
@_spi(Experimental) @_spi(BridgeJS) import JavaScriptKit
156156
157-
@JSFunction func check(_ a: Double, _ b: Bool) throws (JSException) -> Void
157+
@JSFunction func check(_ a: Double, _ b: Bool) throws(JSException) -> Void
158158
"
159159
`;
160160
@@ -167,9 +167,9 @@ exports[`ts2swift > snapshots Swift output for PrimitiveReturn.d.ts > PrimitiveR
167167
168168
@_spi(Experimental) @_spi(BridgeJS) import JavaScriptKit
169169
170-
@JSFunction func checkNumber() throws (JSException) -> Double
170+
@JSFunction func checkNumber() throws(JSException) -> Double
171171
172-
@JSFunction func checkBoolean() throws (JSException) -> Bool
172+
@JSFunction func checkBoolean() throws(JSException) -> Bool
173173
"
174174
`;
175175
@@ -182,11 +182,11 @@ exports[`ts2swift > snapshots Swift output for ReExportFrom.d.ts > ReExportFrom
182182
183183
@_spi(Experimental) @_spi(BridgeJS) import JavaScriptKit
184184
185-
@JSFunction func jsRoundTripNumber(_ v: Double) throws (JSException) -> Double
185+
@JSFunction func jsRoundTripNumber(_ v: Double) throws(JSException) -> Double
186186
187187
@JSClass struct JsGreeter {
188-
@JSFunction init(_ name: String) throws (JSException)
189-
@JSFunction func greet() throws (JSException) -> String
188+
@JSFunction init(_ name: String) throws(JSException)
189+
@JSFunction func greet() throws(JSException) -> String
190190
}
191191
"
192192
`;
@@ -206,9 +206,9 @@ enum FeatureFlag: String {
206206
}
207207
extension FeatureFlag: _BridgedSwiftEnumNoPayload, _BridgedSwiftRawValueEnum {}
208208
209-
@JSFunction func takesFeatureFlag(_ flag: FeatureFlag) throws (JSException) -> Void
209+
@JSFunction func takesFeatureFlag(_ flag: FeatureFlag) throws(JSException) -> Void
210210
211-
@JSFunction func returnsFeatureFlag() throws (JSException) -> FeatureFlag
211+
@JSFunction func returnsFeatureFlag() throws(JSException) -> FeatureFlag
212212
"
213213
`;
214214
@@ -221,9 +221,9 @@ exports[`ts2swift > snapshots Swift output for StringParameter.d.ts > StringPara
221221
222222
@_spi(Experimental) @_spi(BridgeJS) import JavaScriptKit
223223
224-
@JSFunction func checkString(_ a: String) throws (JSException) -> Void
224+
@JSFunction func checkString(_ a: String) throws(JSException) -> Void
225225
226-
@JSFunction func checkStringWithLength(_ a: String, _ b: Double) throws (JSException) -> Void
226+
@JSFunction func checkStringWithLength(_ a: String, _ b: Double) throws(JSException) -> Void
227227
"
228228
`;
229229
@@ -236,7 +236,7 @@ exports[`ts2swift > snapshots Swift output for StringReturn.d.ts > StringReturn
236236
237237
@_spi(Experimental) @_spi(BridgeJS) import JavaScriptKit
238238
239-
@JSFunction func checkString() throws (JSException) -> String
239+
@JSFunction func checkString() throws(JSException) -> String
240240
"
241241
`;
242242
@@ -249,18 +249,18 @@ exports[`ts2swift > snapshots Swift output for TS2SkeletonLike.d.ts > TS2Skeleto
249249
250250
@_spi(Experimental) @_spi(BridgeJS) import JavaScriptKit
251251
252-
@JSFunction func createTS2Skeleton() throws (JSException) -> TypeScriptProcessor
252+
@JSFunction func createTS2Skeleton() throws(JSException) -> TypeScriptProcessor
253253
254254
@JSClass struct TypeScriptProcessor {
255-
@JSFunction func convert(_ ts: String) throws (JSException) -> String
256-
@JSFunction func validate(_ ts: String) throws (JSException) -> Bool
255+
@JSFunction func convert(_ ts: String) throws(JSException) -> String
256+
@JSFunction func validate(_ ts: String) throws(JSException) -> Bool
257257
@JSGetter var version: String
258258
}
259259
260-
@JSFunction func createCodeGenerator(_ format: String) throws (JSException) -> CodeGenerator
260+
@JSFunction func createCodeGenerator(_ format: String) throws(JSException) -> CodeGenerator
261261
262262
@JSClass struct CodeGenerator {
263-
@JSFunction func generate(_ input: JSObject) throws (JSException) -> String
263+
@JSFunction func generate(_ input: JSObject) throws(JSException) -> String
264264
@JSGetter var outputFormat: String
265265
}
266266
"
@@ -275,7 +275,7 @@ exports[`ts2swift > snapshots Swift output for TypeAlias.d.ts > TypeAlias 1`] =
275275
276276
@_spi(Experimental) @_spi(BridgeJS) import JavaScriptKit
277277
278-
@JSFunction func checkSimple(_ a: Double) throws (JSException) -> Void
278+
@JSFunction func checkSimple(_ a: Double) throws(JSException) -> Void
279279
"
280280
`;
281281
@@ -290,11 +290,11 @@ exports[`ts2swift > snapshots Swift output for TypeScriptClass.d.ts > TypeScript
290290
291291
@JSClass struct Greeter {
292292
@JSGetter var name: String
293-
@JSSetter func setName(_ value: String) throws (JSException)
293+
@JSSetter func setName(_ value: String) throws(JSException)
294294
@JSGetter var age: Double
295-
@JSFunction init(_ name: String) throws (JSException)
296-
@JSFunction func greet() throws (JSException) -> String
297-
@JSFunction func changeName(_ name: String) throws (JSException) -> Void
295+
@JSFunction init(_ name: String) throws(JSException)
296+
@JSFunction func greet() throws(JSException) -> String
297+
@JSFunction func changeName(_ name: String) throws(JSException) -> Void
298298
}
299299
"
300300
`;
@@ -308,6 +308,6 @@ exports[`ts2swift > snapshots Swift output for VoidParameterVoidReturn.d.ts > Vo
308308
309309
@_spi(Experimental) @_spi(BridgeJS) import JavaScriptKit
310310
311-
@JSFunction func check() throws (JSException) -> Void
311+
@JSFunction func check() throws(JSException) -> Void
312312
"
313313
`;

Tests/BridgeJSRuntimeTests/Generated/BridgeJS.Macros.swift

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,60 +6,60 @@
66

77
@_spi(Experimental) @_spi(BridgeJS) import JavaScriptKit
88

9-
@JSFunction func jsRoundTripVoid() throws (JSException) -> Void
9+
@JSFunction func jsRoundTripVoid() throws(JSException) -> Void
1010

11-
@JSFunction func jsRoundTripNumber(_ v: Double) throws (JSException) -> Double
11+
@JSFunction func jsRoundTripNumber(_ v: Double) throws(JSException) -> Double
1212

13-
@JSFunction func jsRoundTripBool(_ v: Bool) throws (JSException) -> Bool
13+
@JSFunction func jsRoundTripBool(_ v: Bool) throws(JSException) -> Bool
1414

15-
@JSFunction func jsRoundTripString(_ v: String) throws (JSException) -> String
15+
@JSFunction func jsRoundTripString(_ v: String) throws(JSException) -> String
1616

17-
@JSFunction func jsThrowOrVoid(_ shouldThrow: Bool) throws (JSException) -> Void
17+
@JSFunction func jsThrowOrVoid(_ shouldThrow: Bool) throws(JSException) -> Void
1818

19-
@JSFunction func jsThrowOrNumber(_ shouldThrow: Bool) throws (JSException) -> Double
19+
@JSFunction func jsThrowOrNumber(_ shouldThrow: Bool) throws(JSException) -> Double
2020

21-
@JSFunction func jsThrowOrBool(_ shouldThrow: Bool) throws (JSException) -> Bool
21+
@JSFunction func jsThrowOrBool(_ shouldThrow: Bool) throws(JSException) -> Bool
2222

23-
@JSFunction func jsThrowOrString(_ shouldThrow: Bool) throws (JSException) -> String
23+
@JSFunction func jsThrowOrString(_ shouldThrow: Bool) throws(JSException) -> String
2424

2525
enum FeatureFlag: String {
2626
case foo = "foo"
2727
case bar = "bar"
2828
}
2929
extension FeatureFlag: _BridgedSwiftEnumNoPayload, _BridgedSwiftRawValueEnum {}
3030

31-
@JSFunction func jsRoundTripFeatureFlag(_ flag: FeatureFlag) throws (JSException) -> FeatureFlag
31+
@JSFunction func jsRoundTripFeatureFlag(_ flag: FeatureFlag) throws(JSException) -> FeatureFlag
3232

3333
@JSClass struct JsGreeter {
3434
@JSGetter var name: String
35-
@JSSetter func setName(_ value: String) throws (JSException)
35+
@JSSetter func setName(_ value: String) throws(JSException)
3636
@JSGetter var `prefix`: String
37-
@JSFunction init(_ name: String, _ `prefix`: String) throws (JSException)
38-
@JSFunction func greet() throws (JSException) -> String
39-
@JSFunction func changeName(_ name: String) throws (JSException) -> Void
37+
@JSFunction init(_ name: String, _ `prefix`: String) throws(JSException)
38+
@JSFunction func greet() throws(JSException) -> String
39+
@JSFunction func changeName(_ name: String) throws(JSException) -> Void
4040
}
4141

42-
@JSFunction func runAsyncWorks() throws (JSException) -> JSPromise
42+
@JSFunction func runAsyncWorks() throws(JSException) -> JSPromise
4343

44-
@JSFunction(jsName: "$jsWeirdFunction") func _jsWeirdFunction() throws (JSException) -> Double
44+
@JSFunction(jsName: "$jsWeirdFunction") func _jsWeirdFunction() throws(JSException) -> Double
4545

4646
@JSClass(jsName: "$WeirdClass") struct _WeirdClass {
47-
@JSFunction init() throws (JSException)
48-
@JSFunction(jsName: "method-with-dashes") func method_with_dashes() throws (JSException) -> String
47+
@JSFunction init() throws(JSException)
48+
@JSFunction(jsName: "method-with-dashes") func method_with_dashes() throws(JSException) -> String
4949
}
5050

51-
@JSFunction(from: .global) func parseInt(_ string: String) throws (JSException) -> Double
51+
@JSFunction(from: .global) func parseInt(_ string: String) throws(JSException) -> Double
5252

5353
@JSClass(from: .global) struct Animal {
5454
@JSGetter var name: String
55-
@JSSetter func setName(_ value: String) throws (JSException)
55+
@JSSetter func setName(_ value: String) throws(JSException)
5656
@JSGetter var age: Double
57-
@JSSetter func setAge(_ value: Double) throws (JSException)
57+
@JSSetter func setAge(_ value: Double) throws(JSException)
5858
@JSGetter var isCat: Bool
59-
@JSSetter func setIsCat(_ value: Bool) throws (JSException)
60-
@JSFunction init(_ name: String, _ age: Double, _ isCat: Bool) throws (JSException)
61-
@JSFunction func bark() throws (JSException) -> String
62-
@JSFunction func getIsCat() throws (JSException) -> Bool
59+
@JSSetter func setIsCat(_ value: Bool) throws(JSException)
60+
@JSFunction init(_ name: String, _ age: Double, _ isCat: Bool) throws(JSException)
61+
@JSFunction func bark() throws(JSException) -> String
62+
@JSFunction func getIsCat() throws(JSException) -> Bool
6363
}
6464

6565
@JSGetter(from: .global) var globalObject1: JSObject

0 commit comments

Comments
 (0)