Skip to content

Commit 4bfdfe7

Browse files
BridgeJS: Remove error-prone default effects in thunk generation
1 parent 14561d4 commit 4bfdfe7

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

Plugins/BridgeJS/Sources/BridgeJSCore/ImportTS.swift

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,11 @@ public struct ImportTS {
6666
_ getter: ImportedGetterSkeleton,
6767
topLevelDecls: inout [DeclSyntax]
6868
) throws -> [DeclSyntax] {
69+
let effects = Effects(isAsync: false, isThrows: true)
6970
let builder = try CallJSEmission(
7071
moduleName: moduleName,
7172
abiName: getter.abiName(context: nil),
72-
effects: Effects(isAsync: false, isThrows: true),
73+
effects: effects,
7374
returnType: getter.type
7475
)
7576
try builder.call()
@@ -79,7 +80,8 @@ public struct ImportTS {
7980
builder.renderThunkDecl(
8081
name: "_$\(getter.name)_get",
8182
parameters: [],
82-
returnType: getter.type
83+
returnType: getter.type,
84+
effects: effects
8385
)
8486
.with(\.leadingTrivia, Self.renderDocumentation(documentation: getter.documentation))
8587
]
@@ -360,7 +362,7 @@ public struct ImportTS {
360362
name: String,
361363
parameters: [Parameter],
362364
returnType: BridgeType,
363-
effects: Effects = Effects(isAsync: false, isThrows: true)
365+
effects: Effects
364366
) -> DeclSyntax {
365367
let printer = CodeFragmentPrinter()
366368
let signature = SwiftSignatureBuilder.buildFunctionSignature(
@@ -496,10 +498,11 @@ public struct ImportTS {
496498
}
497499

498500
func renderConstructorDecl(constructor: ImportedConstructorSkeleton) throws -> [DeclSyntax] {
501+
let effects = Effects(isAsync: false, isThrows: true)
499502
let builder = try CallJSEmission(
500503
moduleName: moduleName,
501504
abiName: constructor.abiName(context: type),
502-
effects: Effects(isAsync: false, isThrows: true),
505+
effects: effects,
503506
returnType: .jsObject(nil)
504507
)
505508
for param in constructor.parameters {
@@ -512,16 +515,18 @@ public struct ImportTS {
512515
builder.renderThunkDecl(
513516
name: Self.thunkName(type: type),
514517
parameters: constructor.parameters,
515-
returnType: .jsObject(nil)
518+
returnType: .jsObject(nil),
519+
effects: effects
516520
)
517521
]
518522
}
519523

520524
func renderGetterDecl(getter: ImportedGetterSkeleton) throws -> DeclSyntax {
525+
let effects = Effects(isAsync: false, isThrows: true)
521526
let builder = try CallJSEmission(
522527
moduleName: moduleName,
523528
abiName: getter.abiName(context: type),
524-
effects: Effects(isAsync: false, isThrows: true),
529+
effects: effects,
525530
returnType: getter.type
526531
)
527532
try builder.lowerParameter(param: selfParameter)
@@ -532,16 +537,18 @@ public struct ImportTS {
532537
builder.renderThunkDecl(
533538
name: Self.thunkName(type: type, propertyName: getter.name, operation: "get"),
534539
parameters: [selfParameter],
535-
returnType: getter.type
540+
returnType: getter.type,
541+
effects: effects
536542
)
537543
)
538544
}
539545

540546
func renderSetterDecl(setter: ImportedSetterSkeleton) throws -> DeclSyntax {
547+
let effects = Effects(isAsync: false, isThrows: true)
541548
let builder = try CallJSEmission(
542549
moduleName: moduleName,
543550
abiName: setter.abiName(context: type),
544-
effects: Effects(isAsync: false, isThrows: true),
551+
effects: effects,
545552
returnType: .void
546553
)
547554
let newValue = Parameter(label: nil, name: "newValue", type: setter.type)
@@ -561,7 +568,8 @@ public struct ImportTS {
561568
return builder.renderThunkDecl(
562569
name: Self.thunkName(type: type, propertyName: propertyNameForThunk, operation: "set"),
563570
parameters: [selfParameter, newValue],
564-
returnType: .void
571+
returnType: .void,
572+
effects: effects
565573
)
566574
}
567575
if let constructor = type.constructor {

0 commit comments

Comments
 (0)