Skip to content

Commit 56aabfa

Browse files
[NFC] BridgeJS: Omit trailing spaces on empty lines in generated JS code (#575)
When generating JavaScript code, avoid adding trailing spaces to empty lines.
1 parent 0bd50f8 commit 56aabfa

39 files changed

+148
-143
lines changed

Plugins/BridgeJS/Sources/BridgeJSLink/CodeFragmentPrinter.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ final class CodeFragmentPrinter {
1212
}
1313

1414
func write<S: StringProtocol>(_ line: S) {
15+
if line.isEmpty {
16+
// Empty lines should not have trailing spaces
17+
lines.append("")
18+
return
19+
}
1520
lines.append(String(repeating: " ", count: indentLevel * 4) + String(line))
1621
}
1722

Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayTypes.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export async function createInstantiator(options, swift) {
4444
let tmpStructCleanups = [];
4545
const enumHelpers = {};
4646
const structHelpers = {};
47-
47+
4848
let _exports = null;
4949
let bjs = null;
5050
const __bjs_createPointHelpers = () => {
@@ -288,7 +288,7 @@ export async function createInstantiator(options, swift) {
288288
obj.registry.register(this, obj.pointer);
289289
return obj;
290290
}
291-
291+
292292
release() {
293293
this.registry.unregister(this);
294294
this.deinit(this.pointer);
@@ -298,11 +298,11 @@ export async function createInstantiator(options, swift) {
298298
static __construct(ptr) {
299299
return SwiftHeapObject.__wrap(ptr, instance.exports.bjs_Item_deinit, Item.prototype);
300300
}
301-
301+
302302
}
303303
const PointHelpers = __bjs_createPointHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, enumHelpers);
304304
structHelpers.Point = PointHelpers;
305-
305+
306306
const exports = {
307307
Item,
308308
processIntArray: function bjs_processIntArray(values) {

Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Async.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export async function createInstantiator(options, swift) {
3131
let tmpStructCleanups = [];
3232
const enumHelpers = {};
3333
const structHelpers = {};
34-
34+
3535
let _exports = null;
3636
let bjs = null;
3737

Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DefaultParameters.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export async function createInstantiator(options, swift) {
3737
let tmpStructCleanups = [];
3838
const enumHelpers = {};
3939
const structHelpers = {};
40-
40+
4141
let _exports = null;
4242
let bjs = null;
4343
const __bjs_createConfigHelpers = () => {
@@ -317,7 +317,7 @@ export async function createInstantiator(options, swift) {
317317
obj.registry.register(this, obj.pointer);
318318
return obj;
319319
}
320-
320+
321321
release() {
322322
this.registry.unregister(this);
323323
this.deinit(this.pointer);
@@ -327,7 +327,7 @@ export async function createInstantiator(options, swift) {
327327
static __construct(ptr) {
328328
return SwiftHeapObject.__wrap(ptr, instance.exports.bjs_DefaultGreeter_deinit, DefaultGreeter.prototype);
329329
}
330-
330+
331331
constructor(name) {
332332
const nameBytes = textEncoder.encode(name);
333333
const nameId = swift.memory.retain(nameBytes);
@@ -352,7 +352,7 @@ export async function createInstantiator(options, swift) {
352352
static __construct(ptr) {
353353
return SwiftHeapObject.__wrap(ptr, instance.exports.bjs_EmptyGreeter_deinit, EmptyGreeter.prototype);
354354
}
355-
355+
356356
constructor() {
357357
const ret = instance.exports.bjs_EmptyGreeter_init();
358358
return EmptyGreeter.__construct(ret);
@@ -362,7 +362,7 @@ export async function createInstantiator(options, swift) {
362362
static __construct(ptr) {
363363
return SwiftHeapObject.__wrap(ptr, instance.exports.bjs_ConstructorDefaults_deinit, ConstructorDefaults.prototype);
364364
}
365-
365+
366366
constructor(name = "Default", count = 42, enabled = true, status = StatusValues.Active, tag = null) {
367367
const nameBytes = textEncoder.encode(name);
368368
const nameId = swift.memory.retain(nameBytes);
@@ -433,10 +433,10 @@ export async function createInstantiator(options, swift) {
433433
}
434434
const ConfigHelpers = __bjs_createConfigHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, enumHelpers);
435435
structHelpers.Config = ConfigHelpers;
436-
436+
437437
const MathOperationsHelpers = __bjs_createMathOperationsHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, enumHelpers);
438438
structHelpers.MathOperations = MathOperationsHelpers;
439-
439+
440440
const exports = {
441441
DefaultGreeter,
442442
EmptyGreeter,

Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAssociatedValue.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ export async function createInstantiator(options, swift) {
506506
let tmpStructCleanups = [];
507507
const enumHelpers = {};
508508
const structHelpers = {};
509-
509+
510510
let _exports = null;
511511
let bjs = null;
512512

@@ -683,19 +683,19 @@ export async function createInstantiator(options, swift) {
683683

684684
const APIResultHelpers = __bjs_createAPIResultValuesHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, textEncoder, swift);
685685
enumHelpers.APIResult = APIResultHelpers;
686-
686+
687687
const ComplexResultHelpers = __bjs_createComplexResultValuesHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, textEncoder, swift);
688688
enumHelpers.ComplexResult = ComplexResultHelpers;
689-
689+
690690
const ResultHelpers = __bjs_createResultValuesHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, textEncoder, swift);
691691
enumHelpers.Result = ResultHelpers;
692-
692+
693693
const NetworkingResultHelpers = __bjs_createNetworkingResultValuesHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, textEncoder, swift);
694694
enumHelpers.NetworkingResult = NetworkingResultHelpers;
695-
695+
696696
const APIOptionalResultHelpers = __bjs_createAPIOptionalResultValuesHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, textEncoder, swift);
697697
enumHelpers.APIOptionalResult = APIOptionalResultHelpers;
698-
698+
699699
setException = (error) => {
700700
instance.exports._swift_js_exception.value = swift.memory.retain(error)
701701
}

Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumCase.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export async function createInstantiator(options, swift) {
5555
let tmpStructCleanups = [];
5656
const enumHelpers = {};
5757
const structHelpers = {};
58-
58+
5959
let _exports = null;
6060
let bjs = null;
6161

Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.Global.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export async function createInstantiator(options, swift) {
7575
let tmpStructCleanups = [];
7676
const enumHelpers = {};
7777
const structHelpers = {};
78-
78+
7979
let _exports = null;
8080
let bjs = null;
8181

@@ -286,7 +286,7 @@ export async function createInstantiator(options, swift) {
286286
obj.registry.register(this, obj.pointer);
287287
return obj;
288288
}
289-
289+
290290
release() {
291291
this.registry.unregister(this);
292292
this.deinit(this.pointer);
@@ -296,7 +296,7 @@ export async function createInstantiator(options, swift) {
296296
static __construct(ptr) {
297297
return SwiftHeapObject.__wrap(ptr, instance.exports.bjs_Converter_deinit, Converter.prototype);
298298
}
299-
299+
300300
constructor() {
301301
const ret = instance.exports.bjs_Converter_init();
302302
return Converter.__construct(ret);
@@ -312,7 +312,7 @@ export async function createInstantiator(options, swift) {
312312
static __construct(ptr) {
313313
return SwiftHeapObject.__wrap(ptr, instance.exports.bjs_HTTPServer_deinit, HTTPServer.prototype);
314314
}
315-
315+
316316
constructor() {
317317
const ret = instance.exports.bjs_HTTPServer_init();
318318
return HTTPServer.__construct(ret);
@@ -325,7 +325,7 @@ export async function createInstantiator(options, swift) {
325325
static __construct(ptr) {
326326
return SwiftHeapObject.__wrap(ptr, instance.exports.bjs_TestServer_deinit, TestServer.prototype);
327327
}
328-
328+
329329
constructor() {
330330
const ret = instance.exports.bjs_TestServer_init();
331331
return TestServer.__construct(ret);

Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export async function createInstantiator(options, swift) {
5656
let tmpStructCleanups = [];
5757
const enumHelpers = {};
5858
const structHelpers = {};
59-
59+
6060
let _exports = null;
6161
let bjs = null;
6262

@@ -267,7 +267,7 @@ export async function createInstantiator(options, swift) {
267267
obj.registry.register(this, obj.pointer);
268268
return obj;
269269
}
270-
270+
271271
release() {
272272
this.registry.unregister(this);
273273
this.deinit(this.pointer);
@@ -277,7 +277,7 @@ export async function createInstantiator(options, swift) {
277277
static __construct(ptr) {
278278
return SwiftHeapObject.__wrap(ptr, instance.exports.bjs_Converter_deinit, Converter.prototype);
279279
}
280-
280+
281281
constructor() {
282282
const ret = instance.exports.bjs_Converter_init();
283283
return Converter.__construct(ret);
@@ -293,7 +293,7 @@ export async function createInstantiator(options, swift) {
293293
static __construct(ptr) {
294294
return SwiftHeapObject.__wrap(ptr, instance.exports.bjs_HTTPServer_deinit, HTTPServer.prototype);
295295
}
296-
296+
297297
constructor() {
298298
const ret = instance.exports.bjs_HTTPServer_init();
299299
return HTTPServer.__construct(ret);
@@ -306,7 +306,7 @@ export async function createInstantiator(options, swift) {
306306
static __construct(ptr) {
307307
return SwiftHeapObject.__wrap(ptr, instance.exports.bjs_TestServer_deinit, TestServer.prototype);
308308
}
309-
309+
310310
constructor() {
311311
const ret = instance.exports.bjs_TestServer_init();
312312
return TestServer.__construct(ret);

Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumRawType.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export async function createInstantiator(options, swift) {
106106
let tmpStructCleanups = [];
107107
const enumHelpers = {};
108108
const structHelpers = {};
109-
109+
110110
let _exports = null;
111111
let bjs = null;
112112

Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalGetter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export async function createInstantiator(options, swift) {
3131
let tmpStructCleanups = [];
3232
const enumHelpers = {};
3333
const structHelpers = {};
34-
34+
3535
let _exports = null;
3636
let bjs = null;
3737

0 commit comments

Comments
 (0)