Skip to content

Commit 2afbd90

Browse files
BridgeJS: Add compatibility helper for GenericArgumentSyntax
1 parent bec6d83 commit 2afbd90

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)
@@ -2504,3 +2505,18 @@ private final class ImportSwiftMacrosAPICollector: SyntaxAnyVisitor {
25042505
}
25052506
}
25062507
}
2508+
2509+
extension GenericArgumentListSyntax {
2510+
/// Compatibility helper for accessing the first argument as a TypeSyntax
2511+
///
2512+
/// Note: SwiftSyntax 601 and later support InlineArrayTypeSyntax and
2513+
/// ``GenericArgumentSyntax/argument`` is now a ``TypeSyntax`` or ``ExprSyntax``.
2514+
fileprivate var firstAsTypeSyntax: TypeSyntax? {
2515+
guard let first = self.first else { return nil }
2516+
#if canImport(SwiftSyntax601)
2517+
return first.argument.as(TypeSyntax.self)
2518+
#else
2519+
return TypeSyntax(first.argument)
2520+
#endif
2521+
}
2522+
}

0 commit comments

Comments
 (0)