Skip to content

Commit

Permalink
Update SwiftSyntax. (#2884)
Browse files Browse the repository at this point in the history
* Update SwiftSyntax.

* wip

* fix

* wip

---------

Co-authored-by: Stephen Celis <stephen@stephencelis.com>
  • Loading branch information
mbrandonw and stephencelis committed Mar 5, 2024
1 parent 53af95a commit 115fe5a
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-custom-dump",
"state" : {
"revision" : "aedcf6f4cd486ccef5b312ccac85d4b3f6e58605",
"version" : "1.1.2"
"revision" : "3ce83179e5f0c83ad54c305779c6b438e82aaf1d",
"version" : "1.2.1"
}
},
{
"identity" : "swift-dependencies",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-dependencies",
"state" : {
"revision" : "c31b1445c4fae49e6fdb75496b895a3653f6aefc",
"version" : "1.1.5"
"revision" : "d3a5af3038a09add4d7682f66555d6212058a3c0",
"version" : "1.2.2"
}
},
{
Expand Down Expand Up @@ -113,35 +113,35 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-macro-testing",
"state" : {
"revision" : "10dcef36314ddfea6f60442169b0b320204cbd35",
"version" : "0.2.2"
"revision" : "90e38eec4bf661ec0da1bbfd3ec507d0f0c05310",
"version" : "0.3.0"
}
},
{
"identity" : "swift-perception",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-perception",
"state" : {
"revision" : "42240120b2a8797595433288ab4118f8042214c3",
"version" : "1.1.1"
"revision" : "a5bb578d963fcdbffe4fd56c92b2e222f5b02c8a",
"version" : "1.1.2"
}
},
{
"identity" : "swift-snapshot-testing",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-snapshot-testing.git",
"state" : {
"revision" : "59b663f68e69f27a87b45de48cb63264b8194605",
"version" : "1.15.1"
"revision" : "5b0c434778f2c1a4c9b5ebdb8682b28e84dd69bd",
"version" : "1.15.4"
}
},
{
"identity" : "swift-syntax",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-syntax",
"state" : {
"revision" : "6ad4ea24b01559dde0773e3d091f1b9e36175036",
"version" : "509.0.2"
"revision" : "08a2f0a9a30e0f705f79c9cfaca1f68b71bdc775",
"version" : "510.0.0"
}
},
{
Expand All @@ -158,17 +158,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swiftui-navigation.git",
"state" : {
"revision" : "78f9d72cf667adb47e2040aa373185c88c63f0dc",
"version" : "1.2.0"
"revision" : "d9e72f3083c08375794afa216fb2f89c0114f303",
"version" : "1.2.1"
}
},
{
"identity" : "xctest-dynamic-overlay",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/xctest-dynamic-overlay",
"state" : {
"revision" : "b58e6627149808b40634c4552fcf2f44d0b3ca87",
"version" : "1.1.0"
"revision" : "b13b1d1a8e787a5ffc71ac19dcaf52183ab27ba2",
"version" : "1.1.1"
}
}
],
Expand Down
2 changes: 1 addition & 1 deletion Package@swift-5.9.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ let package = Package(
dependencies: [
.package(url: "https://github.com/apple/swift-collections", from: "1.0.2"),
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),
.package(url: "https://github.com/apple/swift-syntax", from: "509.0.0"),
.package(url: "https://github.com/apple/swift-syntax", "509.0.0"..<"511.0.0"),
.package(url: "https://github.com/google/swift-benchmark", from: "0.1.0"),
.package(url: "https://github.com/pointfreeco/combine-schedulers", from: "1.0.0"),
.package(url: "https://github.com/pointfreeco/swift-case-paths", from: "1.3.0"),
Expand Down
12 changes: 10 additions & 2 deletions Sources/ComposableArchitectureMacros/ObservableStateMacro.swift
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,9 @@ extension VariableDeclSyntax {
renamed rename: String,
context: C
) {
if let attribute = self.firstAttribute(for: name) {
if let attribute = self.firstAttribute(for: name),
let type = attribute.attributeName.as(IdentifierTypeSyntax.self)
{
context.diagnose(
Diagnostic(
node: attribute,
Expand All @@ -475,7 +477,13 @@ extension VariableDeclSyntax {
message: MacroExpansionFixItMessage("Use '@\(rename)' instead"),
oldNode: attribute,
newNode: attribute.with(
\.attributeName, TypeSyntax(IdentifierTypeSyntax(name: .identifier(rename)))
\.attributeName,
TypeSyntax(
type.with(
\.name,
.identifier(rename, trailingTrivia: type.name.trailingTrivia)
)
)
)
)
)
Expand Down
7 changes: 5 additions & 2 deletions Sources/ComposableArchitectureMacros/ReducerMacro.swift
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,7 @@ extension ReducerMacro: MemberMacro {
} || hasReduceMethod
let hasBody =
bindings.contains {
$0.as(PatternBindingSyntax.self)?.pattern
.as(IdentifierPatternSyntax.self)?.identifier.text == "body"
$0.pattern.as(IdentifierPatternSyntax.self)?.identifier.text == "body"
} || hasReduceMethod
var decls: [DeclSyntax] = []
if let enumDecl = declaration.as(EnumDeclSyntax.self) {
Expand Down Expand Up @@ -686,6 +685,10 @@ struct MacroExpansionNoteMessage: NoteMessage {
}

var fixItID: MessageID {
self.noteID
}

var noteID: MessageID {
MessageID(domain: diagnosticDomain, id: "\(Self.self)")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#"""
@available(iOS 18, *)
struct State {
var count = 0 {
var count {
@storageRestrictions(initializes: _count)
init(initialValue) {
_count = initialValue
Expand Down Expand Up @@ -71,7 +71,7 @@
} expansion: {
#"""
struct State {
var count = 0 {
var count {
@storageRestrictions(initializes: _count)
init(initialValue) {
_count = initialValue
Expand Down Expand Up @@ -117,7 +117,7 @@
} expansion: {
#"""
public struct State {
var count = 0 {
var count {
@storageRestrictions(initializes: _count)
init(initialValue) {
_count = initialValue
Expand Down Expand Up @@ -160,7 +160,7 @@
} expansion: {
#"""
package struct State {
var count = 0 {
var count {
@storageRestrictions(initializes: _count)
init(initialValue) {
_count = initialValue
Expand Down
34 changes: 31 additions & 3 deletions Tests/ComposableArchitectureMacrosTests/PresentsMacroTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,40 @@
"""
@ObservableState
struct State: Equatable {
@Presents
@Presents var destination: Destination.State?
}
"""
} expansion: {
"""
#"""
struct State: Equatable {
var destination: Destination.State? {
@storageRestrictions(initializes: _destination)
init(initialValue) {
_destination = PresentationState(wrappedValue: initialValue)
}
get {
_$observationRegistrar.access(self, keyPath: \.destination)
return _destination.wrappedValue
}
set {
_$observationRegistrar.mutate(self, keyPath: \.destination, &_destination.wrappedValue, newValue, _$isIdentityEqual)
}
}
var $destination: ComposableArchitecture.PresentationState<Destination.State> {
get {
_$observationRegistrar.access(self, keyPath: \.destination)
return _destination.projectedValue
}
set {
_$observationRegistrar.mutate(self, keyPath: \.destination, &_destination.projectedValue, newValue, _$isIdentityEqual)
}
}
private var _destination = ComposableArchitecture.PresentationState<Destination.State>(wrappedValue: nil)
var _$observationRegistrar = ComposableArchitecture.ObservationStateRegistrar()
Expand All @@ -176,7 +204,7 @@
_$observationRegistrar._$willModify()
}
}
"""
"""#
}
}
}
Expand Down
18 changes: 9 additions & 9 deletions Tests/ComposableArchitectureMacrosTests/ReducerMacroTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -298,11 +298,11 @@
case activity(Activity.Action)
case timeline(Timeline.Action)
case tweet(Tweet.Action)
case alert(AlertState<Alert>.Action)
case alert(AlertState<Alert> .Action)
}
@ComposableArchitecture.ReducerBuilder<Self.State, Self.Action>
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>> {
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>> {
ComposableArchitecture.Scope(state: \Self.State.Cases.activity, action: \Self.Action.Cases.activity) {
Activity()
}
Expand Down Expand Up @@ -411,7 +411,7 @@
@CasePathable
enum Action {
case alert(AlertState<Never>.Action)
case alert(AlertState<Never> .Action)
}
@ComposableArchitecture.ReducerBuilder<Self.State, Self.Action>
Expand Down Expand Up @@ -468,7 +468,7 @@
}
@ComposableArchitecture.ReducerBuilder<Self.State, Self.Action>
static var body: ComposableArchitecture.ReducerBuilder<Self.State, Self.Action>._Sequence<ComposableArchitecture.Scope<Self.State, Self.Action, Activity>, ComposableArchitecture.Scope<Self.State, Self.Action, Timeline>> {
static var body: ComposableArchitecture.ReducerBuilder<Self.State, Self.Action> ._Sequence<ComposableArchitecture.Scope<Self.State, Self.Action, Activity>, ComposableArchitecture.Scope<Self.State, Self.Action, Timeline>> {
ComposableArchitecture.Scope(state: \Self.State.Cases.activity, action: \Self.Action.Cases.activity) {
Activity()
}
Expand Down Expand Up @@ -589,8 +589,8 @@
@CasePathable
enum Action {
case alert(AlertState<Alert>.Action)
case dialog(ConfirmationDialogState<Dialog>.Action)
case alert(AlertState<Alert> .Action)
case dialog(ConfirmationDialogState<Dialog> .Action)
}
@ComposableArchitecture.ReducerBuilder<Self.State, Self.Action>
Expand Down Expand Up @@ -657,7 +657,7 @@
}
@ComposableArchitecture.ReducerBuilder<Self.State, Self.Action>
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>> {
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>> {
ComposableArchitecture.Scope(state: \Self.State.Cases.drillDown, action: \Self.Action.Cases.drillDown) {
Counter()
}
Expand Down Expand Up @@ -1020,7 +1020,7 @@
case child(ChildFeature.Action)
#if os(macOS)
case mac(MacFeature.Action)
case macAlert(AlertState<MacAlert>.Action)
case macAlert(AlertState<MacAlert> .Action)
#elseif os(iOS)
case phone(PhoneFeature.Action)
#else
Expand All @@ -1030,7 +1030,7 @@
#if DEBUG
#if INNER
case inner(InnerFeature.Action)
case innerDialog(ConfirmationDialogState<InnerDialog>.Action)
case innerDialog(ConfirmationDialogState<InnerDialog> .Action)
#endif
#endif
Expand Down

0 comments on commit 115fe5a

Please sign in to comment.