Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions src/html/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,18 @@ pub fn doc_nodes_into_search_index_node(
}];

if let Some(drilldowns) = symbol.get_drilldown_symbols() {
out.extend(drilldowns.into_iter().flat_map(|drilldown_node| {
doc_nodes_into_search_index_node(ctx, &drilldown_node, Some(id.clone()))
}));
out.extend(
drilldowns
.into_iter()
.filter(|drilldown_node| !drilldown_node.is_internal(ctx.ctx))
.flat_map(|drilldown_node| {
doc_nodes_into_search_index_node(
ctx,
&drilldown_node,
Some(id.clone()),
)
}),
);
}

out
Expand All @@ -128,6 +137,11 @@ pub fn generate_search_index(ctx: &GenerateCtx) -> serde_json::Value {

let mut seen = std::collections::HashSet::new();
let mut doc_nodes = doc_nodes
// Symbols hidden from the rendered docs (e.g. `@internal`) must also be
// hidden from search, otherwise they remain findable there. `@ignore`
// symbols are already dropped earlier, but `is_internal` is only filtered
// in the listing views, so the search index has to apply it too. See #590.
.filter(|node| !node.is_internal(ctx))
.flat_map(|node| doc_nodes_into_search_index_node(&render_ctx, &node, None))
.filter(|node| seen.insert((node.name.clone(), node.file.clone())))
.collect::<Vec<_>>();
Expand Down
60 changes: 60 additions & 0 deletions tests/html_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,66 @@ export class Foo {
);
}

// Regression test for https://github.com/denoland/deno_doc/issues/590:
// `@internal` symbols are excluded from the rendered listings but were still
// emitted into the search index, leaving them findable. This applied to both
// named and default exports. `@ignore` symbols are already dropped entirely.
#[tokio::test]
async fn html_internal_symbols_excluded_from_search() {
let source = r#"
/** @internal */
export function internalNamed(): void {}

/** A visible function. */
export function visible(): void {}

/** @internal */
export default function (): void {}
"#;

let ctx = GenerateCtx::create_basic(
GenerateOptions {
package_name: None,
main_entrypoint: Some(ModuleSpecifier::parse("file:///mod.ts").unwrap()),
href_resolver: Arc::new(EmptyResolver),
usage_composer: Some(Arc::new(EmptyResolver)),
rewrite_map: None,
category_docs: None,
disable_search: false,
symbol_redirect_map: None,
default_symbol_map: None,
markdown_renderer: comrak::create_renderer(None, None, None),
markdown_stripper: Arc::new(comrak::strip),
head_inject: None,
id_prefix: None,
diff_only: false,
},
parse_source(source).await,
None,
)
.unwrap();

let files = generate(ctx).unwrap();
let search = files
.get("search_index.js")
.expect("search index should be generated");

// The visible export is searchable.
assert!(
search.contains("/~/visible.html"),
"visible export should be in the search index"
);
// `@internal` named and default exports must not be searchable.
assert!(
!search.contains("/~/internalNamed.html"),
"@internal named export leaked into the search index"
);
assert!(
!search.contains("/~/default.html"),
"@internal default export leaked into the search index"
);
}

#[tokio::test]
async fn diff_kind_change() {
let test_dir = std::env::current_dir()
Expand Down
Loading
Loading