Skip to content

Commit 36d4c73

Browse files
zhiqipanclaudekateinoigakukun
authored
Fix missing comma in @_expose attribute for SwiftSyntax602 (#555)
* Fix missing comma in @_expose attribute for SwiftSyntax602 The SwiftSyntax602 code path in `buildExposeAttributes` was using array literal syntax to construct `LabeledExprListSyntax`, which doesn't set `trailingComma` on the AST nodes. This resulted in malformed attributes: `@_expose(wasm "name")` instead of `@_expose(wasm, "name")`. The fix uses the result builder syntax with explicit `.with(\.trailingComma, .commaToken())` to ensure the comma is present in the generated code. Also adds a dedicated `bridgejs-test` CI job that tests BridgeJS with multiple Swift/SwiftSyntax version combinations to ensure both code paths (pre-602 and 602+) are exercised: - Swift 6.0.3 with SwiftSyntax 600.0.1 - Swift 6.1.2 with SwiftSyntax 601.0.1 - Swift 6.2 with SwiftSyntax 602.0.0 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Rename CI job to test-bridgejs-against-swift-versions * Simplify CI: let SPM resolve SwiftSyntax version naturally Remove sed-based version pinning that caused linker errors on Swift 6.2. Swift 6.2 ships with prebuilt SwiftSyntax 602.0.0, and forcing an exact version caused duplicate symbol errors during linking. Each Swift version naturally resolves to compatible SwiftSyntax: - Swift 6.0.x → SwiftSyntax 600.x - Swift 6.1.x → SwiftSyntax 601.x - Swift 6.2.x → SwiftSyntax 602.x Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Remove Swift 6.0.3 from test matrix The codebase uses trailing commas in argument lists (BridgeJSToolInternal.swift) which requires Swift 6.1+. Testing with 6.1.2 and 6.2 covers both SwiftSyntax code paths (non-602 and 602). Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Force SwiftSyntax 602.x for Swift 6.2 CI job On Swift 6.2, SPM resolves to SwiftSyntax 600.0.1 by default (per Package.swift), which doesn't have the SwiftSyntax602 module. Use sed to temporarily force SwiftSyntax 602.x so we actually test the SwiftSyntax602 code path. This also may avoid the prebuilt binary linker conflicts that occur with SwiftSyntax 600.0.1 on Swift 6.2. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Disable experimental SwiftSyntax prebuilts for BridgeJS tests * Override swift-syntax version via environment variable --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: Yuta Saito <kateinoigakukun@gmail.com>
1 parent d4c16e4 commit 36d4c73

File tree

3 files changed

+35
-5
lines changed

3 files changed

+35
-5
lines changed

.github/workflows/test.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,33 @@ jobs:
6767
- run: swift test --package-path ./Plugins/PackageToJS
6868
- run: swift test --package-path ./Plugins/BridgeJS
6969

70+
test-bridgejs-against-swift-versions:
71+
name: Test BridgeJS against Swift versions
72+
strategy:
73+
matrix:
74+
entry:
75+
- image: "swift:6.1.2"
76+
swift-syntax-version: "601.0.0"
77+
- image: "swift:6.2"
78+
swift-syntax-version: "602.0.0"
79+
runs-on: ubuntu-latest
80+
container:
81+
image: ${{ matrix.entry.image }}
82+
steps:
83+
- uses: actions/checkout@v6
84+
- name: Setup Node.js
85+
uses: actions/setup-node@v4
86+
with:
87+
node-version: '20'
88+
- name: Install TypeScript
89+
run: npm install --prefix Plugins/BridgeJS/Sources/TS2Swift/JavaScript
90+
- name: Run BridgeJS tests
91+
# NOTE: Seems like the prebuilt SwiftSyntax binaries are not compatible with
92+
# non-macro dependents, so disable experimental prebuilts for now.
93+
run: swift test --disable-experimental-prebuilts --package-path ./Plugins/BridgeJS
94+
env:
95+
BRIDGEJS_OVERRIDE_SWIFT_SYNTAX_VERSION: ${{ matrix.entry.swift-syntax-version }}
96+
7097
native-build:
7198
# Check native build to make it easy to develop applications by Xcode
7299
name: Build for native target

Plugins/BridgeJS/Package.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
import CompilerPluginSupport
44
import PackageDescription
55

6+
let swiftSyntaxVersion = Context.environment["BRIDGEJS_OVERRIDE_SWIFT_SYNTAX_VERSION"] ?? "600.0.1"
7+
68
let package = Package(
79
name: "BridgeJS",
810
platforms: [.macOS(.v13)],
911
dependencies: [
10-
.package(url: "https://github.com/swiftlang/swift-syntax", from: "600.0.1"),
12+
.package(url: "https://github.com/swiftlang/swift-syntax", from: Version(swiftSyntaxVersion)!),
1113
// Development dependencies
1214
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.7.0"),
1315
],

Plugins/BridgeJS/Sources/BridgeJSCore/ImportTS.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -760,10 +760,11 @@ enum SwiftCodePattern {
760760
return AttributeListSyntax {
761761
#if canImport(SwiftSyntax602)
762762
let exposeAttrArgs = AttributeSyntax.Arguments.argumentList(
763-
[
764-
LabeledExprSyntax(label: nil, expression: DeclReferenceExprSyntax(baseName: "wasm")),
765-
LabeledExprSyntax(label: nil, expression: StringLiteralExprSyntax(content: abiName)),
766-
]
763+
LabeledExprListSyntax {
764+
LabeledExprSyntax(label: nil, expression: DeclReferenceExprSyntax(baseName: "wasm"))
765+
.with(\.trailingComma, .commaToken())
766+
LabeledExprSyntax(label: nil, expression: StringLiteralExprSyntax(content: abiName))
767+
}
767768
)
768769
let cdeclAttrArgs = AttributeSyntax.Arguments.argumentList(
769770
[

0 commit comments

Comments
 (0)