Skip to content

Commit

Permalink
Tolerate more shapes of SourceKit output
Browse files Browse the repository at this point in the history
  • Loading branch information
johnfairh committed Oct 15, 2024
1 parent fbd6bbc commit 8506a77
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions Source/SourceKittenFramework/JSONOutput.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,28 +43,28 @@ public func toJSON(_ object: Any, options: JSONSerialization.WritingOptions? = n
- returns: JSON-serializable value.
*/
public func toNSDictionary(_ dictionary: [String: SourceKitRepresentable]) -> NSDictionary {
var anyDictionary = [String: Any]()
for (key, object) in dictionary {
switch object {
func toNSDictionaryValue(_ value: SourceKitRepresentable) -> Any {
switch value {
case let object as [SourceKitRepresentable]:
anyDictionary[key] = object.map { toNSDictionary($0 as! [String: SourceKitRepresentable]) }
return object.map { toNSDictionaryValue($0) }
case let object as [[String: SourceKitRepresentable]]:
anyDictionary[key] = object.map { toNSDictionary($0) }
return object.map { toNSDictionary($0) }
case let object as [String: SourceKitRepresentable]:
anyDictionary[key] = toNSDictionary(object)
return toNSDictionary(object)
case let object as String:
anyDictionary[key] = object
return object
case let object as Int64:
anyDictionary[key] = NSNumber(value: object)
return NSNumber(value: object)
case let object as Bool:
anyDictionary[key] = NSNumber(value: object)
return NSNumber(value: object)
case let object as Any:
anyDictionary[key] = object
return object
default:
fatalError("Should never happen because we've checked all SourceKitRepresentable types")
}
}
return anyDictionary.bridge()

return dictionary.mapValues(toNSDictionaryValue).bridge()
}

#if !os(Linux)
Expand Down

0 comments on commit 8506a77

Please sign in to comment.