From e58dcc417bcafc72b0c5e8f636c58acc25cfa1ed Mon Sep 17 00:00:00 2001 From: Jineun Jeong Date: Tue, 9 Jul 2024 23:42:58 +0900 Subject: [PATCH] fix(): `ComposableObject` macro doesn't add `@Published` to constants --- Sources/ComposeMacro/ComposableObjectMacro.swift | 8 ++++++++ Tests/ComposeMacroTests/ComposeMacroTests.swift | 13 +++++++++++++ 2 files changed, 21 insertions(+) diff --git a/Sources/ComposeMacro/ComposableObjectMacro.swift b/Sources/ComposeMacro/ComposableObjectMacro.swift index 1621756..2c49376 100644 --- a/Sources/ComposeMacro/ComposableObjectMacro.swift +++ b/Sources/ComposeMacro/ComposableObjectMacro.swift @@ -38,6 +38,10 @@ extension ComposableObjectMacro: MemberAttributeMacro { return [] } + guard !(member.variable?.isConstant ?? false) else { + return [] + } + guard member.variable?.binding?.isObservableStoredProperty ?? false else { return [] } @@ -70,6 +74,10 @@ private extension VariableDeclSyntax { var isPrivateProperty: Bool { modifier?.name.text == "private" && modifier?.detail?.detail.text != "set" } + + var isConstant: Bool { + bindingSpecifier.text == "let" + } } private extension PatternBindingListSyntax.Element { diff --git a/Tests/ComposeMacroTests/ComposeMacroTests.swift b/Tests/ComposeMacroTests/ComposeMacroTests.swift index b6ee79c..69cec06 100644 --- a/Tests/ComposeMacroTests/ComposeMacroTests.swift +++ b/Tests/ComposeMacroTests/ComposeMacroTests.swift @@ -36,6 +36,12 @@ final class ComposeMacroTests: XCTestCase { var b: Int = 0 private(set) var c: Int = 0 private var d: Int = 0 + public private(set) var e: Int = 0 + public let f: Int = 0 + let g: Int = 0 + private(set) let h: Int = 0 + private let i: Int = 0 + public private(set) let j: Int = 0 } """, expandedSource: """ @@ -47,6 +53,13 @@ final class ComposeMacroTests: XCTestCase { @Published private(set) var c: Int = 0 private var d: Int = 0 + @Published + public private(set) var e: Int = 0 + public let f: Int = 0 + let g: Int = 0 + private(set) let h: Int = 0 + private let i: Int = 0 + public private(set) let j: Int = 0 } extension Environment: ObservableObject {