Skip to content

Commit 4514a16

Browse files
authored
Add package access modifier support to @Reducer on enums (#2939)
1 parent 0301506 commit 4514a16

File tree

2 files changed

+103
-1
lines changed

2 files changed

+103
-1
lines changed

Sources/ComposableArchitectureMacros/ReducerMacro.swift

+3-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,9 @@ extension ReducerMacro: MemberMacro {
190190
providingMembersOf declaration: D,
191191
in context: C
192192
) throws -> [DeclSyntax] {
193-
let access = declaration.modifiers.first { $0.name.tokenKind == .keyword(.public) }
193+
let access = declaration.modifiers.first {
194+
[.keyword(.public), .keyword(.package)].contains($0.name.tokenKind)
195+
}
194196
let typeNames = declaration.memberBlock.members.compactMap {
195197
$0.decl.as(StructDeclSyntax.self)?.name.text
196198
?? $0.decl.as(TypeAliasDeclSyntax.self)?.name.text

Tests/ComposableArchitectureMacrosTests/ReducerMacroTests.swift

+100
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,106 @@
387387
}
388388
}
389389

390+
func testEnum_Empty_AccessControl_Package() {
391+
assertMacro {
392+
"""
393+
@Reducer
394+
package enum Destination {
395+
}
396+
"""
397+
} expansion: {
398+
"""
399+
package enum Destination {
400+
401+
@CasePathable
402+
@dynamicMemberLookup
403+
@ObservableState
404+
405+
package enum State: ComposableArchitecture.CaseReducerState {
406+
407+
package typealias StateReducer = Destination
408+
409+
}
410+
411+
@CasePathable
412+
413+
package enum Action {
414+
415+
}
416+
417+
@ComposableArchitecture.ReducerBuilder<Self.State, Self.Action>
418+
419+
package static var body: ComposableArchitecture.EmptyReducer<Self.State, Self.Action> {
420+
ComposableArchitecture.EmptyReducer<Self.State, Self.Action>()
421+
}
422+
423+
package enum CaseScope {
424+
425+
}
426+
427+
package static func scope(_ store: ComposableArchitecture.Store<Self.State, Self.Action>) -> CaseScope {
428+
switch store.state {
429+
430+
}
431+
}
432+
}
433+
434+
extension Destination: ComposableArchitecture.CaseReducer, ComposableArchitecture.Reducer {
435+
}
436+
"""
437+
}
438+
}
439+
440+
func testEnum_Empty_AccessControl_Public() {
441+
assertMacro {
442+
"""
443+
@Reducer
444+
public enum Destination {
445+
}
446+
"""
447+
} expansion: {
448+
"""
449+
public enum Destination {
450+
451+
@CasePathable
452+
@dynamicMemberLookup
453+
@ObservableState
454+
455+
public enum State: ComposableArchitecture.CaseReducerState {
456+
457+
public typealias StateReducer = Destination
458+
459+
}
460+
461+
@CasePathable
462+
463+
public enum Action {
464+
465+
}
466+
467+
@ComposableArchitecture.ReducerBuilder<Self.State, Self.Action>
468+
469+
public static var body: ComposableArchitecture.EmptyReducer<Self.State, Self.Action> {
470+
ComposableArchitecture.EmptyReducer<Self.State, Self.Action>()
471+
}
472+
473+
public enum CaseScope {
474+
475+
}
476+
477+
public static func scope(_ store: ComposableArchitecture.Store<Self.State, Self.Action>) -> CaseScope {
478+
switch store.state {
479+
480+
}
481+
}
482+
}
483+
484+
extension Destination: ComposableArchitecture.CaseReducer, ComposableArchitecture.Reducer {
485+
}
486+
"""
487+
}
488+
}
489+
390490
func testEnum_OneAlertCase() {
391491
assertMacro {
392492
"""

0 commit comments

Comments
 (0)