Skip to content

Commit 492551d

Browse files
committed
Following up on closures property wrappers cleanup
This change fixes an issue with the use of property wrappers for closures in WebAPIKit, which caused unnecessary increases in binary code size for products utilizing this library. Use of property wrappers is removed and simple direct getter and setter accessors are used for properties of closure types instead.
1 parent 7f1772e commit 492551d

File tree

1 file changed

+14
-34
lines changed

1 file changed

+14
-34
lines changed

Sources/WebIDLToSwift/WebIDL+SwiftRepresentation.swift

Lines changed: 14 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -36,47 +36,27 @@ extension IDLAttribute: SwiftRepresentable {
3636
}
3737
if ModuleState.override {
3838
assert(!ModuleState.static)
39-
// can't do property wrappers on override declarations
40-
return """
41-
@usableFromInline let \(wrapperName): \(idlType.propertyWrapper(readonly: readonly))<\(idlType)>
42-
@inlinable override public var \(name): \(idlType) {
43-
get { \(wrapperName).wrappedValue }
44-
\(readonly ? "" : "set { \(wrapperName).wrappedValue = newValue }")
45-
}
46-
"""
47-
} else if ModuleState.constructor == nil || ModuleState.static {
48-
// can't do property wrappers on extensions
49-
let propertyWrapper = idlType.propertyWrapper(readonly: readonly)
50-
if [SwiftSource.readOnlyAttribute, .readWriteAttribute].contains(propertyWrapper) {
51-
let setter: SwiftSource = """
52-
nonmutating set { jsObject[\(ModuleState.source(for: name))] = _toJSValue(newValue) }
53-
"""
5439

55-
return """
56-
@inlinable public\(raw: ModuleState.static ? " static" : "") var \(name): \(idlType) {
57-
get { jsObject[\(ModuleState.source(for: name))]\(idlType.fromJSValue) }
58-
\(readonly ? "" : setter)
59-
}
60-
"""
40+
return ""
41+
} else {
42+
let stringKey = ModuleState.source(for: name)
43+
let getter: SwiftSource
44+
let setter: SwiftSource
45+
46+
if let closure = idlType.closurePattern {
47+
getter = "get { \(closure.getter(name: stringKey)) }"
48+
setter = "set { \(closure.setter(name: stringKey)) }"
6149
} else {
62-
let setter: SwiftSource = """
63-
nonmutating set { \(
64-
idlType.propertyWrapper(readonly: readonly))[\(ModuleState.source(for: name)
65-
), in: jsObject] = newValue }
66-
"""
50+
getter = "get { jsObject[\(stringKey)]\(idlType.fromJSValue) }"
51+
setter = "set { jsObject[\(stringKey)] = _toJSValue(newValue) }"
52+
}
6753

68-
return """
54+
return """
6955
@inlinable public\(raw: ModuleState.static ? " static" : "") var \(name): \(idlType) {
70-
get { \(idlType.propertyWrapper(readonly: readonly))[\(ModuleState.source(for: name)), in: jsObject] }
56+
\(getter)
7157
\(readonly ? "" : setter)
7258
}
7359
"""
74-
}
75-
} else {
76-
return """
77-
@\(idlType.propertyWrapper(readonly: readonly))
78-
public var \(name): \(idlType)
79-
"""
8060
}
8161
}
8262

0 commit comments

Comments
 (0)