Skip to content

Commit 6d49ec7

Browse files
BridgeJS: Fix PackageToJS build
1 parent 1a1e58d commit 6d49ec7

File tree

27 files changed

+101
-101
lines changed

27 files changed

+101
-101
lines changed

Benchmarks/Sources/Generated/BridgeJS.Macros.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// To update this file, just rebuild your project or run
55
// `swift package bridge-js`.
66

7-
import JavaScriptKit
7+
@_spi(Experimental) import JavaScriptKit
88

99
@JSFunction func benchmarkHelperNoop() throws (JSException) -> Void
1010

Benchmarks/Sources/Generated/BridgeJS.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// To update this file, just rebuild your project or run
66
// `swift package bridge-js`.
77

8-
@_spi(BridgeJS) @_spi(Experimental) import JavaScriptKit
8+
@_spi(BridgeJS) import JavaScriptKit
99

1010
extension APIResult: _BridgedSwiftAssociatedValueEnum {
1111
private static func _bridgeJSLiftFromCaseId(_ caseId: Int32) -> APIResult {

Examples/PlayBridgeJS/Sources/PlayBridgeJS/Generated/BridgeJS.Macros.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// To update this file, just rebuild your project or run
55
// `swift package bridge-js`.
66

7-
import JavaScriptKit
7+
@_spi(Experimental) import JavaScriptKit
88

99
@JSFunction func createTS2Swift() throws (JSException) -> TS2Swift
1010

Examples/PlayBridgeJS/Sources/PlayBridgeJS/Generated/BridgeJS.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// To update this file, just rebuild your project or run
66
// `swift package bridge-js`.
77

8-
@_spi(BridgeJS) @_spi(Experimental) import JavaScriptKit
8+
@_spi(BridgeJS) import JavaScriptKit
99

1010
@_expose(wasm, "bjs_PlayBridgeJS_init")
1111
@_cdecl("bjs_PlayBridgeJS_init")

Plugins/BridgeJS/Sources/BridgeJSCore/ImportSwiftMacros.swift

Lines changed: 44 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -155,16 +155,15 @@ public final class ImportSwiftMacros {
155155
}
156156
}
157157

158-
159158
/// Extracts the jsName argument value from a @JSSetter attribute, if present.
160159
static func extractJSName(from attribute: AttributeSyntax) -> String? {
161160
guard let arguments = attribute.arguments?.as(LabeledExprListSyntax.self) else {
162161
return nil
163162
}
164163
for argument in arguments {
165164
if argument.label?.text == "jsName",
166-
let stringLiteral = argument.expression.as(StringLiteralExprSyntax.self),
167-
let segment = stringLiteral.segments.first?.as(StringSegmentSyntax.self)
165+
let stringLiteral = argument.expression.as(StringLiteralExprSyntax.self),
166+
let segment = stringLiteral.segments.first?.as(StringSegmentSyntax.self)
168167
{
169168
return segment.content.text
170169
}
@@ -217,7 +216,8 @@ public final class ImportSwiftMacros {
217216
jsSetter: AttributeSyntax,
218217
enclosingTypeName: String?
219218
) -> SetterValidationResult? {
220-
guard let effects = validateEffects(node.signature.effectSpecifiers, node: node, attributeName: "JSSetter") else {
219+
guard let effects = validateEffects(node.signature.effectSpecifiers, node: node, attributeName: "JSSetter")
220+
else {
221221
return nil
222222
}
223223

@@ -270,7 +270,8 @@ public final class ImportSwiftMacros {
270270
return (propertyName: propertyName, functionBaseName: functionBaseName)
271271
}
272272

273-
let rawFunctionName = functionName.hasPrefix("`") && functionName.hasSuffix("`") && functionName.count > 2
273+
let rawFunctionName =
274+
functionName.hasPrefix("`") && functionName.hasSuffix("`") && functionName.count > 2
274275
? String(functionName.dropFirst().dropLast())
275276
: functionName
276277

@@ -367,7 +368,8 @@ public final class ImportSwiftMacros {
367368

368369
private func handleTopLevelFunction(_ node: FunctionDeclSyntax) -> SyntaxVisitorContinueKind {
369370
if AttributeChecker.hasJSFunctionAttribute(node.attributes),
370-
let function = parseFunction(node, enclosingTypeName: nil, isStaticMember: true) {
371+
let function = parseFunction(node, enclosingTypeName: nil, isStaticMember: true)
372+
{
371373
importedFunctions.append(function)
372374
return .skipChildren
373375
}
@@ -392,9 +394,13 @@ public final class ImportSwiftMacros {
392394
) -> Bool {
393395
if AttributeChecker.hasJSFunctionAttribute(node.attributes) {
394396
if isStaticMember {
395-
parseFunction(node, enclosingTypeName: typeName, isStaticMember: true).map { importedFunctions.append($0) }
397+
parseFunction(node, enclosingTypeName: typeName, isStaticMember: true).map {
398+
importedFunctions.append($0)
399+
}
396400
} else {
397-
parseFunction(node, enclosingTypeName: typeName, isStaticMember: false).map { type.methods.append($0) }
401+
parseFunction(node, enclosingTypeName: typeName, isStaticMember: false).map {
402+
type.methods.append($0)
403+
}
398404
}
399405
return true
400406
}
@@ -404,11 +410,13 @@ public final class ImportSwiftMacros {
404410
errors.append(
405411
DiagnosticError(
406412
node: node,
407-
message: "@JSSetter is not supported for static members. Use it only for instance members in @JSClass types."
413+
message:
414+
"@JSSetter is not supported for static members. Use it only for instance members in @JSClass types."
408415
)
409416
)
410417
} else if let jsSetter = AttributeChecker.firstJSSetterAttribute(node.attributes),
411-
let setter = parseSetterSkeleton(jsSetter, node, enclosingTypeName: typeName) {
418+
let setter = parseSetterSkeleton(jsSetter, node, enclosingTypeName: typeName)
419+
{
412420
type.setters.append(setter)
413421
}
414422
return true
@@ -440,7 +448,8 @@ public final class ImportSwiftMacros {
440448
errors.append(
441449
DiagnosticError(
442450
node: node,
443-
message: "@JSGetter is not supported for static members. Use it only for instance members in @JSClass types."
451+
message:
452+
"@JSGetter is not supported for static members. Use it only for instance members in @JSClass types."
444453
)
445454
)
446455
} else if let getter = parseGetterSkeleton(node, enclosingTypeName: typeName) {
@@ -481,29 +490,32 @@ public final class ImportSwiftMacros {
481490
}
482491
}
483492

484-
485493
// MARK: - Member Collection
486494

487495
private func collectStaticMembers(in members: MemberBlockItemListSyntax, typeName: String) {
488496
for member in members {
489497
if let function = member.decl.as(FunctionDeclSyntax.self) {
490498
if AttributeChecker.hasJSFunctionAttribute(function.attributes),
491-
let parsed = parseFunction(function, enclosingTypeName: typeName, isStaticMember: true) {
499+
let parsed = parseFunction(function, enclosingTypeName: typeName, isStaticMember: true)
500+
{
492501
importedFunctions.append(parsed)
493502
} else if AttributeChecker.hasJSSetterAttribute(function.attributes) {
494503
errors.append(
495504
DiagnosticError(
496505
node: function,
497-
message: "@JSSetter is not supported for static members. Use it only for instance members in @JSClass types."
506+
message:
507+
"@JSSetter is not supported for static members. Use it only for instance members in @JSClass types."
498508
)
499509
)
500510
}
501511
} else if let variable = member.decl.as(VariableDeclSyntax.self),
502-
AttributeChecker.hasJSGetterAttribute(variable.attributes) {
512+
AttributeChecker.hasJSGetterAttribute(variable.attributes)
513+
{
503514
errors.append(
504515
DiagnosticError(
505516
node: variable,
506-
message: "@JSGetter is not supported for static members. Use it only for instance members in @JSClass types."
517+
message:
518+
"@JSGetter is not supported for static members. Use it only for instance members in @JSClass types."
507519
)
508520
)
509521
}
@@ -516,7 +528,10 @@ public final class ImportSwiftMacros {
516528
_ initializer: InitializerDeclSyntax,
517529
typeName: String
518530
) -> ImportedConstructorSkeleton? {
519-
guard validateEffects(initializer.signature.effectSpecifiers, node: initializer, attributeName: "JSFunction") != nil else {
531+
guard
532+
validateEffects(initializer.signature.effectSpecifiers, node: initializer, attributeName: "JSFunction")
533+
!= nil
534+
else {
520535
return nil
521536
}
522537
return ImportedConstructorSkeleton(
@@ -532,7 +547,8 @@ public final class ImportSwiftMacros {
532547
enclosingTypeName: String?,
533548
isStaticMember: Bool
534549
) -> ImportedFunctionSkeleton? {
535-
guard validateEffects(node.signature.effectSpecifiers, node: node, attributeName: "JSFunction") != nil else {
550+
guard validateEffects(node.signature.effectSpecifiers, node: node, attributeName: "JSFunction") != nil
551+
else {
536552
return nil
537553
}
538554

@@ -562,15 +578,15 @@ public final class ImportSwiftMacros {
562578
)
563579
}
564580

565-
566581
/// Extracts property info from a VariableDeclSyntax (binding, identifier, type)
567582
private func extractPropertyInfo(
568583
_ node: VariableDeclSyntax,
569584
errorMessage: String = "@JSGetter must declare a single stored property with an explicit type."
570585
) -> (identifier: IdentifierPatternSyntax, type: TypeSyntax)? {
571586
guard let binding = node.bindings.first,
572-
let identifier = binding.pattern.as(IdentifierPatternSyntax.self),
573-
let typeAnnotation = binding.typeAnnotation else {
587+
let identifier = binding.pattern.as(IdentifierPatternSyntax.self),
588+
let typeAnnotation = binding.typeAnnotation
589+
else {
574590
errors.append(DiagnosticError(node: node, message: errorMessage))
575591
return nil
576592
}
@@ -605,11 +621,13 @@ public final class ImportSwiftMacros {
605621
}
606622

607623
let functionName = node.name.text
608-
guard let (propertyName, functionBaseName) = PropertyNameResolver.resolve(
609-
functionName: functionName,
610-
jsName: validation.jsName,
611-
normalizeIdentifier: normalizeIdentifier
612-
) else {
624+
guard
625+
let (propertyName, functionBaseName) = PropertyNameResolver.resolve(
626+
functionName: functionName,
627+
jsName: validation.jsName,
628+
normalizeIdentifier: normalizeIdentifier
629+
)
630+
else {
613631
return nil
614632
}
615633

@@ -621,7 +639,6 @@ public final class ImportSwiftMacros {
621639
)
622640
}
623641

624-
625642
// MARK: - Type and Parameter Parsing
626643

627644
private func parseParameters(
@@ -648,7 +665,6 @@ public final class ImportSwiftMacros {
648665
}
649666
}
650667

651-
652668
private func parseType(_ type: TypeSyntax, enclosingTypeName: String?) -> BridgeType {
653669
guard let identifier = type.as(IdentifierTypeSyntax.self) else {
654670
errors.append(

Plugins/BridgeJS/Sources/BridgeJSTool/BridgeJSTool.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,8 @@ private func hasBridgeJSSkipComment(_ content: String) -> Bool {
218218
}
219219

220220
private func combineGeneratedSwift(_ pieces: [String]) -> String {
221-
let trimmedPieces = pieces
221+
let trimmedPieces =
222+
pieces
222223
.map { $0.trimmingCharacters(in: .newlines) }
223224
.filter { !$0.isEmpty }
224225
guard !trimmedPieces.isEmpty else { return "" }
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import Foundation
2-
31
extension String {
42
public var capitalizedFirstLetter: String {
53
guard !isEmpty else { return self }
@@ -8,13 +6,15 @@ extension String {
86
}
97

108
public enum BridgeJSGeneratedFile {
9+
/// The magic comment to skip processing by BridgeJS.
1110
public static let skipLine = "// bridge-js: skip"
1211

1312
public static func hasSkipComment(_ content: String) -> Bool {
1413
content.starts(with: skipLine + "\n")
1514
}
1615

1716
public static var swiftPreamble: String {
17+
// The generated Swift file itself should not be processed by BridgeJS again.
1818
"""
1919
\(skipLine)
2020
// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit,
@@ -23,7 +23,7 @@ public enum BridgeJSGeneratedFile {
2323
// To update this file, just rebuild your project or run
2424
// `swift package bridge-js`.
2525
26-
@_spi(BridgeJS) @_spi(Experimental) import JavaScriptKit
27-
""".trimmingCharacters(in: .newlines)
26+
@_spi(BridgeJS) import JavaScriptKit
27+
"""
2828
}
2929
}

Plugins/BridgeJS/Sources/TS2Swift/JavaScript/src/processor.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export class TypeProcessor {
7878
"// To update this file, just rebuild your project or run",
7979
"// `swift package bridge-js`.",
8080
"",
81-
"import JavaScriptKit",
81+
"@_spi(Experimental) import JavaScriptKit",
8282
""
8383
);
8484

@@ -142,7 +142,7 @@ export class TypeProcessor {
142142
const returnType = this.renderBridgeType(this.visitType(signature.getReturnType(), node), node);
143143
const effects = this.renderEffects({ isAsync: false });
144144
const swiftName = this.renderIdentifier(name);
145-
145+
146146
this.swiftLines.push(`@JSFunction func ${swiftName}(${params}) ${effects} -> ${returnType}`);
147147
this.swiftLines.push("");
148148
}
@@ -276,18 +276,18 @@ export class TypeProcessor {
276276
// Collect all declarations with their positions to preserve order
277277
/** @type {Array<{ decl: ts.Node, symbol: ts.Symbol, position: number }>} */
278278
const allDecls = [];
279-
279+
280280
for (const symbol of members) {
281281
for (const decl of symbol.getDeclarations() ?? []) {
282282
const sourceFile = decl.getSourceFile();
283283
const pos = sourceFile ? decl.getStart() : 0;
284284
allDecls.push({ decl, symbol, position: pos });
285285
}
286286
}
287-
287+
288288
// Sort by position to preserve declaration order
289289
allDecls.sort((a, b) => a.position - b.position);
290-
290+
291291
// Process declarations in order
292292
for (const { decl, symbol } of allDecls) {
293293
if (symbol.flags & ts.SymbolFlags.Property) {
@@ -410,10 +410,10 @@ export class TypeProcessor {
410410

411411
const type = this.renderBridgeType(property.type, node);
412412
const name = this.renderIdentifier(property.name);
413-
413+
414414
// Always render getter
415415
this.swiftLines.push(` @JSGetter var ${name}: ${type}`);
416-
416+
417417
// Render setter if not readonly
418418
if (!property.isReadonly) {
419419
const capitalizedName = property.name.charAt(0).toUpperCase() + property.name.slice(1);
@@ -441,7 +441,7 @@ export class TypeProcessor {
441441
const returnType = this.renderBridgeType(this.visitType(signature.getReturnType(), node), node);
442442
const effects = this.renderEffects({ isAsync: false });
443443
const swiftName = this.renderIdentifier(name);
444-
444+
445445
this.swiftLines.push(` @JSFunction func ${swiftName}(${params}) ${effects} -> ${returnType}`);
446446
}
447447

Plugins/BridgeJS/Tests/BridgeJSToolTests/BridgeJSLinkTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ import Testing
5555
let (_, outputSkeleton) = try #require(try swiftAPI.finalize())
5656
let bridgeJSLink: BridgeJSLink = BridgeJSLink(
5757
skeletons: [
58-
BridgeJSSkeleton(moduleName: "TestModule", exported: outputSkeleton),
58+
BridgeJSSkeleton(moduleName: "TestModule", exported: outputSkeleton)
5959
],
6060
sharedMemory: false
6161
)
@@ -116,7 +116,7 @@ import Testing
116116
let (_, outputSkeleton) = try #require(try swiftAPI.finalize())
117117
let bridgeJSLink: BridgeJSLink = BridgeJSLink(
118118
skeletons: [
119-
BridgeJSSkeleton(moduleName: "TestModule", exported: outputSkeleton),
119+
BridgeJSSkeleton(moduleName: "TestModule", exported: outputSkeleton)
120120
],
121121
sharedMemory: false
122122
)

Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/ArrayParameter.Macros.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// To update this file, just rebuild your project or run
55
// `swift package bridge-js`.
66

7-
import JavaScriptKit
7+
@_spi(Experimental) import JavaScriptKit
88

99
@JSFunction func checkArray(_ a: JSObject) throws (JSException) -> Void
1010

0 commit comments

Comments
 (0)