Skip to content

Commit 24dc372

Browse files
authored
Merge pull request #69644 from stephencelis/patch-6
Clean up formatting of Observable macro
2 parents 63b967c + 541716d commit 24dc372

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

lib/Macros/Sources/ObservationMacros/ObservableMacro.swift

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ public struct ObservableMacro {
4848
return
4949
"""
5050
internal nonisolated func access<Member>(
51-
keyPath: KeyPath<\(observableType), Member>
51+
keyPath: KeyPath<\(observableType), Member>
5252
) {
53-
\(raw: registrarVariableName).access(self, keyPath: keyPath)
53+
\(raw: registrarVariableName).access(self, keyPath: keyPath)
5454
}
5555
"""
5656
}
@@ -59,10 +59,10 @@ public struct ObservableMacro {
5959
return
6060
"""
6161
internal nonisolated func withMutation<Member, MutationResult>(
62-
keyPath: KeyPath<\(observableType), Member>,
63-
_ mutation: () throws -> MutationResult
62+
keyPath: KeyPath<\(observableType), Member>,
63+
_ mutation: () throws -> MutationResult
6464
) rethrows -> MutationResult {
65-
try \(raw: registrarVariableName).withMutation(of: self, keyPath: keyPath, mutation)
65+
try \(raw: registrarVariableName).withMutation(of: self, keyPath: keyPath, mutation)
6666
}
6767
"""
6868
}
@@ -202,7 +202,7 @@ extension ObservableMacro: MemberMacro {
202202
return []
203203
}
204204

205-
let observableType = identified.name
205+
let observableType = identified.name.trimmed
206206

207207
if declaration.isEnum {
208208
// enumerations cannot store properties
@@ -294,7 +294,7 @@ public struct ObservationTrackedMacro: AccessorMacro {
294294
) throws -> [AccessorDeclSyntax] {
295295
guard let property = declaration.as(VariableDeclSyntax.self),
296296
property.isValidForObservation,
297-
let identifier = property.identifier else {
297+
let identifier = property.identifier?.trimmed else {
298298
return []
299299
}
300300

@@ -306,24 +306,24 @@ public struct ObservationTrackedMacro: AccessorMacro {
306306
"""
307307
@storageRestrictions(initializes: _\(identifier))
308308
init(initialValue) {
309-
_\(identifier) = initialValue
309+
_\(identifier) = initialValue
310310
}
311311
"""
312312

313313
let getAccessor: AccessorDeclSyntax =
314314
"""
315315
get {
316-
access(keyPath: \\.\(identifier))
317-
return _\(identifier)
316+
access(keyPath: \\.\(identifier))
317+
return _\(identifier)
318318
}
319319
"""
320320

321321
let setAccessor: AccessorDeclSyntax =
322322
"""
323323
set {
324-
withMutation(keyPath: \\.\(identifier)) {
325-
_\(identifier) = newValue
326-
}
324+
withMutation(keyPath: \\.\(identifier)) {
325+
_\(identifier) = newValue
326+
}
327327
}
328328
"""
329329

0 commit comments

Comments
 (0)