Skip to content

Commit

Permalink
Add package access modifier support to @Reducer on enums (#2939)
Browse files Browse the repository at this point in the history
  • Loading branch information
samrayner authored Apr 1, 2024
1 parent 0301506 commit 4514a16
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Sources/ComposableArchitectureMacros/ReducerMacro.swift
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,9 @@ extension ReducerMacro: MemberMacro {
providingMembersOf declaration: D,
in context: C
) throws -> [DeclSyntax] {
let access = declaration.modifiers.first { $0.name.tokenKind == .keyword(.public) }
let access = declaration.modifiers.first {
[.keyword(.public), .keyword(.package)].contains($0.name.tokenKind)
}
let typeNames = declaration.memberBlock.members.compactMap {
$0.decl.as(StructDeclSyntax.self)?.name.text
?? $0.decl.as(TypeAliasDeclSyntax.self)?.name.text
Expand Down
100 changes: 100 additions & 0 deletions Tests/ComposableArchitectureMacrosTests/ReducerMacroTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,106 @@
}
}

func testEnum_Empty_AccessControl_Package() {
assertMacro {
"""
@Reducer
package enum Destination {
}
"""
} expansion: {
"""
package enum Destination {
@CasePathable
@dynamicMemberLookup
@ObservableState
package enum State: ComposableArchitecture.CaseReducerState {
package typealias StateReducer = Destination
}
@CasePathable
package enum Action {
}
@ComposableArchitecture.ReducerBuilder<Self.State, Self.Action>
package static var body: ComposableArchitecture.EmptyReducer<Self.State, Self.Action> {
ComposableArchitecture.EmptyReducer<Self.State, Self.Action>()
}
package enum CaseScope {
}
package static func scope(_ store: ComposableArchitecture.Store<Self.State, Self.Action>) -> CaseScope {
switch store.state {
}
}
}
extension Destination: ComposableArchitecture.CaseReducer, ComposableArchitecture.Reducer {
}
"""
}
}

func testEnum_Empty_AccessControl_Public() {
assertMacro {
"""
@Reducer
public enum Destination {
}
"""
} expansion: {
"""
public enum Destination {
@CasePathable
@dynamicMemberLookup
@ObservableState
public enum State: ComposableArchitecture.CaseReducerState {
public typealias StateReducer = Destination
}
@CasePathable
public enum Action {
}
@ComposableArchitecture.ReducerBuilder<Self.State, Self.Action>
public static var body: ComposableArchitecture.EmptyReducer<Self.State, Self.Action> {
ComposableArchitecture.EmptyReducer<Self.State, Self.Action>()
}
public enum CaseScope {
}
public static func scope(_ store: ComposableArchitecture.Store<Self.State, Self.Action>) -> CaseScope {
switch store.state {
}
}
}
extension Destination: ComposableArchitecture.CaseReducer, ComposableArchitecture.Reducer {
}
"""
}
}

func testEnum_OneAlertCase() {
assertMacro {
"""
Expand Down

0 comments on commit 4514a16

Please sign in to comment.