@@ -27,6 +27,7 @@ public struct FlagMacro {
2727 let description : ExprSyntax
2828 let display : ExprSyntax ?
2929 let type : TypeSyntax
30+ let scopes : DeclModifierListSyntax
3031
3132
3233 // MARK: - Initialisation
@@ -54,6 +55,7 @@ public struct FlagMacro {
5455 else {
5556 throw DiagnosticsError ( diagnostics: [ . init( node: node, message: Diagnostic . onlySimpleVariableSupported) ] )
5657 }
58+ self . scopes = property. modifiers. scopeSyntax
5759
5860 var defaultExprSyntax : ExprSyntax
5961 if let defaultExpr = arguments [ label: " default " ] ? . expression ?? binding. initializer? . value {
@@ -100,6 +102,22 @@ public struct FlagMacro {
100102 """
101103 }
102104
105+ func makeWigwagDeclaration( ) throws -> VariableDeclSyntax {
106+ try VariableDeclSyntax ( " var $ \( raw: propertyName) : FlagWigwag< \( type) > " ) {
107+ """
108+ FlagWigwag(
109+ keyPath: \( key) ,
110+ name: \( name ?? " nil " ) ,
111+ defaultValue: \( defaultValue) ,
112+ description: \( description) ,
113+ displayOption: \( display ?? " .default " ) ,
114+ lookup: _flagLookup
115+ )
116+ """
117+ }
118+ . with ( \. modifiers, scopes)
119+ }
120+
103121}
104122
105123private extension AttributeSyntax . Arguments {
@@ -153,19 +171,8 @@ extension FlagMacro: PeerMacro {
153171 ) throws -> [ DeclSyntax ] {
154172 do {
155173 let macro = try FlagMacro ( node: node, declaration: declaration, context: context)
156- return [
157- """
158- var $ \( raw: macro. propertyName) : FlagWigwag< \( macro. type) > {
159- FlagWigwag(
160- keyPath: \( macro. key) ,
161- name: \( macro. name ?? " nil " ) ,
162- defaultValue: \( macro. defaultValue) ,
163- description: \( macro. description) ,
164- displayOption: \( macro. display ?? " .default " ) ,
165- lookup: _flagLookup
166- )
167- }
168- """ ,
174+ return try [
175+ DeclSyntax ( macro. makeWigwagDeclaration ( ) ) ,
169176 ]
170177 } catch {
171178 return [ ]
0 commit comments