Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 11 additions & 1 deletion Sources/DependenciesMacrosPlugin/DependencyClientMacro.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,11 @@ public enum DependencyClientMacro: MemberAttributeMacro, MemberMacro {
var hasEndpoints = false
var accesses: Set<Access> = 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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
"""
Expand Down