Skip to content

Commit 115fe5a

Browse files
Update SwiftSyntax. (pointfreeco#2884)
* Update SwiftSyntax. * wip * fix * wip --------- Co-authored-by: Stephen Celis <stephen@stephencelis.com>
1 parent 53af95a commit 115fe5a

File tree

7 files changed

+76
-37
lines changed

7 files changed

+76
-37
lines changed

ComposableArchitecture.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 16 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package@swift-5.9.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ let package = Package(
2020
dependencies: [
2121
.package(url: "https://github.com/apple/swift-collections", from: "1.0.2"),
2222
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),
23-
.package(url: "https://github.com/apple/swift-syntax", from: "509.0.0"),
23+
.package(url: "https://github.com/apple/swift-syntax", "509.0.0"..<"511.0.0"),
2424
.package(url: "https://github.com/google/swift-benchmark", from: "0.1.0"),
2525
.package(url: "https://github.com/pointfreeco/combine-schedulers", from: "1.0.0"),
2626
.package(url: "https://github.com/pointfreeco/swift-case-paths", from: "1.3.0"),

Sources/ComposableArchitectureMacros/ObservableStateMacro.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,9 @@ extension VariableDeclSyntax {
466466
renamed rename: String,
467467
context: C
468468
) {
469-
if let attribute = self.firstAttribute(for: name) {
469+
if let attribute = self.firstAttribute(for: name),
470+
let type = attribute.attributeName.as(IdentifierTypeSyntax.self)
471+
{
470472
context.diagnose(
471473
Diagnostic(
472474
node: attribute,
@@ -475,7 +477,13 @@ extension VariableDeclSyntax {
475477
message: MacroExpansionFixItMessage("Use '@\(rename)' instead"),
476478
oldNode: attribute,
477479
newNode: attribute.with(
478-
\.attributeName, TypeSyntax(IdentifierTypeSyntax(name: .identifier(rename)))
480+
\.attributeName,
481+
TypeSyntax(
482+
type.with(
483+
\.name,
484+
.identifier(rename, trailingTrivia: type.name.trailingTrivia)
485+
)
486+
)
479487
)
480488
)
481489
)

Sources/ComposableArchitectureMacros/ReducerMacro.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,7 @@ extension ReducerMacro: MemberMacro {
231231
} || hasReduceMethod
232232
let hasBody =
233233
bindings.contains {
234-
$0.as(PatternBindingSyntax.self)?.pattern
235-
.as(IdentifierPatternSyntax.self)?.identifier.text == "body"
234+
$0.pattern.as(IdentifierPatternSyntax.self)?.identifier.text == "body"
236235
} || hasReduceMethod
237236
var decls: [DeclSyntax] = []
238237
if let enumDecl = declaration.as(EnumDeclSyntax.self) {
@@ -686,6 +685,10 @@ struct MacroExpansionNoteMessage: NoteMessage {
686685
}
687686

688687
var fixItID: MessageID {
688+
self.noteID
689+
}
690+
691+
var noteID: MessageID {
689692
MessageID(domain: diagnosticDomain, id: "\(Self.self)")
690693
}
691694
}

Tests/ComposableArchitectureMacrosTests/ObservableStateMacroTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#"""
2626
@available(iOS 18, *)
2727
struct State {
28-
var count = 0 {
28+
var count {
2929
@storageRestrictions(initializes: _count)
3030
init(initialValue) {
3131
_count = initialValue
@@ -71,7 +71,7 @@
7171
} expansion: {
7272
#"""
7373
struct State {
74-
var count = 0 {
74+
var count {
7575
@storageRestrictions(initializes: _count)
7676
init(initialValue) {
7777
_count = initialValue
@@ -117,7 +117,7 @@
117117
} expansion: {
118118
#"""
119119
public struct State {
120-
var count = 0 {
120+
var count {
121121
@storageRestrictions(initializes: _count)
122122
init(initialValue) {
123123
_count = initialValue
@@ -160,7 +160,7 @@
160160
} expansion: {
161161
#"""
162162
package struct State {
163-
var count = 0 {
163+
var count {
164164
@storageRestrictions(initializes: _count)
165165
init(initialValue) {
166166
_count = initialValue

Tests/ComposableArchitectureMacrosTests/PresentsMacroTests.swift

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,40 @@
159159
"""
160160
@ObservableState
161161
struct State: Equatable {
162-
@Presents
162+
@Presents var destination: Destination.State?
163163
}
164164
"""
165165
} expansion: {
166-
"""
166+
#"""
167167
struct State: Equatable {
168+
169+
var destination: Destination.State? {
170+
@storageRestrictions(initializes: _destination)
171+
init(initialValue) {
172+
_destination = PresentationState(wrappedValue: initialValue)
173+
}
174+
get {
175+
_$observationRegistrar.access(self, keyPath: \.destination)
176+
return _destination.wrappedValue
177+
}
178+
set {
179+
_$observationRegistrar.mutate(self, keyPath: \.destination, &_destination.wrappedValue, newValue, _$isIdentityEqual)
180+
}
181+
}
182+
183+
var $destination: ComposableArchitecture.PresentationState<Destination.State> {
184+
get {
185+
_$observationRegistrar.access(self, keyPath: \.destination)
186+
return _destination.projectedValue
187+
}
188+
set {
189+
_$observationRegistrar.mutate(self, keyPath: \.destination, &_destination.projectedValue, newValue, _$isIdentityEqual)
190+
}
191+
}
192+
193+
194+
195+
private var _destination = ComposableArchitecture.PresentationState<Destination.State>(wrappedValue: nil)
168196
169197
var _$observationRegistrar = ComposableArchitecture.ObservationStateRegistrar()
170198
@@ -176,7 +204,7 @@
176204
_$observationRegistrar._$willModify()
177205
}
178206
}
179-
"""
207+
"""#
180208
}
181209
}
182210
}

Tests/ComposableArchitectureMacrosTests/ReducerMacroTests.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -298,11 +298,11 @@
298298
case activity(Activity.Action)
299299
case timeline(Timeline.Action)
300300
case tweet(Tweet.Action)
301-
case alert(AlertState<Alert>.Action)
301+
case alert(AlertState<Alert> .Action)
302302
}
303303
304304
@ComposableArchitecture.ReducerBuilder<Self.State, Self.Action>
305-
static var body: ComposableArchitecture.ReducerBuilder<Self.State, Self.Action>._Sequence<ComposableArchitecture.ReducerBuilder<Self.State, Self.Action>._Sequence<ComposableArchitecture.Scope<Self.State, Self.Action, Activity>, ComposableArchitecture.Scope<Self.State, Self.Action, Timeline>>, ComposableArchitecture.Scope<Self.State, Self.Action, Tweet>> {
305+
static var body: ComposableArchitecture.ReducerBuilder<Self.State, Self.Action> ._Sequence<ComposableArchitecture.ReducerBuilder<Self.State, Self.Action> ._Sequence<ComposableArchitecture.Scope<Self.State, Self.Action, Activity>, ComposableArchitecture.Scope<Self.State, Self.Action, Timeline>>, ComposableArchitecture.Scope<Self.State, Self.Action, Tweet>> {
306306
ComposableArchitecture.Scope(state: \Self.State.Cases.activity, action: \Self.Action.Cases.activity) {
307307
Activity()
308308
}
@@ -411,7 +411,7 @@
411411
412412
@CasePathable
413413
enum Action {
414-
case alert(AlertState<Never>.Action)
414+
case alert(AlertState<Never> .Action)
415415
}
416416
417417
@ComposableArchitecture.ReducerBuilder<Self.State, Self.Action>
@@ -468,7 +468,7 @@
468468
}
469469
470470
@ComposableArchitecture.ReducerBuilder<Self.State, Self.Action>
471-
static var body: ComposableArchitecture.ReducerBuilder<Self.State, Self.Action>._Sequence<ComposableArchitecture.Scope<Self.State, Self.Action, Activity>, ComposableArchitecture.Scope<Self.State, Self.Action, Timeline>> {
471+
static var body: ComposableArchitecture.ReducerBuilder<Self.State, Self.Action> ._Sequence<ComposableArchitecture.Scope<Self.State, Self.Action, Activity>, ComposableArchitecture.Scope<Self.State, Self.Action, Timeline>> {
472472
ComposableArchitecture.Scope(state: \Self.State.Cases.activity, action: \Self.Action.Cases.activity) {
473473
Activity()
474474
}
@@ -589,8 +589,8 @@
589589
590590
@CasePathable
591591
enum Action {
592-
case alert(AlertState<Alert>.Action)
593-
case dialog(ConfirmationDialogState<Dialog>.Action)
592+
case alert(AlertState<Alert> .Action)
593+
case dialog(ConfirmationDialogState<Dialog> .Action)
594594
}
595595
596596
@ComposableArchitecture.ReducerBuilder<Self.State, Self.Action>
@@ -657,7 +657,7 @@
657657
}
658658
659659
@ComposableArchitecture.ReducerBuilder<Self.State, Self.Action>
660-
static var body: ComposableArchitecture.ReducerBuilder<Self.State, Self.Action>._Sequence<ComposableArchitecture.ReducerBuilder<Self.State, Self.Action>._Sequence<ComposableArchitecture.Scope<Self.State, Self.Action, Counter>, ComposableArchitecture.Scope<Self.State, Self.Action, Counter>>, ComposableArchitecture.Scope<Self.State, Self.Action, Counter>> {
660+
static var body: ComposableArchitecture.ReducerBuilder<Self.State, Self.Action> ._Sequence<ComposableArchitecture.ReducerBuilder<Self.State, Self.Action> ._Sequence<ComposableArchitecture.Scope<Self.State, Self.Action, Counter>, ComposableArchitecture.Scope<Self.State, Self.Action, Counter>>, ComposableArchitecture.Scope<Self.State, Self.Action, Counter>> {
661661
ComposableArchitecture.Scope(state: \Self.State.Cases.drillDown, action: \Self.Action.Cases.drillDown) {
662662
Counter()
663663
}
@@ -1020,7 +1020,7 @@
10201020
case child(ChildFeature.Action)
10211021
#if os(macOS)
10221022
case mac(MacFeature.Action)
1023-
case macAlert(AlertState<MacAlert>.Action)
1023+
case macAlert(AlertState<MacAlert> .Action)
10241024
#elseif os(iOS)
10251025
case phone(PhoneFeature.Action)
10261026
#else
@@ -1030,7 +1030,7 @@
10301030
#if DEBUG
10311031
#if INNER
10321032
case inner(InnerFeature.Action)
1033-
case innerDialog(ConfirmationDialogState<InnerDialog>.Action)
1033+
case innerDialog(ConfirmationDialogState<InnerDialog> .Action)
10341034
#endif
10351035
#endif
10361036

0 commit comments

Comments
 (0)