|
| 1 | +import SwiftSyntax |
| 2 | +import SwiftSyntaxBuilder |
| 3 | +import SwiftSyntaxMacros |
| 4 | + |
| 5 | +enum JSImportFunctionMacro {} |
| 6 | + |
| 7 | +extension JSImportFunctionMacro: BodyMacro { |
| 8 | + package static func expansion( |
| 9 | + of node: AttributeSyntax, |
| 10 | + providingBodyFor declaration: some DeclSyntaxProtocol & WithOptionalCodeBlockSyntax, |
| 11 | + in context: some MacroExpansionContext |
| 12 | + ) throws -> [CodeBlockItemSyntax] { |
| 13 | + return [ |
| 14 | + "fatalError(\"Not implemented\")" |
| 15 | + ] |
| 16 | + } |
| 17 | +} |
| 18 | + |
| 19 | +enum JSImportVariableMacro {} |
| 20 | + |
| 21 | +extension JSImportVariableMacro: AccessorMacro { |
| 22 | + package static func expansion( |
| 23 | + of node: AttributeSyntax, |
| 24 | + providingAccessorsOf declaration: some DeclSyntaxProtocol, |
| 25 | + in context: some MacroExpansionContext |
| 26 | +) throws -> [AccessorDeclSyntax] { |
| 27 | + return [ |
| 28 | + AccessorDeclSyntax( |
| 29 | + accessorSpecifier: .keyword(.get), |
| 30 | + effectSpecifiers: AccessorEffectSpecifiersSyntax( |
| 31 | + asyncSpecifier: nil, |
| 32 | + throwsClause: nil |
| 33 | + ), |
| 34 | + body: CodeBlockSyntax { |
| 35 | + "fatalError(\"Not implemented\")" |
| 36 | + } |
| 37 | + ) |
| 38 | + ] |
| 39 | + } |
| 40 | +} |
| 41 | + |
| 42 | +extension JSImportFunctionMacro: AccessorMacro { |
| 43 | + package static func expansion( |
| 44 | + of node: AttributeSyntax, |
| 45 | + providingAccessorsOf declaration: some DeclSyntaxProtocol, |
| 46 | + in context: some MacroExpansionContext |
| 47 | +) throws -> [AccessorDeclSyntax] { |
| 48 | + return [ |
| 49 | + AccessorDeclSyntax( |
| 50 | + accessorSpecifier: .keyword(.get), |
| 51 | + effectSpecifiers: AccessorEffectSpecifiersSyntax( |
| 52 | + asyncSpecifier: nil, |
| 53 | + throwsClause: nil |
| 54 | + ), |
| 55 | + body: CodeBlockSyntax { |
| 56 | + "fatalError(\"Not implemented\")" |
| 57 | + } |
| 58 | + ) |
| 59 | + ] |
| 60 | + } |
| 61 | +} |
| 62 | + |
| 63 | +extension JSImportFunctionMacro: PeerMacro { |
| 64 | + package static func expansion( |
| 65 | + of node: AttributeSyntax, |
| 66 | + providingPeersOf declaration: some DeclSyntaxProtocol, |
| 67 | + in context: some MacroExpansionContext |
| 68 | +) throws -> [DeclSyntax] { |
| 69 | + let functionDecl: DeclSyntax = """ |
| 70 | + func \(raw: context.makeUniqueName("jsImportFunction"))() -> UInt32 { |
| 71 | + fatalError("Not implemented") |
| 72 | + } |
| 73 | + """ |
| 74 | + return [functionDecl] |
| 75 | + } |
| 76 | +} |
0 commit comments