@@ -126,15 +126,17 @@ fn get_children_of_node(node: Symbol) -> Vec<Symbol> {
126126 doc_nodes
127127}
128128
129- pub fn docnodes_v1_to_v2 ( value : serde_json:: Value ) -> Vec < Symbol > {
129+ pub fn docnodes_v1_to_v2 ( value : serde_json:: Value ) -> Document {
130130 let serde_json:: Value :: Array ( arr) = value else {
131- return vec ! [ ] ;
131+ return Document :: default ( ) ;
132132 } ;
133133
134134 // v1 format: flat array where each entry has "name", "kind", "location",
135135 // "declarationKind", "jsDoc", and def fields all at the top level.
136- // v2 format: array of Symbol { name, isDefault, declarations: [...] }
137- // where each declaration has the remaining fields.
136+ // v2 format: Document { module_doc, imports, symbols }
137+ // where symbols are Symbol { name, isDefault, declarations: [...] }.
138+ let mut module_doc = js_doc:: JsDoc :: default ( ) ;
139+ let mut imports = Vec :: new ( ) ;
138140 let mut symbols: indexmap:: IndexMap < Box < str > , Symbol > =
139141 indexmap:: IndexMap :: new ( ) ;
140142
@@ -143,6 +145,51 @@ pub fn docnodes_v1_to_v2(value: serde_json::Value) -> Vec<Symbol> {
143145 continue ;
144146 } ;
145147
148+ let kind = obj
149+ . get ( "kind" )
150+ . and_then ( |v| v. as_str ( ) )
151+ . map ( |s| s. to_string ( ) ) ;
152+
153+ // v1 moduleDoc nodes become Document.module_doc
154+ if kind. as_deref ( ) == Some ( "moduleDoc" ) {
155+ if let Some ( js_doc_val) = obj
156+ . remove ( "jsDoc" )
157+ . and_then ( |v| serde_json:: from_value :: < js_doc:: JsDoc > ( v) . ok ( ) )
158+ {
159+ module_doc = js_doc_val;
160+ }
161+ continue ;
162+ }
163+
164+ // v1 import nodes become Document.imports
165+ if kind. as_deref ( ) == Some ( "import" ) {
166+ let imported_name: Box < str > = obj
167+ . remove ( "name" )
168+ . and_then ( |v| v. as_str ( ) . map ( |s| s. into ( ) ) )
169+ . unwrap_or_else ( || "" . into ( ) ) ;
170+ let import_def = obj. remove ( "importDef" ) . unwrap_or_default ( ) ;
171+ let src = import_def
172+ . get ( "src" )
173+ . and_then ( |v| v. as_str ( ) )
174+ . unwrap_or ( "" )
175+ . to_string ( ) ;
176+ let original_name = import_def
177+ . get ( "imported" )
178+ . and_then ( |v| v. as_str ( ) )
179+ . map ( |s| s. to_string ( ) ) ;
180+ let js_doc = obj
181+ . remove ( "jsDoc" )
182+ . and_then ( |v| serde_json:: from_value :: < js_doc:: JsDoc > ( v) . ok ( ) )
183+ . unwrap_or_default ( ) ;
184+ imports. push ( node:: Import {
185+ imported_name,
186+ original_name,
187+ src,
188+ js_doc,
189+ } ) ;
190+ continue ;
191+ }
192+
146193 let name: Box < str > = obj
147194 . remove ( "name" )
148195 . and_then ( |v| v. as_str ( ) . map ( |s| s. into ( ) ) )
@@ -190,7 +237,11 @@ pub fn docnodes_v1_to_v2(value: serde_json::Value) -> Vec<Symbol> {
190237 }
191238 }
192239
193- symbols. into_values ( ) . collect ( )
240+ Document {
241+ module_doc,
242+ imports,
243+ symbols : symbols. into_values ( ) . collect ( ) ,
244+ }
194245}
195246
196247/// Recursively walk JSON and convert v1 TsTypeDef objects (which use
0 commit comments