Skip to content

Commit c20cc50

Browse files
committed
fix: Make NavigationRoot internal only
Allows multiple navigation roots declarations in project (one per module), also prevents accidentally manipulating wrong navigation root from a different module.
1 parent 935c1d5 commit c20cc50

File tree

4 files changed

+4
-4
lines changed

4 files changed

+4
-4
lines changed

Sources/GoodCoordinator/Macros.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import Foundation
1212
public macro Navigable() = #externalMacro(module: "GoodCoordinatorMacros", type: "Navigable")
1313

1414
@attached(member, names: named(__navigationPath))
15-
@attached(peer, names: named(__global_rootNavigationPath))
15+
@attached(peer, names: named(__module_rootNavigationPath))
1616
public macro NavigationRoot() = #externalMacro(module: "GoodCoordinatorMacros", type: "NavigationRoot")
1717

1818
@freestanding(expression)

Sources/GoodCoordinatorMacros/Macros/NavigationRoot.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public struct NavigationRoot: MemberMacro, PeerMacro {
3131
}
3232

3333
let funcBody = "return \(navigationRootDeclarationName).__navigationPath"
34-
let navigationRootSyntax = DeclSyntax("@MainActor public func __global_rootNavigationPath() -> Router { \(raw: funcBody) }")
34+
let navigationRootSyntax = DeclSyntax("@MainActor internal func __module_rootNavigationPath() -> Router { \(raw: funcBody) }")
3535

3636

3737
return [navigationRootSyntax]

Sources/GoodCoordinatorMacros/Macros/NavigationRouter.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public struct NavigationRouter: ExpressionMacro {
1515
of node: some FreestandingMacroExpansionSyntax,
1616
in context: some MacroExpansionContext
1717
) throws -> ExprSyntax {
18-
return ExprSyntax("__global_rootNavigationPath()")
18+
return ExprSyntax("__module_rootNavigationPath()")
1919
}
2020

2121
}

Tests/GoodCoordinatorMacrosTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ final class MacroCollectionTests: XCTestCase {
136136
@MainActor static let __navigationPath: Router = Router()
137137
}
138138
139-
@MainActor public func __global_rootNavigationPath() -> Router {
139+
@MainActor internal func __module_rootNavigationPath() -> Router {
140140
return MainWindow.__navigationPath
141141
}
142142
"""

0 commit comments

Comments
 (0)