From c65b5d86208fee3fe427ae117d5b81cf990c76f5 Mon Sep 17 00:00:00 2001 From: Stephen Celis Date: Mon, 4 Mar 2024 17:20:43 -0800 Subject: [PATCH] fix --- .../PerceptionMacros/PerceptibleMacro.swift | 30 +++++++++---------- .../PerceptionMacrosTests.swift | 22 +++++++------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/Sources/PerceptionMacros/PerceptibleMacro.swift b/Sources/PerceptionMacros/PerceptibleMacro.swift index 4f15c00..75f6b27 100644 --- a/Sources/PerceptionMacros/PerceptibleMacro.swift +++ b/Sources/PerceptionMacros/PerceptibleMacro.swift @@ -48,11 +48,11 @@ public struct PerceptibleMacro { return """ internal nonisolated func access( - 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) } """ } @@ -61,10 +61,10 @@ public struct PerceptibleMacro { return """ internal nonisolated func withMutation( - 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) } """ } @@ -218,7 +218,7 @@ extension PerceptibleMacro: MemberMacro { return [] } - let perceptibleType = identified.name + let perceptibleType = identified.name.trimmed if declaration.isEnum { // enumerations cannot store properties @@ -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 [] } @@ -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 + } } """ diff --git a/Tests/PerceptionMacrosTests/PerceptionMacrosTests.swift b/Tests/PerceptionMacrosTests/PerceptionMacrosTests.swift index afb8b59..8e6a483 100644 --- a/Tests/PerceptionMacrosTests/PerceptionMacrosTests.swift +++ b/Tests/PerceptionMacrosTests/PerceptionMacrosTests.swift @@ -6,7 +6,7 @@ class PerceptionMacroTests: XCTestCase { override func invokeTest() { withMacroTesting( - //isRecording: true, + // isRecording: true, macros: [ PerceptibleMacro.self, PerceptionTrackedMacro.self, @@ -28,18 +28,18 @@ } 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 } } } @@ -47,15 +47,15 @@ private let _$perceptionRegistrar = Perception.PerceptionRegistrar() internal nonisolated func access( - keyPath: KeyPath, - file: StaticString = #file, - line: UInt = #line + keyPath: KeyPath, + file: StaticString = #file, + line: UInt = #line ) { _$perceptionRegistrar.access(self, keyPath: keyPath, file: file, line: line) } internal nonisolated func withMutation( - keyPath: KeyPath, + keyPath: KeyPath, _ mutation: () throws -> MutationResult ) rethrows -> MutationResult { try _$perceptionRegistrar.withMutation(of: self, keyPath: keyPath, mutation)