Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump swift-syntax to 510.0 #47

Merged
merged 2 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,44 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-collections",
"state" : {
"revision" : "d029d9d39c87bed85b1c50adee7c41795261a192",
"version" : "1.0.6"
"revision" : "94cf62b3ba8d4bed62680a282d4c25f9c63c2efb",
"version" : "1.1.0"
}
},
{
"identity" : "swift-macro-testing",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-macro-testing",
"state" : {
"revision" : "35acd9468d40ae87e75991a18af6271e8124c261",
"version" : "0.2.1"
"revision" : "90e38eec4bf661ec0da1bbfd3ec507d0f0c05310",
"version" : "0.3.0"
}
},
{
"identity" : "swift-snapshot-testing",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-snapshot-testing",
"state" : {
"revision" : "bb0ea08db8e73324fe6c3727f755ca41a23ff2f4",
"version" : "1.14.2"
"revision" : "5b0c434778f2c1a4c9b5ebdb8682b28e84dd69bd",
"version" : "1.15.4"
}
},
{
"identity" : "swift-syntax",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-syntax.git",
"location" : "https://github.com/apple/swift-syntax",
"state" : {
"revision" : "74203046135342e4a4a627476dd6caf8b28fe11b",
"version" : "509.0.0"
"revision" : "08a2f0a9a30e0f705f79c9cfaca1f68b71bdc775",
"version" : "510.0.0"
}
},
{
"identity" : "xctest-dynamic-overlay",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/xctest-dynamic-overlay",
"state" : {
"revision" : "23cbf2294e350076ea4dbd7d5d047c1e76b03631",
"version" : "1.0.2"
"revision" : "b13b1d1a8e787a5ffc71ac19dcaf52183ab27ba2",
"version" : "1.1.1"
}
}
],
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ let package = Package(
.library(name: "Perception", targets: ["Perception"])
],
dependencies: [
.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/apple/swift-collections", from: "1.0.0"),
.package(url: "https://github.com/pointfreeco/swift-macro-testing", from: "0.1.0"),
.package(url: "https://github.com/pointfreeco/xctest-dynamic-overlay", from: "1.0.0"),
Expand Down
19 changes: 6 additions & 13 deletions Sources/PerceptionMacros/Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ extension VariableDeclSyntax {

func accessorsMatching(_ predicate: (TokenKind) -> Bool) -> [AccessorDeclSyntax] {
let patternBindings = bindings.compactMap { binding in
binding.as(PatternBindingSyntax.self)
binding
}
let accessors: [AccessorDeclListSyntax.Element] = patternBindings.compactMap { patternBinding in
switch patternBinding.accessorBlock?.accessors {
Expand All @@ -52,14 +52,7 @@ extension VariableDeclSyntax {
}
}.flatMap { $0 }
return accessors.compactMap { accessor in
guard let decl = accessor.as(AccessorDeclSyntax.self) else {
return nil
}
if predicate(decl.accessorSpecifier.tokenKind) {
return decl
} else {
return nil
}
predicate(accessor.accessorSpecifier.tokenKind) ? accessor : nil
}
}

Expand Down Expand Up @@ -215,7 +208,7 @@ extension DeclGroupSyntax {
var memberFunctionStandins: [FunctionDeclSyntax.SignatureStandin] {
var standins = [FunctionDeclSyntax.SignatureStandin]()
for member in memberBlock.members {
if let function = member.as(MemberBlockItemSyntax.self)?.decl.as(FunctionDeclSyntax.self) {
if let function = member.decl.as(FunctionDeclSyntax.self) {
standins.append(function.signatureStandin)
}
}
Expand All @@ -224,7 +217,7 @@ extension DeclGroupSyntax {

func hasMemberFunction(equivalentTo other: FunctionDeclSyntax) -> Bool {
for member in memberBlock.members {
if let function = member.as(MemberBlockItemSyntax.self)?.decl.as(FunctionDeclSyntax.self) {
if let function = member.decl.as(FunctionDeclSyntax.self) {
if function.isEquivalent(to: other) {
return true
}
Expand All @@ -235,7 +228,7 @@ extension DeclGroupSyntax {

func hasMemberProperty(equivalentTo other: VariableDeclSyntax) -> Bool {
for member in memberBlock.members {
if let variable = member.as(MemberBlockItemSyntax.self)?.decl.as(VariableDeclSyntax.self) {
if let variable = member.decl.as(VariableDeclSyntax.self) {
if variable.isEquivalent(to: other) {
return true
}
Expand All @@ -246,7 +239,7 @@ extension DeclGroupSyntax {

var definedVariables: [VariableDeclSyntax] {
memberBlock.members.compactMap { member in
if let variableDecl = member.as(MemberBlockItemSyntax.self)?.decl.as(VariableDeclSyntax.self)
if let variableDecl = member.decl.as(VariableDeclSyntax.self)
{
return variableDecl
}
Expand Down
30 changes: 15 additions & 15 deletions Sources/PerceptionMacros/PerceptibleMacro.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ public struct PerceptibleMacro {
return
"""
internal nonisolated func access<Member>(
keyPath: KeyPath<\(perceptibleType), Member>,
file: StaticString = #file,
line: UInt = #line
keyPath: KeyPath<\(perceptibleType), Member>,
file: StaticString = #file,
line: UInt = #line
) {
\(raw: registrarVariableName).access(self, keyPath: keyPath, file: file, line: line)
\(raw: registrarVariableName).access(self, keyPath: keyPath, file: file, line: line)
}
"""
}
Expand All @@ -61,10 +61,10 @@ public struct PerceptibleMacro {
return
"""
internal nonisolated func withMutation<Member, MutationResult>(
keyPath: KeyPath<\(perceptibleType), Member>,
_ mutation: () throws -> MutationResult
keyPath: KeyPath<\(perceptibleType), Member>,
_ mutation: () throws -> MutationResult
) rethrows -> MutationResult {
try \(raw: registrarVariableName).withMutation(of: self, keyPath: keyPath, mutation)
try \(raw: registrarVariableName).withMutation(of: self, keyPath: keyPath, mutation)
}
"""
}
Expand Down Expand Up @@ -218,7 +218,7 @@ extension PerceptibleMacro: MemberMacro {
return []
}

let perceptibleType = identified.name
let perceptibleType = identified.name.trimmed

if declaration.isEnum {
// enumerations cannot store properties
Expand Down Expand Up @@ -333,7 +333,7 @@ public struct PerceptionTrackedMacro: AccessorMacro {
) throws -> [AccessorDeclSyntax] {
guard let property = declaration.as(VariableDeclSyntax.self),
property.isValidForPerception,
let identifier = property.identifier
let identifier = property.identifier?.trimmed
else {
return []
}
Expand All @@ -346,24 +346,24 @@ public struct PerceptionTrackedMacro: AccessorMacro {
"""
@storageRestrictions(initializes: _\(identifier))
init(initialValue) {
_\(identifier) = initialValue
_\(identifier) = initialValue
}
"""

let getAccessor: AccessorDeclSyntax =
"""
get {
access(keyPath: \\.\(identifier))
return _\(identifier)
access(keyPath: \\.\(identifier))
return _\(identifier)
}
"""

let setAccessor: AccessorDeclSyntax =
"""
set {
withMutation(keyPath: \\.\(identifier)) {
_\(identifier) = newValue
}
withMutation(keyPath: \\.\(identifier)) {
_\(identifier) = newValue
}
}
"""

Expand Down
22 changes: 11 additions & 11 deletions Tests/PerceptionMacrosTests/PerceptionMacrosTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
class PerceptionMacroTests: XCTestCase {
override func invokeTest() {
withMacroTesting(
//isRecording: true,
// isRecording: true,
macros: [
PerceptibleMacro.self,
PerceptionTrackedMacro.self,
Expand All @@ -28,34 +28,34 @@
} expansion: {
#"""
class Feature {
var count = 0 {
@storageRestrictions(initializes: _count )
var count {
@storageRestrictions(initializes: _count)
init(initialValue) {
_count = initialValue
_count = initialValue
}
get {
access(keyPath: \.count )
access(keyPath: \.count)
return _count
}
set {
withMutation(keyPath: \.count ) {
_count = newValue
withMutation(keyPath: \.count) {
_count = newValue
}
}
}

private let _$perceptionRegistrar = Perception.PerceptionRegistrar()

internal nonisolated func access<Member>(
keyPath: KeyPath<Feature , Member>,
file: StaticString = #file,
line: UInt = #line
keyPath: KeyPath<Feature, Member>,
file: StaticString = #file,
line: UInt = #line
) {
_$perceptionRegistrar.access(self, keyPath: keyPath, file: file, line: line)
}

internal nonisolated func withMutation<Member, MutationResult>(
keyPath: KeyPath<Feature , Member>,
keyPath: KeyPath<Feature, Member>,
_ mutation: () throws -> MutationResult
) rethrows -> MutationResult {
try _$perceptionRegistrar.withMutation(of: self, keyPath: keyPath, mutation)
Expand Down
Loading