Skip to content

Commit

Permalink
Handle type names prefixed with any
Browse files Browse the repository at this point in the history
  • Loading branch information
skorulis-ap committed Jan 15, 2025
1 parent 6b852ec commit db2260f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Sources/KnitCodeGen/TypeNamer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ enum TypeNamer {
// The naming doesn't work for function types, just return closure
return "closure"
}
// Drop any annotation
var type = type.replacingOccurrences(of: "any ", with: "")
let removedCharacters = CharacterSet(charactersIn: "?[]():&, ")
var type = type.components(separatedBy: removedCharacters).joined(separator: "")
type = type.components(separatedBy: removedCharacters).joined(separator: "")
let regex = try! NSRegularExpression(pattern: "<.*>")
let nsString = type as NSString
if let match = regex.firstMatch(in: type, range: .init(location: 0, length: type.count)) {
Expand Down
12 changes: 12 additions & 0 deletions Tests/KnitCodeGenTests/TypeNamerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,18 @@ final class TypeNamerTests: XCTestCase {
)
}

func testAnyPrefix() {
assertComputedIdentifier(
type: "(any AppTransitionObservable)",
expectedIdentifier: "appTransitionObservable"
)

assertComputedIdentifier(
type: "any AppTransitionObservable",
expectedIdentifier: "appTransitionObservable"
)
}

}

private func assertComputedIdentifier(
Expand Down

0 comments on commit db2260f

Please sign in to comment.