diff --git a/src/parser.rs b/src/parser.rs index 7b17fc5b..fc0fbfa8 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -544,8 +544,10 @@ impl<'a> DocParser<'a> { TsModuleName::Str(str_) => str_.value.to_string(), }; let mut elements = Vec::new(); + let mut handled_symbols = HashSet::new(); for (export_name, export_symbol_id) in symbol.exports() { + handled_symbols.insert(*export_symbol_id); let export_symbol = module_symbol.symbol(*export_symbol_id).unwrap(); let definitions = self.root_symbol.go_to_definitions( &self.graph, @@ -553,6 +555,7 @@ impl<'a> DocParser<'a> { export_symbol, ); for definition in definitions { + handled_symbols.insert(definition.symbol.symbol_id()); if definition.module.specifier() != module_symbol.specifier() { continue; } @@ -572,18 +575,17 @@ impl<'a> DocParser<'a> { } let is_ambient = elements.is_empty() && !module_has_import(module_symbol); - if is_ambient || self.private { - let mut handled_symbols = - symbol.exports().values().copied().collect::>(); - for child_id in symbol.child_decls() { - if !handled_symbols.insert(child_id) { - continue; // already handled - } - let child_symbol = module_symbol.symbol(child_id).unwrap(); + for child_id in symbol.child_decls() { + if !handled_symbols.insert(child_id) { + continue; // already handled + } + let child_symbol = module_symbol.symbol(child_id).unwrap(); + if child_symbol.is_public() || is_ambient || self.private { for decl in child_symbol.decls() { if let Some(node) = decl.maybe_node() { - let is_declared = self.get_declare_for_symbol_node(node); - if is_declared || self.private { + let is_declared = + is_ambient && self.get_declare_for_symbol_node(node); + if child_symbol.is_public() || is_declared || self.private { if let Some(mut doc_node) = self.get_doc_for_symbol_node_ref( module_symbol, child_symbol, @@ -592,7 +594,6 @@ impl<'a> DocParser<'a> { doc_node.declaration_kind = if is_declared { DeclarationKind::Declare } else { - debug_assert!(self.private); DeclarationKind::Private }; elements.push(doc_node); @@ -902,8 +903,10 @@ impl<'a> DocParser<'a> { } } + let mut handled_symbols = HashSet::new(); let exports = module_symbol.exports(&self.graph, &self.root_symbol); for (export_name, (export_module, export_symbol_id)) in &exports { + handled_symbols.insert(*export_symbol_id); let export_symbol = export_module.symbol(*export_symbol_id).unwrap(); let definitions = self.root_symbol.go_to_definitions( &self.graph, @@ -914,6 +917,7 @@ impl<'a> DocParser<'a> { if definition.module.specifier() != module_symbol.specifier() { continue; } + handled_symbols.insert(definition.symbol.symbol_id()); let maybe_doc = self.doc_for_maybe_node( definition.module, definition.symbol, @@ -929,18 +933,17 @@ impl<'a> DocParser<'a> { } let is_ambient = exports.is_empty() && !module_has_import(module_symbol); - if is_ambient || self.private { - let mut handled_symbols = - exports.values().map(|n| n.1).collect::>(); - for child_id in module_symbol.child_decls() { - if !handled_symbols.insert(child_id) { - continue; // already handled - } - let child_symbol = module_symbol.symbol(child_id).unwrap(); + for child_id in module_symbol.child_decls() { + if !handled_symbols.insert(child_id) { + continue; // already handled + } + let child_symbol = module_symbol.symbol(child_id).unwrap(); + if child_symbol.is_public() || is_ambient || self.private { for decl in child_symbol.decls() { if let Some(node) = decl.maybe_node() { - let is_declared = self.get_declare_for_symbol_node(node); - if is_declared || self.private { + let is_declared = + is_ambient && self.get_declare_for_symbol_node(node); + if child_symbol.is_public() || is_declared || self.private { if let Some(mut doc_node) = self.get_doc_for_symbol_node_ref( module_symbol, child_symbol, @@ -949,7 +952,6 @@ impl<'a> DocParser<'a> { doc_node.declaration_kind = if is_declared { DeclarationKind::Declare } else { - debug_assert!(self.private); DeclarationKind::Private }; doc_nodes.push(doc_node); diff --git a/src/tests.rs b/src/tests.rs index 2f268da0..5b2a2b77 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -3450,7 +3450,6 @@ export function foo(a: string, b?: number, cb: (...cbArgs: unknown[]) => void, . r#" interface AssignOpts { a: string; - b: number; } export function foo([e,,f, ...g]: number[], { c, d: asdf, i = "asdf", ...rest}, ops: AssignOpts = {}): void { @@ -3568,18 +3567,49 @@ export function foo([e,,f, ...g]: number[], { c, d: asdf, i = "asdf", ...rest}, "location": { "col": 0, "filename": "file:///test.ts", - "line": 7, + "line": 6, }, "name": "foo", + }, { + "kind": "interface", + "name": "AssignOpts", + "location": { + "col": 0, + "filename": "file:///test.ts", + "line": 2, + }, + "declarationKind": "private", + "interfaceDef": { + "extends": [], + "methods": [], + "properties": [{ + "name": "a", + "location": { + "filename": "file:///test.ts", + "line": 3, + "col": 2, + }, + "params": [], + "computed": false, + "optional": false, + "tsType": { + "repr": "string", + "kind": "keyword", + "keyword": "string", + }, + "typeParams": [], + }], + "callSignatures": [], + "indexSignatures": [], + "typeParams": [], + } }]); json_test!(export_interface, - r#" + r#" interface Foo { - foo(): void; } interface Bar { - bar(): void; } /** * Interface js doc @@ -3589,92 +3619,126 @@ export interface Reader extends Foo, Bar { read?(buf: Uint8Array, something: unknown): Promise } "#; - [{ - "kind": "interface", - "name": "Reader", - "location": { - "filename": "file:///test.ts", - "line": 11, - "col": 0 - }, - "declarationKind": "export", - "jsDoc": { - "doc": "Interface js doc", - }, - "interfaceDef": { - "extends": [ - { - "repr": "Foo", - "kind": "typeRef", - "typeRef": { - "typeParams": null, - "typeName": "Foo" - } + [{ + "kind": "interface", + "name": "Reader", + "location": { + "filename": "file:///test.ts", + "line": 9, + "col": 0 }, - { - "repr": "Bar", - "kind": "typeRef", - "typeRef": { - "typeParams": null, - "typeName": "Bar" - } - } - ], - "methods": [ - { - "name": "read", - "kind": "method", - "location": { - "filename": "file:///test.ts", - "line": 13, - "col": 4 - }, - "optional": true, - "jsDoc": { - "doc": "Read n bytes", - }, - "params": [ + "declarationKind": "export", + "jsDoc": { + "doc": "Interface js doc", + }, + "interfaceDef": { + "extends": [ { - "name": "buf", - "kind": "identifier", - "optional": false, - "tsType": { - "repr": "Uint8Array", - "kind": "typeRef", - "typeRef": { - "typeParams": null, - "typeName": "Uint8Array" - } + "repr": "Foo", + "kind": "typeRef", + "typeRef": { + "typeParams": null, + "typeName": "Foo" } }, { - "name": "something", - "kind": "identifier", - "optional": false, - "tsType": { - "repr": "unknown", - "kind": "keyword", - "keyword": "unknown" + "repr": "Bar", + "kind": "typeRef", + "typeRef": { + "typeParams": null, + "typeName": "Bar" } } ], - "typeParams": [], - "returnType": { - "repr": "Promise", - "kind": "typeRef", - "typeRef": { - "typeParams": [ + "methods": [ + { + "name": "read", + "kind": "method", + "location": { + "filename": "file:///test.ts", + "line": 11, + "col": 4 + }, + "optional": true, + "jsDoc": { + "doc": "Read n bytes", + }, + "params": [ { - "repr": "number", - "kind": "keyword", - "keyword": "number" + "name": "buf", + "kind": "identifier", + "optional": false, + "tsType": { + "repr": "Uint8Array", + "kind": "typeRef", + "typeRef": { + "typeParams": null, + "typeName": "Uint8Array" + } + } + }, + { + "name": "something", + "kind": "identifier", + "optional": false, + "tsType": { + "repr": "unknown", + "kind": "keyword", + "keyword": "unknown" + } } ], - "typeName": "Promise" + "typeParams": [], + "returnType": { + "repr": "Promise", + "kind": "typeRef", + "typeRef": { + "typeParams": [ + { + "repr": "number", + "kind": "keyword", + "keyword": "number" + } + ], + "typeName": "Promise" + } + } } - } - } - ], + ], + "properties": [], + "callSignatures": [], + "indexSignatures": [], + "typeParams": [], + } + }, { + "kind": "interface", + "name": "Foo", + "location": { + "filename": "file:///test.ts", + "line": 2, + "col": 0 + }, + "declarationKind": "private", + "interfaceDef": { + "extends": [], + "methods": [], + "properties": [], + "callSignatures": [], + "indexSignatures": [], + "typeParams": [], + } + }, { + "kind": "interface", + "name": "Bar", + "location": { + "filename": "file:///test.ts", + "line": 4, + "col": 0 + }, + "declarationKind": "private", + "interfaceDef": { + "extends": [], + "methods": [], "properties": [], "callSignatures": [], "indexSignatures": [],