@@ -1856,7 +1856,6 @@ private final class ImportSwiftMacrosAPICollector: SyntaxAnyVisitor {
18561856 private let inputFilePath : String
18571857 private var jsClassNames : Set < String >
18581858 private let parent : SwiftToSkeleton
1859-
18601859 // MARK: - State Management
18611860
18621861 enum State {
@@ -1876,6 +1875,7 @@ private final class ImportSwiftMacrosAPICollector: SyntaxAnyVisitor {
18761875 let from : JSImportFrom ?
18771876 var constructor : ImportedConstructorSkeleton ?
18781877 var methods : [ ImportedFunctionSkeleton ]
1878+ var staticMethods : [ ImportedFunctionSkeleton ]
18791879 var getters : [ ImportedGetterSkeleton ]
18801880 var setters : [ ImportedSetterSkeleton ]
18811881 }
@@ -2094,6 +2094,7 @@ private final class ImportSwiftMacrosAPICollector: SyntaxAnyVisitor {
20942094 from: nil ,
20952095 constructor: nil ,
20962096 methods: [ ] ,
2097+ staticMethods: [ ] ,
20972098 getters: [ ] ,
20982099 setters: [ ]
20992100 )
@@ -2107,6 +2108,7 @@ private final class ImportSwiftMacrosAPICollector: SyntaxAnyVisitor {
21072108 from: from,
21082109 constructor: nil ,
21092110 methods: [ ] ,
2111+ staticMethods: [ ] ,
21102112 getters: [ ] ,
21112113 setters: [ ]
21122114 )
@@ -2121,6 +2123,7 @@ private final class ImportSwiftMacrosAPICollector: SyntaxAnyVisitor {
21212123 from: type. from,
21222124 constructor: type. constructor,
21232125 methods: type. methods,
2126+ staticMethods: type. staticMethods,
21242127 getters: type. getters,
21252128 setters: type. setters,
21262129 documentation: nil
@@ -2165,12 +2168,6 @@ private final class ImportSwiftMacrosAPICollector: SyntaxAnyVisitor {
21652168
21662169 // MARK: - Visitor Methods
21672170
2168- override func visit( _ node: ExtensionDeclSyntax ) -> SyntaxVisitorContinueKind {
2169- let typeName = node. extendedType. trimmedDescription
2170- collectStaticMembers ( in: node. memberBlock. members, typeName: typeName)
2171- return . skipChildren
2172- }
2173-
21742171 override func visit( _ node: FunctionDeclSyntax ) -> SyntaxVisitorContinueKind {
21752172 switch state {
21762173 case . topLevel:
@@ -2191,7 +2188,7 @@ private final class ImportSwiftMacrosAPICollector: SyntaxAnyVisitor {
21912188
21922189 private func handleTopLevelFunction( _ node: FunctionDeclSyntax ) -> SyntaxVisitorContinueKind {
21932190 if let jsFunction = AttributeChecker . firstJSFunctionAttribute ( node. attributes) ,
2194- let function = parseFunction ( jsFunction, node, enclosingTypeName : nil , isStaticMember : true )
2191+ let function = parseFunction ( jsFunction, node)
21952192 {
21962193 importedFunctions. append ( function)
21972194 return . skipChildren
@@ -2216,13 +2213,11 @@ private final class ImportSwiftMacrosAPICollector: SyntaxAnyVisitor {
22162213 type: inout CurrentType
22172214 ) -> Bool {
22182215 if let jsFunction = AttributeChecker . firstJSFunctionAttribute ( node. attributes) {
2219- if isStaticMember {
2220- parseFunction ( jsFunction, node, enclosingTypeName: typeName, isStaticMember: true ) . map {
2221- importedFunctions. append ( $0)
2222- }
2223- } else {
2224- parseFunction ( jsFunction, node, enclosingTypeName: typeName, isStaticMember: false ) . map {
2225- type. methods. append ( $0)
2216+ if let method = parseFunction ( jsFunction, node) {
2217+ if isStaticMember {
2218+ type. staticMethods. append ( method)
2219+ } else {
2220+ type. methods. append ( method)
22262221 }
22272222 }
22282223 return true
@@ -2313,38 +2308,6 @@ private final class ImportSwiftMacrosAPICollector: SyntaxAnyVisitor {
23132308 }
23142309 }
23152310
2316- // MARK: - Member Collection
2317-
2318- private func collectStaticMembers( in members: MemberBlockItemListSyntax , typeName: String ) {
2319- for member in members {
2320- if let function = member. decl. as ( FunctionDeclSyntax . self) {
2321- if let jsFunction = AttributeChecker . firstJSFunctionAttribute ( function. attributes) ,
2322- let parsed = parseFunction ( jsFunction, function, enclosingTypeName: typeName, isStaticMember: true )
2323- {
2324- importedFunctions. append ( parsed)
2325- } else if AttributeChecker . hasJSSetterAttribute ( function. attributes) {
2326- errors. append (
2327- DiagnosticError (
2328- node: function,
2329- message:
2330- " @JSSetter is not supported for static members. Use it only for instance members in @JSClass types. "
2331- )
2332- )
2333- }
2334- } else if let variable = member. decl. as ( VariableDeclSyntax . self) ,
2335- AttributeChecker . hasJSGetterAttribute ( variable. attributes)
2336- {
2337- errors. append (
2338- DiagnosticError (
2339- node: variable,
2340- message:
2341- " @JSGetter is not supported for static members. Use it only for instance members in @JSClass types. "
2342- )
2343- )
2344- }
2345- }
2346- }
2347-
23482311 // MARK: - Parsing Methods
23492312
23502313 private func parseConstructor(
@@ -2365,8 +2328,6 @@ private final class ImportSwiftMacrosAPICollector: SyntaxAnyVisitor {
23652328 private func parseFunction(
23662329 _ jsFunction: AttributeSyntax ,
23672330 _ node: FunctionDeclSyntax ,
2368- enclosingTypeName: String ? ,
2369- isStaticMember: Bool
23702331 ) -> ImportedFunctionSkeleton ? {
23712332 guard validateEffects ( node. signature. effectSpecifiers, node: node, attributeName: " JSFunction " ) != nil
23722333 else {
@@ -2376,12 +2337,7 @@ private final class ImportSwiftMacrosAPICollector: SyntaxAnyVisitor {
23762337 let baseName = SwiftToSkeleton . normalizeIdentifier ( node. name. text)
23772338 let jsName = AttributeChecker . extractJSName ( from: jsFunction)
23782339 let from = AttributeChecker . extractJSImportFrom ( from: jsFunction)
2379- let name : String
2380- if isStaticMember, let enclosingTypeName {
2381- name = " \( enclosingTypeName) _ \( baseName) "
2382- } else {
2383- name = baseName
2384- }
2340+ let name = baseName
23852341
23862342 let parameters = parseParameters ( from: node. signature. parameterClause)
23872343 let returnType : BridgeType
0 commit comments