diff --git a/Dependencies.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Dependencies.xcworkspace/xcshareddata/swiftpm/Package.resolved index 0cb4b8fd..9fad66b3 100644 --- a/Dependencies.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Dependencies.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -86,8 +86,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/pointfreeco/xctest-dynamic-overlay", "state" : { - "revision" : "23cbf2294e350076ea4dbd7d5d047c1e76b03631", - "version" : "1.0.2" + "revision" : "b13b1d1a8e787a5ffc71ac19dcaf52183ab27ba2", + "version" : "1.1.1" } } ], diff --git a/Sources/DependenciesMacrosPlugin/DependencyClientMacro.swift b/Sources/DependenciesMacrosPlugin/DependencyClientMacro.swift index b4712677..72882612 100644 --- a/Sources/DependenciesMacrosPlugin/DependencyClientMacro.swift +++ b/Sources/DependenciesMacrosPlugin/DependencyClientMacro.swift @@ -86,7 +86,11 @@ public enum DependencyClientMacro: MemberAttributeMacro, MemberMacro { var hasEndpoints = false var accesses: Set = Access(modifiers: declaration.modifiers).map { [$0] } ?? [] for member in declaration.memberBlock.members { - guard var property = member.decl.as(VariableDeclSyntax.self) else { continue } + guard + var property = member.decl.as(VariableDeclSyntax.self), + !property.isStatic + else { continue } + let isEndpoint = property.hasDependencyEndpointMacroAttached || property.bindingSpecifier.tokenKind != .keyword(.let) && property.isClosure @@ -249,6 +253,12 @@ private struct Property { } extension VariableDeclSyntax { + fileprivate var isStatic: Bool { + self.modifiers.contains { modifier in + modifier.name.tokenKind == .keyword(.static) + } + } + fileprivate var hasDependencyEndpointMacroAttached: Bool { self.attributes.contains { guard diff --git a/Tests/DependenciesMacrosPluginTests/DependencyClientMacroTests.swift b/Tests/DependenciesMacrosPluginTests/DependencyClientMacroTests.swift index 3d790551..9a348565 100644 --- a/Tests/DependenciesMacrosPluginTests/DependencyClientMacroTests.swift +++ b/Tests/DependenciesMacrosPluginTests/DependencyClientMacroTests.swift @@ -276,6 +276,35 @@ final class DependencyClientMacroTests: BaseTestCase { } } + func testStaticVar() { + assertMacro { + """ + @DependencyClient + struct Client { + var config: () -> Void + static var value = Client() + } + """ + } expansion: { + """ + struct Client { + @DependencyEndpoint + var config: () -> Void + static var value = Client() + + init( + config: @escaping () -> Void + ) { + self.config = config + } + + init() { + } + } + """ + } + } + func testDefaultValue() { assertMacro { """