Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
stephencelis committed Mar 5, 2024
1 parent db970a7 commit c65b5d8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 26 deletions.
30 changes: 15 additions & 15 deletions Sources/PerceptionMacros/PerceptibleMacro.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ public struct PerceptibleMacro {
return
"""
internal nonisolated func access<Member>(
keyPath: KeyPath<\(perceptibleType), Member>,
file: StaticString = #file,
line: UInt = #line
keyPath: KeyPath<\(perceptibleType), Member>,
file: StaticString = #file,
line: UInt = #line
) {
\(raw: registrarVariableName).access(self, keyPath: keyPath, file: file, line: line)
\(raw: registrarVariableName).access(self, keyPath: keyPath, file: file, line: line)
}
"""
}
Expand All @@ -61,10 +61,10 @@ public struct PerceptibleMacro {
return
"""
internal nonisolated func withMutation<Member, MutationResult>(
keyPath: KeyPath<\(perceptibleType), Member>,
_ mutation: () throws -> MutationResult
keyPath: KeyPath<\(perceptibleType), Member>,
_ mutation: () throws -> MutationResult
) rethrows -> MutationResult {
try \(raw: registrarVariableName).withMutation(of: self, keyPath: keyPath, mutation)
try \(raw: registrarVariableName).withMutation(of: self, keyPath: keyPath, mutation)
}
"""
}
Expand Down Expand Up @@ -218,7 +218,7 @@ extension PerceptibleMacro: MemberMacro {
return []
}

let perceptibleType = identified.name
let perceptibleType = identified.name.trimmed

if declaration.isEnum {
// enumerations cannot store properties
Expand Down Expand Up @@ -333,7 +333,7 @@ public struct PerceptionTrackedMacro: AccessorMacro {
) throws -> [AccessorDeclSyntax] {
guard let property = declaration.as(VariableDeclSyntax.self),
property.isValidForPerception,
let identifier = property.identifier
let identifier = property.identifier?.trimmed
else {
return []
}
Expand All @@ -346,24 +346,24 @@ public struct PerceptionTrackedMacro: AccessorMacro {
"""
@storageRestrictions(initializes: _\(identifier))
init(initialValue) {
_\(identifier) = initialValue
_\(identifier) = initialValue
}
"""

let getAccessor: AccessorDeclSyntax =
"""
get {
access(keyPath: \\.\(identifier))
return _\(identifier)
access(keyPath: \\.\(identifier))
return _\(identifier)
}
"""

let setAccessor: AccessorDeclSyntax =
"""
set {
withMutation(keyPath: \\.\(identifier)) {
_\(identifier) = newValue
}
withMutation(keyPath: \\.\(identifier)) {
_\(identifier) = newValue
}
}
"""

Expand Down
22 changes: 11 additions & 11 deletions Tests/PerceptionMacrosTests/PerceptionMacrosTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
class PerceptionMacroTests: XCTestCase {
override func invokeTest() {
withMacroTesting(
//isRecording: true,
// isRecording: true,
macros: [
PerceptibleMacro.self,
PerceptionTrackedMacro.self,
Expand All @@ -28,34 +28,34 @@
} expansion: {
#"""
class Feature {
var count = 0 {
@storageRestrictions(initializes: _count )
var count {
@storageRestrictions(initializes: _count)
init(initialValue) {
_count = initialValue
_count = initialValue
}
get {
access(keyPath: \.count )
access(keyPath: \.count)
return _count
}
set {
withMutation(keyPath: \.count ) {
_count = newValue
withMutation(keyPath: \.count) {
_count = newValue
}
}
}
private let _$perceptionRegistrar = Perception.PerceptionRegistrar()
internal nonisolated func access<Member>(
keyPath: KeyPath<Feature , Member>,
file: StaticString = #file,
line: UInt = #line
keyPath: KeyPath<Feature, Member>,
file: StaticString = #file,
line: UInt = #line
) {
_$perceptionRegistrar.access(self, keyPath: keyPath, file: file, line: line)
}
internal nonisolated func withMutation<Member, MutationResult>(
keyPath: KeyPath<Feature , Member>,
keyPath: KeyPath<Feature, Member>,
_ mutation: () throws -> MutationResult
) rethrows -> MutationResult {
try _$perceptionRegistrar.withMutation(of: self, keyPath: keyPath, mutation)
Expand Down

0 comments on commit c65b5d8

Please sign in to comment.