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

Propagate @ViewAction macro availability #2785

Merged
merged 1 commit into from
Feb 8, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion Sources/ComposableArchitectureMacros/ViewActionMacro.swift
Expand Up @@ -68,7 +68,8 @@ public struct ViewActionMacro: ExtensionMacro {

let ext: DeclSyntax =
"""
extension \(type.trimmed): ComposableArchitecture.ViewActionSending {}
\(declaration.attributes.availability)extension \(type.trimmed): \
ComposableArchitecture.ViewActionSending {}
"""
return [ext.cast(ExtensionDeclSyntax.self)]
}
Expand Down
28 changes: 28 additions & 0 deletions Tests/ComposableArchitectureMacrosTests/ViewActionMacroTests.swift
Expand Up @@ -438,5 +438,33 @@
"""
}
}

func testAvailability() {
assertMacro {
"""
@available(iOS 17, macOS 14, tvOS 17, visionOS 1, watchOS 10, *)
@ViewAction(for: Feature.self)
struct FeatureView: View {
@State var store: StoreOf<Feature>
var body: some View {
EmptyView()
}
}
"""
} expansion: {
"""
@available(iOS 17, macOS 14, tvOS 17, visionOS 1, watchOS 10, *)
struct FeatureView: View {
@State var store: StoreOf<Feature>
var body: some View {
EmptyView()
}
}

@available(iOS 17, macOS 14, tvOS 17, visionOS 1, watchOS 10, *) extension FeatureView: ComposableArchitecture.ViewActionSending {
}
"""
}
}
}
#endif