Skip to content

Commit a5bb578

Browse files
authored
Bump swift-syntax to 510.0 (pointfreeco#47)
* Bump swift-syntax to 510.0 * fix
1 parent b646ffc commit a5bb578

File tree

5 files changed

+44
-51
lines changed

5 files changed

+44
-51
lines changed

Package.resolved

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

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ let package = Package(
1515
.library(name: "Perception", targets: ["Perception"])
1616
],
1717
dependencies: [
18-
.package(url: "https://github.com/apple/swift-syntax", from: "509.0.0"),
18+
.package(url: "https://github.com/apple/swift-syntax", "509.0.0"..<"511.0.0"),
1919
.package(url: "https://github.com/apple/swift-collections", from: "1.0.0"),
2020
.package(url: "https://github.com/pointfreeco/swift-macro-testing", from: "0.1.0"),
2121
.package(url: "https://github.com/pointfreeco/xctest-dynamic-overlay", from: "1.0.0"),

Sources/PerceptionMacros/Extensions.swift

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ extension VariableDeclSyntax {
4141

4242
func accessorsMatching(_ predicate: (TokenKind) -> Bool) -> [AccessorDeclSyntax] {
4343
let patternBindings = bindings.compactMap { binding in
44-
binding.as(PatternBindingSyntax.self)
44+
binding
4545
}
4646
let accessors: [AccessorDeclListSyntax.Element] = patternBindings.compactMap { patternBinding in
4747
switch patternBinding.accessorBlock?.accessors {
@@ -52,14 +52,7 @@ extension VariableDeclSyntax {
5252
}
5353
}.flatMap { $0 }
5454
return accessors.compactMap { accessor in
55-
guard let decl = accessor.as(AccessorDeclSyntax.self) else {
56-
return nil
57-
}
58-
if predicate(decl.accessorSpecifier.tokenKind) {
59-
return decl
60-
} else {
61-
return nil
62-
}
55+
predicate(accessor.accessorSpecifier.tokenKind) ? accessor : nil
6356
}
6457
}
6558

@@ -215,7 +208,7 @@ extension DeclGroupSyntax {
215208
var memberFunctionStandins: [FunctionDeclSyntax.SignatureStandin] {
216209
var standins = [FunctionDeclSyntax.SignatureStandin]()
217210
for member in memberBlock.members {
218-
if let function = member.as(MemberBlockItemSyntax.self)?.decl.as(FunctionDeclSyntax.self) {
211+
if let function = member.decl.as(FunctionDeclSyntax.self) {
219212
standins.append(function.signatureStandin)
220213
}
221214
}
@@ -224,7 +217,7 @@ extension DeclGroupSyntax {
224217

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

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

247240
var definedVariables: [VariableDeclSyntax] {
248241
memberBlock.members.compactMap { member in
249-
if let variableDecl = member.as(MemberBlockItemSyntax.self)?.decl.as(VariableDeclSyntax.self)
242+
if let variableDecl = member.decl.as(VariableDeclSyntax.self)
250243
{
251244
return variableDecl
252245
}

Sources/PerceptionMacros/PerceptibleMacro.swift

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ public struct PerceptibleMacro {
4848
return
4949
"""
5050
internal nonisolated func access<Member>(
51-
keyPath: KeyPath<\(perceptibleType), Member>,
52-
file: StaticString = #file,
53-
line: UInt = #line
51+
keyPath: KeyPath<\(perceptibleType), Member>,
52+
file: StaticString = #file,
53+
line: UInt = #line
5454
) {
55-
\(raw: registrarVariableName).access(self, keyPath: keyPath, file: file, line: line)
55+
\(raw: registrarVariableName).access(self, keyPath: keyPath, file: file, line: line)
5656
}
5757
"""
5858
}
@@ -61,10 +61,10 @@ public struct PerceptibleMacro {
6161
return
6262
"""
6363
internal nonisolated func withMutation<Member, MutationResult>(
64-
keyPath: KeyPath<\(perceptibleType), Member>,
65-
_ mutation: () throws -> MutationResult
64+
keyPath: KeyPath<\(perceptibleType), Member>,
65+
_ mutation: () throws -> MutationResult
6666
) rethrows -> MutationResult {
67-
try \(raw: registrarVariableName).withMutation(of: self, keyPath: keyPath, mutation)
67+
try \(raw: registrarVariableName).withMutation(of: self, keyPath: keyPath, mutation)
6868
}
6969
"""
7070
}
@@ -218,7 +218,7 @@ extension PerceptibleMacro: MemberMacro {
218218
return []
219219
}
220220

221-
let perceptibleType = identified.name
221+
let perceptibleType = identified.name.trimmed
222222

223223
if declaration.isEnum {
224224
// enumerations cannot store properties
@@ -333,7 +333,7 @@ public struct PerceptionTrackedMacro: AccessorMacro {
333333
) throws -> [AccessorDeclSyntax] {
334334
guard let property = declaration.as(VariableDeclSyntax.self),
335335
property.isValidForPerception,
336-
let identifier = property.identifier
336+
let identifier = property.identifier?.trimmed
337337
else {
338338
return []
339339
}
@@ -346,24 +346,24 @@ public struct PerceptionTrackedMacro: AccessorMacro {
346346
"""
347347
@storageRestrictions(initializes: _\(identifier))
348348
init(initialValue) {
349-
_\(identifier) = initialValue
349+
_\(identifier) = initialValue
350350
}
351351
"""
352352

353353
let getAccessor: AccessorDeclSyntax =
354354
"""
355355
get {
356-
access(keyPath: \\.\(identifier))
357-
return _\(identifier)
356+
access(keyPath: \\.\(identifier))
357+
return _\(identifier)
358358
}
359359
"""
360360

361361
let setAccessor: AccessorDeclSyntax =
362362
"""
363363
set {
364-
withMutation(keyPath: \\.\(identifier)) {
365-
_\(identifier) = newValue
366-
}
364+
withMutation(keyPath: \\.\(identifier)) {
365+
_\(identifier) = newValue
366+
}
367367
}
368368
"""
369369

Tests/PerceptionMacrosTests/PerceptionMacrosTests.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
class PerceptionMacroTests: XCTestCase {
77
override func invokeTest() {
88
withMacroTesting(
9-
//isRecording: true,
9+
// isRecording: true,
1010
macros: [
1111
PerceptibleMacro.self,
1212
PerceptionTrackedMacro.self,
@@ -28,34 +28,34 @@
2828
} expansion: {
2929
#"""
3030
class Feature {
31-
var count = 0 {
32-
@storageRestrictions(initializes: _count )
31+
var count {
32+
@storageRestrictions(initializes: _count)
3333
init(initialValue) {
34-
_count = initialValue
34+
_count = initialValue
3535
}
3636
get {
37-
access(keyPath: \.count )
37+
access(keyPath: \.count)
3838
return _count
3939
}
4040
set {
41-
withMutation(keyPath: \.count ) {
42-
_count = newValue
41+
withMutation(keyPath: \.count) {
42+
_count = newValue
4343
}
4444
}
4545
}
4646
4747
private let _$perceptionRegistrar = Perception.PerceptionRegistrar()
4848
4949
internal nonisolated func access<Member>(
50-
keyPath: KeyPath<Feature , Member>,
51-
file: StaticString = #file,
52-
line: UInt = #line
50+
keyPath: KeyPath<Feature, Member>,
51+
file: StaticString = #file,
52+
line: UInt = #line
5353
) {
5454
_$perceptionRegistrar.access(self, keyPath: keyPath, file: file, line: line)
5555
}
5656
5757
internal nonisolated func withMutation<Member, MutationResult>(
58-
keyPath: KeyPath<Feature , Member>,
58+
keyPath: KeyPath<Feature, Member>,
5959
_ mutation: () throws -> MutationResult
6060
) rethrows -> MutationResult {
6161
try _$perceptionRegistrar.withMutation(of: self, keyPath: keyPath, mutation)

0 commit comments

Comments
 (0)