Skip to content

Support SwiftSyntax v601 #93

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

Merged
merged 2 commits into from
Jun 23, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
28 changes: 14 additions & 14 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ let package = Package(
dependencies: [
.package(url: "https://github.com/maplibre/maplibre-gl-native-distribution.git", from: "6.10.0"),
// Macros
.package(url: "https://github.com/swiftlang/swift-syntax.git", "509.0.0" ..< "601.0.0"),
.package(url: "https://github.com/swiftlang/swift-syntax.git", "509.0.0" ..< "602.0.0"),
// Testing
.package(url: "https://github.com/Kolos65/Mockable.git", from: "0.3.1"),
.package(url: "https://github.com/pointfreeco/swift-snapshot-testing", from: "1.18.3"),
Expand Down
14 changes: 14 additions & 0 deletions Sources/MapLibreSwiftMacrosImpl/StyleExpressionMacro.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,21 @@
}
}

#if canImport(SwiftSyntax601)
// This provides compatibility for the new SwiftSyntax API, returning an empty result if the argument has
// been parsed as an expression.
private func generateStyleProperty(for attributes: AttributeSyntax, valueType: GenericArgumentSyntax.Argument,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem to be used anywhere; am I missing something?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it might not be straight forward, but this is what's going on:

  • SwiftSyntax 601 introduces a new nested GenericArgument.Argument type because the parser can now parse types and expressions (experimental).
  • So in 601, GenericArgumentSyntax.argument doesn't give you a TypeSyntax as before, but this new enum.
  • This code provides an override (conditional on SwiftSyntax601) to generateStyleProperty that takes this new Argument type and unwraps it to send to the existing generateStyleProperty function.
  • This means you don't need any changes at the call site, but in 601 it is actually calling this override.

Does that make sense?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, wow 😅 Yeah, I think that makes sense. Thanks! I'll get the swiftformat stuff cleaned up and we can get this merged.

isRawRepresentable: Bool) throws -> [DeclSyntax] {
switch valueType {
case .type(let type):
return try generateStyleProperty(for: attributes, valueType: type, isRawRepresentable: isRawRepresentable)
default:
return []
}
}
#endif

public struct MLNStylePropertyMacro: MemberMacro {

Check warning on line 110 in Sources/MapLibreSwiftMacrosImpl/StyleExpressionMacro.swift

View workflow job for this annotation

GitHub Actions / platform=iOS Simulator,name=iPhone 16,OS=18.1

deprecated default implementation is used to satisfy static method 'expansion(of:providingMembersOf:conformingTo:in:)' required by protocol 'MemberMacro': `MemberMacro` conformance should implement the `expansion` function that takes a `conformingTo` parameter

Check warning on line 110 in Sources/MapLibreSwiftMacrosImpl/StyleExpressionMacro.swift

View workflow job for this annotation

GitHub Actions / platform=iOS Simulator,name=iPhone 16,OS=18.1

deprecated default implementation is used to satisfy static method 'expansion(of:providingMembersOf:conformingTo:in:)' required by protocol 'MemberMacro': `MemberMacro` conformance should implement the `expansion` function that takes a `conformingTo` parameter

Check warning on line 110 in Sources/MapLibreSwiftMacrosImpl/StyleExpressionMacro.swift

View workflow job for this annotation

GitHub Actions / platform=iOS Simulator,name=iPhone 16,OS=18.1

deprecated default implementation is used to satisfy static method 'expansion(of:providingMembersOf:conformingTo:in:)' required by protocol 'MemberMacro': `MemberMacro` conformance should implement the `expansion` function that takes a `conformingTo` parameter

Check warning on line 110 in Sources/MapLibreSwiftMacrosImpl/StyleExpressionMacro.swift

View workflow job for this annotation

GitHub Actions / platform=iOS Simulator,name=iPhone 16,OS=18.1

deprecated default implementation is used to satisfy static method 'expansion(of:providingMembersOf:conformingTo:in:)' required by protocol 'MemberMacro': `MemberMacro` conformance should implement the `expansion` function that takes a `conformingTo` parameter
public static func expansion(
of node: AttributeSyntax,
providingMembersOf _: some DeclGroupSyntax,
Expand All @@ -112,7 +126,7 @@
}
}

public struct MLNRawRepresentableStylePropertyMacro: MemberMacro {

Check warning on line 129 in Sources/MapLibreSwiftMacrosImpl/StyleExpressionMacro.swift

View workflow job for this annotation

GitHub Actions / platform=iOS Simulator,name=iPhone 16,OS=18.1

deprecated default implementation is used to satisfy static method 'expansion(of:providingMembersOf:conformingTo:in:)' required by protocol 'MemberMacro': `MemberMacro` conformance should implement the `expansion` function that takes a `conformingTo` parameter

Check warning on line 129 in Sources/MapLibreSwiftMacrosImpl/StyleExpressionMacro.swift

View workflow job for this annotation

GitHub Actions / platform=iOS Simulator,name=iPhone 16,OS=18.1

deprecated default implementation is used to satisfy static method 'expansion(of:providingMembersOf:conformingTo:in:)' required by protocol 'MemberMacro': `MemberMacro` conformance should implement the `expansion` function that takes a `conformingTo` parameter

Check warning on line 129 in Sources/MapLibreSwiftMacrosImpl/StyleExpressionMacro.swift

View workflow job for this annotation

GitHub Actions / platform=iOS Simulator,name=iPhone 16,OS=18.1

deprecated default implementation is used to satisfy static method 'expansion(of:providingMembersOf:conformingTo:in:)' required by protocol 'MemberMacro': `MemberMacro` conformance should implement the `expansion` function that takes a `conformingTo` parameter

Check warning on line 129 in Sources/MapLibreSwiftMacrosImpl/StyleExpressionMacro.swift

View workflow job for this annotation

GitHub Actions / platform=iOS Simulator,name=iPhone 16,OS=18.1

deprecated default implementation is used to satisfy static method 'expansion(of:providingMembersOf:conformingTo:in:)' required by protocol 'MemberMacro': `MemberMacro` conformance should implement the `expansion` function that takes a `conformingTo` parameter
public static func expansion(
of node: AttributeSyntax,
providingMembersOf _: some DeclGroupSyntax,
Expand Down
Loading