Skip to content

Commit 6d24178

Browse files
BridgeJS: Add compatibility helper for GenericArgumentSyntax
1 parent 7d7f5d6 commit 6d24178

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

Plugins/BridgeJS/Sources/BridgeJSCore/SwiftToSkeleton.swift

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ public final class SwiftToSkeleton {
104104
identifierType.name.text == "JSTypedClosure",
105105
let genericArgs = identifierType.genericArgumentClause?.arguments,
106106
genericArgs.count == 1,
107-
let signatureType = lookupType(for: genericArgs.first!.argument, errors: &errors),
107+
let argument = genericArgs.firstAsTypeSyntax,
108+
let signatureType = lookupType(for: argument, errors: &errors),
108109
case .closure(let signature) = signatureType
109110
{
110111
return .closure(signature)
@@ -2506,3 +2507,18 @@ private final class ImportSwiftMacrosAPICollector: SyntaxAnyVisitor {
25062507
}
25072508
}
25082509
}
2510+
2511+
extension GenericArgumentListSyntax {
2512+
/// Compatibility helper for accessing the first argument as a TypeSyntax
2513+
///
2514+
/// Note: SwiftSyntax 601 and later support InlineArrayTypeSyntax and
2515+
/// ``GenericArgumentSyntax/argument`` is now a ``TypeSyntax`` or ``ExprSyntax``.
2516+
fileprivate var firstAsTypeSyntax: TypeSyntax? {
2517+
guard let first = self.first else { return nil }
2518+
#if canImport(SwiftSyntax601)
2519+
return first.argument.as(TypeSyntax.self)
2520+
#else
2521+
return TypeSyntax(first.argument)
2522+
#endif
2523+
}
2524+
}

0 commit comments

Comments
 (0)