Skip to content

Commit ef2349f

Browse files
committed
fix tests
1 parent f599fa9 commit ef2349f

21 files changed

Lines changed: 1044 additions & 746 deletions

src/html/types.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,7 @@ pub(crate) fn render_type_def(
166166
)
167167
})
168168
} else {
169-
Some(format!(
170-
"#{}",
171-
IdBuilder::new(ctx)
172-
.kind(IdKind::TypeParam)
173-
.name(&type_ref.type_name)
174-
.build_unregistered()
175-
))
169+
None
176170
}
177171
}
178172
crate::ts_type::TypeRefResolution::Import { specifier, name } => {

src/js_doc.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ pub fn parse_jsdoc_type(
7474
type_alias,
7575
) = type_alias
7676
{
77-
Some(TsTypeDef::new(module_info, &type_alias.type_annotation))
77+
let mut ts_type = TsTypeDef::new(module_info, &type_alias.type_annotation);
78+
ts_type.clear_resolutions();
79+
Some(ts_type)
7880
} else {
7981
None
8082
}
@@ -615,7 +617,6 @@ mod tests {
615617
) -> serde_json::Value {
616618
let mut value = serde_json::json!({
617619
"typeName": name,
618-
"resolution": { "kind": "typeParam" },
619620
});
620621
if let Some(tp) = type_params {
621622
value["typeParams"] = serde_json::json!(tp);

src/lib.rs

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -207,16 +207,16 @@ pub fn docnodes_v1_to_v2(value: serde_json::Value) -> Document {
207207
let mut declaration = serde_json::Value::Object(obj);
208208
migrate_declaration(&mut declaration);
209209

210-
let symbol = symbols.entry(name.clone()).or_insert_with(|| Symbol {
211-
name,
212-
is_default,
213-
declarations: vec![],
214-
});
215-
// If any entry is marked default, the symbol is default
216-
if is_default {
217-
symbol.is_default = true;
218-
}
219210
if let Ok(decl) = serde_json::from_value::<Declaration>(declaration) {
211+
let symbol = symbols.entry(name.clone()).or_insert_with(|| Symbol {
212+
name,
213+
is_default,
214+
declarations: vec![],
215+
});
216+
// If any entry is marked default, the symbol is default
217+
if is_default {
218+
symbol.is_default = true;
219+
}
220220
symbol.declarations.push(decl);
221221
}
222222
}
@@ -313,18 +313,21 @@ fn v1_nodes_to_symbols(nodes: Vec<serde_json::Value>) -> serde_json::Value {
313313
let mut decl = serde_json::Value::Object(obj);
314314
migrate_declaration(&mut decl);
315315

316-
let symbol = symbols.entry(name.clone()).or_insert_with(|| {
317-
serde_json::json!({
318-
"name": name,
319-
"declarations": []
320-
})
321-
});
316+
let declaration = serde_json::from_value::<Declaration>(decl.clone());
317+
if declaration.is_ok() {
318+
let symbol = symbols.entry(name.clone()).or_insert_with(|| {
319+
serde_json::json!({
320+
"name": name,
321+
"declarations": []
322+
})
323+
});
324+
325+
if is_default {
326+
symbol["isDefault"] = serde_json::Value::Bool(true);
327+
}
322328

323-
if is_default {
324-
symbol["isDefault"] = serde_json::Value::Bool(true);
329+
symbol["declarations"].as_array_mut().unwrap().push(decl);
325330
}
326-
327-
symbol["declarations"].as_array_mut().unwrap().push(decl);
328331
}
329332

330333
serde_json::Value::Array(symbols.into_values().collect())

src/parser.rs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,8 +1413,14 @@ impl<'a> DocParser<'a> {
14131413
self.get_doc_for_export_default_decl(module_info, n)
14141414
}
14151415
SymbolNodeRef::ExportDefaultExpr(n) => {
1416-
let js_doc = js_doc_for_range(module_info, n.span())?;
1417-
let location = get_location(module_info, n.span().start);
1416+
let (js_doc, location) = self
1417+
.export_default_expr_context(module_info, n)
1418+
.unwrap_or_else(|| {
1419+
(
1420+
js_doc_for_range(module_info, n.span()).unwrap_or_default(),
1421+
get_location(module_info, n.span().start),
1422+
)
1423+
});
14181424
self.get_decl_for_export_default_expr(module_info, n, js_doc, location)
14191425
}
14201426
SymbolNodeRef::FnDecl(n) => {
@@ -1530,6 +1536,26 @@ impl<'a> DocParser<'a> {
15301536
}
15311537
}
15321538

1539+
fn export_default_expr_context(
1540+
&self,
1541+
module_info: &EsModuleInfo,
1542+
export_expr: &ExportDefaultDeclarationKind,
1543+
) -> Option<(JsDoc, Location)> {
1544+
let expr_span = export_expr.span();
1545+
for stmt in module_info.statements() {
1546+
let Statement::ExportDefaultDeclaration(export_default) = stmt else {
1547+
continue;
1548+
};
1549+
if export_default.declaration.span() == expr_span {
1550+
return Some((
1551+
js_doc_for_range(module_info, export_default.span)?,
1552+
get_location(module_info, export_default.span.start),
1553+
));
1554+
}
1555+
}
1556+
None
1557+
}
1558+
15331559
fn get_declare_for_export_decl_declaration(
15341560
&self,
15351561
export_decl: &ExportNamedDeclaration,

src/tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -519,8 +519,8 @@ export * as b from "./mod_doc.ts";
519519
"location": {
520520
"filename": "file:///ns.ts",
521521
"line": 1,
522-
"col": 7,
523-
"byteIndex": 8
522+
"col": 0,
523+
"byteIndex": 1
524524
},
525525
"declarationKind": "export",
526526
"jsDoc": {

0 commit comments

Comments
 (0)