GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — BridgeJS: Introduce extended macro and namespace information extracti… · t089/JavaScriptKit@1561681

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • Plugins/BridgeJS
    • Sources
      • BridgeJSCore
        • ExportSwift.swift
      • BridgeJSLink
        • BridgeJSLink.swift
      • BridgeJSSkeleton
        • BridgeJSSkeleton.swift
    • Tests/BridgeJSToolTests
      • Inputs
        • Namespaces.swift
      • __Snapshots__
        • BridgeJSLinkTests
          • Namespaces.Export.d.ts
          • Namespaces.Export.js
        • ExportSwiftTests
          • Namespaces.json
          • Namespaces.swift
  • Sources/JavaScriptKit
    • Macros.swift
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift‎

Copy file name to clipboardExpand all lines: Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift
+29-6Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,13 @@ class ExportSwift {
123123
}
124124

125125
private func visitFunction(node: FunctionDeclSyntax) -> ExportedFunction? {
126-
guard node.attributes.hasJSAttribute() else {
126+
guard let jsAttribute = node.attributes.firstJSAttribute else {
127127
return nil
128128
}
129+
129130
let name = node.name.text
131+
let namespace = extractNamespace(from: jsAttribute)
132+
130133
var parameters: [Parameter] = []
131134
for param in node.signature.parameterClause.parameters {
132135
guard let type = self.parent.lookupType(for: param.type) else {
@@ -165,7 +168,8 @@ class ExportSwift {
165168
abiName: abiName,
166169
parameters: parameters,
167170
returnType: returnType,
168-
effects: effects
171+
effects: effects,
172+
namespace: namespace
169173
)
170174
}
171175

@@ -192,6 +196,17 @@ class ExportSwift {
192196
}
193197
return Effects(isAsync: isAsync, isThrows: isThrows)
194198
}
199+
200+
private func extractNamespace(
201+
from jsAttribute: AttributeSyntax
202+
) -> [String]? {
203+
guard let arguments = jsAttribute.arguments?.as(LabeledExprListSyntax.self),
204+
let firstArg = arguments.first?.expression.as(StringLiteralExprSyntax.self),
205+
let namespaceString = firstArg.segments.first?.as(StringSegmentSyntax.self)?.content.text else {
206+
return nil
207+
}
208+
return namespaceString.split(separator: ".").map(String.init)
209+
}
195210

196211
override func visit(_ node: InitializerDeclSyntax) -> SyntaxVisitorContinueKind {
197212
guard node.attributes.hasJSAttribute() else { return .skipChildren }
@@ -225,13 +240,17 @@ class ExportSwift {
225240

226241
override func visit(_ node: ClassDeclSyntax) -> SyntaxVisitorContinueKind {
227242
let name = node.name.text
243+
228244
stateStack.push(state: .classBody(name: name))
229245

230-
guard node.attributes.hasJSAttribute() else { return .skipChildren }
246+
guard let jsAttribute = node.attributes.firstJSAttribute else { return .skipChildren }
247+
248+
let namespace = extractNamespace(from: jsAttribute)
231249
exportedClassByName[name] = ExportedClass(
232250
name: name,
233251
constructor: nil,
234-
methods: []
252+
methods: [],
253+
namespace: namespace
235254
)
236255
exportedClassNames.append(name)
237256
return .visitChildren
@@ -635,9 +654,13 @@ class ExportSwift {
635654

636655
extension AttributeListSyntax {
637656
fileprivate func hasJSAttribute() -> Bool {
638-
return first(where: {
657+
firstJSAttribute != nil
658+
}
659+
660+
fileprivate var firstJSAttribute: AttributeSyntax? {
661+
first(where: {
639662
$0.as(AttributeSyntax.self)?.attributeName.trimmedDescription == "JS"
640-
}) != nil
663+
})?.as(AttributeSyntax.self)
641664
}
642665
}
643666

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.