@@ -25,7 +25,8 @@ extension ReducerMacro: ExtensionMacro {
25
25
{
26
26
return [ ]
27
27
}
28
- let proto = declaration. isEnum
28
+ let proto =
29
+ declaration. isEnum
29
30
? " ComposableArchitecture.CaseReducer, ComposableArchitecture.Reducer "
30
31
: " ComposableArchitecture.Reducer "
31
32
let ext : DeclSyntax =
@@ -132,7 +133,8 @@ extension ReducerMacro: MemberAttributeMacro {
132
133
!attributeName. starts ( with: " ComposableArchitecture.ReducerBuilder " )
133
134
else { return [ ] }
134
135
}
135
- let genericArguments = genericArguments. count == 1
136
+ let genericArguments =
137
+ genericArguments. count == 1
136
138
? " \( genericArguments. description) .State, \( genericArguments. description) .Action "
137
139
: " \( genericArguments) "
138
140
return [
@@ -176,8 +178,8 @@ extension ReducerMacro: MemberAttributeMacro {
176
178
}
177
179
}
178
180
179
- private extension IdentifierTypeSyntax {
180
- var isEphemeral : Bool {
181
+ extension IdentifierTypeSyntax {
182
+ fileprivate var isEphemeral : Bool {
181
183
self . name. text == " AlertState " || self . name. text == " ConfirmationDialogState "
182
184
}
183
185
}
@@ -215,20 +217,23 @@ extension ReducerMacro: MemberMacro {
215
217
}
216
218
return true
217
219
}
218
- let hasExplicitReducerBody = bindings. contains {
219
- guard $0. initializer == nil
220
- else { return true }
221
- guard let name = $0. typeAnnotation? . type. as ( SomeOrAnyTypeSyntax . self) ? . constraint
222
- . as ( IdentifierTypeSyntax . self) ? . name. text
223
- else {
224
- return false
225
- }
226
- return [ " Reducer " , " ReducerOf " ] . withQualified. contains ( name)
227
- } || hasReduceMethod
228
- let hasBody = bindings. contains {
229
- $0. as ( PatternBindingSyntax . self) ? . pattern
230
- . as ( IdentifierPatternSyntax . self) ? . identifier. text == " body "
231
- } || hasReduceMethod
220
+ let hasExplicitReducerBody =
221
+ bindings. contains {
222
+ guard $0. initializer == nil
223
+ else { return true }
224
+ guard
225
+ let name = $0. typeAnnotation? . type. as ( SomeOrAnyTypeSyntax . self) ? . constraint
226
+ . as ( IdentifierTypeSyntax . self) ? . name. text
227
+ else {
228
+ return false
229
+ }
230
+ return [ " Reducer " , " ReducerOf " ] . withQualified. contains ( name)
231
+ } || hasReduceMethod
232
+ let hasBody =
233
+ bindings. contains {
234
+ $0. as ( PatternBindingSyntax . self) ? . pattern
235
+ . as ( IdentifierPatternSyntax . self) ? . identifier. text == " body "
236
+ } || hasReduceMethod
232
237
var decls : [ DeclSyntax ] = [ ]
233
238
if let enumDecl = declaration. as ( EnumDeclSyntax . self) {
234
239
let enumCaseElements = enumDecl. memberBlock
@@ -257,7 +262,8 @@ extension ReducerMacro: MemberMacro {
257
262
parameter. type. is ( IdentifierTypeSyntax . self) || parameter. type. is ( MemberTypeSyntax . self)
258
263
{
259
264
let type = parameter. type
260
- let stateCase = enumCaseElement. attribute == . ephemeral
265
+ let stateCase =
266
+ enumCaseElement. attribute == . ephemeral
261
267
? element
262
268
: element. suffixed ( " State " )
263
269
stateCaseDecls. append ( " case \( stateCase. trimmedDescription) " )
@@ -311,7 +317,8 @@ extension ReducerMacro: MemberMacro {
311
317
if case let . argumentList( arguments) = node. arguments,
312
318
let startIndex = arguments. firstIndex ( where: { $0. label? . text == " state " } )
313
319
{
314
- let endIndex = arguments. firstIndex ( where: { $0. label? . text == " action " } )
320
+ let endIndex =
321
+ arguments. firstIndex ( where: { $0. label? . text == " action " } )
315
322
?? arguments. endIndex
316
323
conformances. append (
317
324
contentsOf: arguments [ startIndex..< endIndex] . compactMap {
@@ -400,7 +407,8 @@ extension ReducerMacro: MemberMacro {
400
407
fixIt: . replace(
401
408
message: MacroExpansionFixItMessage ( " Remove '( \( arguments) )' " ) ,
402
409
oldNode: node,
403
- newNode: node
410
+ newNode:
411
+ node
404
412
. with ( \. leftParen, nil )
405
413
. with ( \. arguments, nil )
406
414
. with ( \. rightParen, nil )
@@ -487,8 +495,8 @@ private final class ReduceVisitor: SyntaxVisitor {
487
495
}
488
496
}
489
497
490
- private extension EnumCaseDeclSyntax {
491
- var attribute : ReducerCase . Attribute ? {
498
+ extension EnumCaseDeclSyntax {
499
+ fileprivate var attribute : ReducerCase . Attribute ? {
492
500
if self . isIgnored {
493
501
return . ignored
494
502
} else if self . isEphemeral {
@@ -498,12 +506,12 @@ private extension EnumCaseDeclSyntax {
498
506
}
499
507
}
500
508
501
- var isIgnored : Bool {
509
+ fileprivate var isIgnored : Bool {
502
510
self . attributes. contains ( " ReducerCaseIgnored " )
503
511
|| self . elements. contains { $0. parameterClause? . parameters. count != 1 }
504
512
}
505
513
506
- var isEphemeral : Bool {
514
+ fileprivate var isEphemeral : Bool {
507
515
self . attributes. contains ( " ReducerCaseEphemeral " )
508
516
|| self . elements. contains {
509
517
guard
@@ -517,8 +525,8 @@ private extension EnumCaseDeclSyntax {
517
525
}
518
526
}
519
527
520
- private extension EnumCaseElementSyntax {
521
- func suffixed( _ suffix: TokenSyntax ) -> Self {
528
+ extension EnumCaseElementSyntax {
529
+ fileprivate func suffixed( _ suffix: TokenSyntax ) -> Self {
522
530
var element = self
523
531
if var parameterClause = element. parameterClause,
524
532
let type = parameterClause. parameters. first? . type
@@ -531,8 +539,8 @@ private extension EnumCaseElementSyntax {
531
539
}
532
540
}
533
541
534
- private extension AttributeListSyntax {
535
- func contains( _ name: TokenSyntax ) -> Bool {
542
+ extension AttributeListSyntax {
543
+ fileprivate func contains( _ name: TokenSyntax ) -> Bool {
536
544
self . contains {
537
545
guard
538
546
case let . attribute( attribute) = $0,
0 commit comments