Skip to content

Commit

Permalink
fix: do not show [UNSUPPORTED] default in html docs (#608)
Browse files Browse the repository at this point in the history
  • Loading branch information
kt3k authored Jul 11, 2024
1 parent 7dd8166 commit 7408634
Show file tree
Hide file tree
Showing 9 changed files with 229 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/html/symbols/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,9 @@ fn render_single_function(
.unwrap_or_default();

if let Some(default) = &default {
ts_type = format!(r#"{ts_type}<span><span class="font-normal"> = </span>{default}</span>"#);
if default != "[UNSUPPORTED]" {
ts_type = format!(r#"{ts_type}<span><span class="font-normal"> = </span>{default}</span>"#);
}
}

let tags = if matches!(
Expand Down
1 change: 1 addition & 0 deletions tests/html_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ async fn html_doc_files_rewrite() {
"./~/Hello.html",
"./~/Hello.world.html",
"./~/c.html",
"./~/d.html",
"./~/qaz.html",
"foo/index.html",
"foo/~/default.html",
Expand Down
2 changes: 1 addition & 1 deletion tests/snapshots/html_test__html_doc_files_rewrite-16.snap
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ Variables</h2></div><div class="namespaceSection"><div id="namespace_default" cl
<span class="hover:bg-Interface/15">Hello</span>
</a>
</li></ul><a class="flex items-center gap-0.5" href="..&#x2F;.&#x2F;all_symbols.html">
<span class="leading-none">view all 9 symbols</span><svg
<span class="leading-none">view all 10 symbols</span><svg
width="16"
height="16"
viewBox="0 0 16 16"
Expand Down
10 changes: 8 additions & 2 deletions tests/snapshots/html_test__html_doc_files_rewrite-2.snap
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@ Functions</h2></div><div class="namespaceSection"><div id="namespace_c" class="n
<div class="namespaceItemContent">
<a href="..&#x2F;.&#x2F;.&#x2F;~&#x2F;c.html" title="c">c</a>

<div><span class="italic">No documentation available</span></div>
</div>
</div><div id="namespace_d" class="namespaceItem" ><div class="docNodeKindIcon"><div class="text-Function bg-Function/15" title="Function">f</div></div>
<div class="namespaceItemContent">
<a href="..&#x2F;.&#x2F;.&#x2F;~&#x2F;d.html" title="d">d</a>

<div><span class="italic">No documentation available</span></div>
</div>
</div><div id="namespace_qaz" class="namespaceItem" ><div class="docNodeKindIcon"><div class="text-Function bg-Function/15" title="Function">f</div></div>
Expand Down Expand Up @@ -271,7 +277,7 @@ Type Aliases</h2></div><div class="namespaceSection"><div id="namespace_baz" cla
<span class="hover:bg-Interface/15">Hello</span>
</a>
</li></ul><a class="flex items-center gap-0.5" href="..&#x2F;.&#x2F;all_symbols.html">
<span class="leading-none">view all 9 symbols</span><svg
<span class="leading-none">view all 10 symbols</span><svg
width="16"
height="16"
viewBox="0 0 16 16"
Expand All @@ -280,7 +286,7 @@ Type Aliases</h2></div><div class="namespaceSection"><div id="namespace_baz" cla
<path fill-rule="evenodd" clip-rule="evenodd" d="M5.76748 11.8159C5.5378 11.577 5.54525 11.1972 5.78411 10.9675L8.93431 8L5.78411 5.0325C5.54525 4.80282 5.5378 4.423 5.76748 4.18413C5.99715 3.94527 6.37698 3.93782 6.61584 4.1675L10.2158 7.5675C10.3335 7.68062 10.4 7.83679 10.4 8C10.4 8.16321 10.3335 8.31938 10.2158 8.4325L6.61584 11.8325C6.37698 12.0622 5.99715 12.0547 5.76748 11.8159Z" fill="currentColor" />
</svg>
</a></nav><nav class="documentNavigation">
<h3>Document Navigation</h3><ul><li><a href="#classes" title="Classes">Classes</a></li><li><ul><li><a href="#namespace_bar" title="Bar">Bar</a></li><li><a href="#namespace_foo" title="Foo">Foo</a></li><li><a href="#namespace_foobar" title="Foobar">Foobar</a></li></ul></li><li><a href="#functions" title="Functions">Functions</a></li><li><ul><li><a href="#namespace_c" title="c">c</a></li><li><a href="#namespace_qaz" title="qaz">qaz</a></li></ul></li><li><a href="#interfaces" title="Interfaces">Interfaces</a></li><li><ul><li><a href="#namespace_hello" title="Hello">Hello</a></li></ul></li><li><a href="#type-aliases" title="Type Aliases">Type Aliases</a></li><li><ul><li><a href="#namespace_baz" title="Baz">Baz</a></li></ul></nav></div>
<h3>Document Navigation</h3><ul><li><a href="#classes" title="Classes">Classes</a></li><li><ul><li><a href="#namespace_bar" title="Bar">Bar</a></li><li><a href="#namespace_foo" title="Foo">Foo</a></li><li><a href="#namespace_foobar" title="Foobar">Foobar</a></li></ul></li><li><a href="#functions" title="Functions">Functions</a></li><li><ul><li><a href="#namespace_c" title="c">c</a></li><li><a href="#namespace_d" title="d">d</a></li><li><a href="#namespace_qaz" title="qaz">qaz</a></li></ul></li><li><a href="#interfaces" title="Interfaces">Interfaces</a></li><li><ul><li><a href="#namespace_hello" title="Hello">Hello</a></li></ul></li><li><a href="#type-aliases" title="Type Aliases">Type Aliases</a></li><li><ul><li><a href="#namespace_baz" title="Baz">Baz</a></li></ul></nav></div>
</div><div id="searchResults"></div></div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion tests/snapshots/html_test__html_doc_files_rewrite-22.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ source: tests/html_test.rs
expression: "files.get(\"search_index.js\").unwrap()"
---
(function () {
window.DENO_DOC_SEARCH_INDEX = {"nodes":[{"kind":["class"],"name":"A","file":".","doc":"","location":{"filename":".","line":45,"col":0,"byteIndex":741},"url":"././~/A.html","category":"","declarationKind":"private","deprecated":false},{"kind":["class"],"name":"B","file":".","doc":"","location":{"filename":".","line":48,"col":0,"byteIndex":770},"url":"././~/B.html","category":"","declarationKind":"export","deprecated":false},{"kind":["class"],"name":"Bar","file":".","doc":"","location":{"filename":".","line":31,"col":0,"byteIndex":588},"url":"././~/Bar.html","category":"","declarationKind":"export","deprecated":false},{"kind":["typeAlias"],"name":"Baz","file":".","doc":"","location":{"filename":".","line":41,"col":0,"byteIndex":702},"url":"././~/Baz.html","category":"","declarationKind":"export","deprecated":false},{"kind":["class"],"name":"Foo","file":".","doc":"some Foo docs","location":{"filename":".","line":25,"col":0,"byteIndex":488},"url":"././~/Foo.html","category":"","declarationKind":"export","deprecated":false},{"kind":["class"],"name":"Foobar","file":".","doc":"","location":{"filename":".","line":34,"col":0,"byteIndex":622},"url":"././~/Foobar.html","category":"","declarationKind":"export","deprecated":false},{"kind":["interface"],"name":"Hello","file":".","doc":"","location":{"filename":".","line":37,"col":0,"byteIndex":655},"url":"././~/Hello.html","category":"","declarationKind":"export","deprecated":false},{"kind":["function"],"name":"c","file":".","doc":"","location":{"filename":".","line":57,"col":13,"byteIndex":933},"url":"././~/c.html","category":"","declarationKind":"export","deprecated":false},{"kind":["function","function","function"],"name":"qaz","file":".","doc":"","location":{"filename":".","line":53,"col":0,"byteIndex":812},"url":"././~/qaz.html","category":"","declarationKind":"export","deprecated":false},{"kind":["variable"],"name":"default","file":"foo","doc":"The default export item.\n\nThis item reproduces the issue reported in {@link https://github.com/jsr-io/jsr/issues/459}","location":{"filename":"foo","line":7,"col":6,"byteIndex":167},"url":"./foo/~/default.html","category":"","declarationKind":"export","deprecated":false},{"kind":["function"],"name":"x","file":"foo","doc":"","location":{"filename":"foo","line":1,"col":0,"byteIndex":0},"url":"./foo/~/x.html","category":"","declarationKind":"export","deprecated":false}]};
window.DENO_DOC_SEARCH_INDEX = {"nodes":[{"kind":["class"],"name":"A","file":".","doc":"","location":{"filename":".","line":45,"col":0,"byteIndex":741},"url":"././~/A.html","category":"","declarationKind":"private","deprecated":false},{"kind":["class"],"name":"B","file":".","doc":"","location":{"filename":".","line":48,"col":0,"byteIndex":770},"url":"././~/B.html","category":"","declarationKind":"export","deprecated":false},{"kind":["class"],"name":"Bar","file":".","doc":"","location":{"filename":".","line":31,"col":0,"byteIndex":588},"url":"././~/Bar.html","category":"","declarationKind":"export","deprecated":false},{"kind":["typeAlias"],"name":"Baz","file":".","doc":"","location":{"filename":".","line":41,"col":0,"byteIndex":702},"url":"././~/Baz.html","category":"","declarationKind":"export","deprecated":false},{"kind":["class"],"name":"Foo","file":".","doc":"some Foo docs","location":{"filename":".","line":25,"col":0,"byteIndex":488},"url":"././~/Foo.html","category":"","declarationKind":"export","deprecated":false},{"kind":["class"],"name":"Foobar","file":".","doc":"","location":{"filename":".","line":34,"col":0,"byteIndex":622},"url":"././~/Foobar.html","category":"","declarationKind":"export","deprecated":false},{"kind":["interface"],"name":"Hello","file":".","doc":"","location":{"filename":".","line":37,"col":0,"byteIndex":655},"url":"././~/Hello.html","category":"","declarationKind":"export","deprecated":false},{"kind":["function"],"name":"c","file":".","doc":"","location":{"filename":".","line":57,"col":13,"byteIndex":933},"url":"././~/c.html","category":"","declarationKind":"export","deprecated":false},{"kind":["function"],"name":"d","file":".","doc":"","location":{"filename":".","line":59,"col":0,"byteIndex":961},"url":"././~/d.html","category":"","declarationKind":"export","deprecated":false},{"kind":["function","function","function"],"name":"qaz","file":".","doc":"","location":{"filename":".","line":53,"col":0,"byteIndex":812},"url":"././~/qaz.html","category":"","declarationKind":"export","deprecated":false},{"kind":["variable"],"name":"default","file":"foo","doc":"The default export item.\n\nThis item reproduces the issue reported in {@link https://github.com/jsr-io/jsr/issues/459}","location":{"filename":"foo","line":7,"col":6,"byteIndex":167},"url":"./foo/~/default.html","category":"","declarationKind":"export","deprecated":false},{"kind":["function"],"name":"x","file":"foo","doc":"","location":{"filename":"foo","line":1,"col":0,"byteIndex":0},"url":"./foo/~/x.html","category":"","declarationKind":"export","deprecated":false}]};
})()
6 changes: 6 additions & 0 deletions tests/snapshots/html_test__html_doc_files_rewrite.snap
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ expression: "files.get(\"./all_symbols.html\").unwrap()"
<div class="namespaceItemContent">
<a href=".&#x2F;.&#x2F;.&#x2F;~&#x2F;c.html" title="c">c</a>

<div><span class="italic">No documentation available</span></div>
</div>
</div><div id="namespace_d" class="namespaceItem" ><div class="docNodeKindIcon"><div class="text-Function bg-Function/15" title="Function">f</div></div>
<div class="namespaceItemContent">
<a href=".&#x2F;.&#x2F;.&#x2F;~&#x2F;d.html" title="d">d</a>

<div><span class="italic">No documentation available</span></div>
</div>
</div><div id="namespace_foo" class="namespaceItem" ><div class="docNodeKindIcon"><div class="text-Class bg-Class/15" title="Class">c</div></div>
Expand Down
183 changes: 183 additions & 0 deletions tests/snapshots/html_test__symbol_group.snap
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,189 @@ expression: files
"disable_search": false,
"categories_panel": null
},
{
"html_head_ctx": {
"title": "d - documentation",
"current_file": ".",
"stylesheet_url": "../styles.css",
"page_stylesheet_url": "../page.css",
"reset_stylesheet_url": "../reset.css",
"url_search_index": "../search_index.js",
"script_js": "../script.js",
"fuse_js": "../fuse.js",
"url_search": "../search.js",
"disable_search": false
},
"symbol_group_ctx": {
"name": "d",
"symbols": [
{
"kind": {
"kind": "Function",
"char": "f",
"title": "Function",
"title_lowercase": "function",
"title_plural": "Functions"
},
"usage": null,
"tags": [],
"subtitle": null,
"content": [
{
"kind": "function",
"value": {
"overloads_ctx": [
{
"function_id": "function_d",
"overload_id": "function_d_0",
"additional_css": "\n#function_d_0 {\n display: none;\n}\n#function_d_0:checked ~ *:last-child > :not(#function_d_0_div) {\n display: none;\n}\n#function_d_0:checked ~ div:first-of-type > label[for='function_d_0'] {\n background-color: var(--ddoc-selection-selected-bg);\n border: solid var(--ddoc-selection-border-width) var(--ddoc-selection-selected-border-color);\n cursor: unset;\n padding: var(--ddoc-selection-padding); /* 1px less to counter the increased border */\n}\n\n.ddoc:has(#function_d_0:not(:checked)) #function_d_0_toc {\n display: none;\n}\n",
"html_attrs": "checked",
"name": "d",
"deprecated": null,
"summary": "(<span><span>foo?<span>: <span>number</span></span></span><span>, </span><span>bar?<span>: <span>string</span></span></span><span>, </span><span>baz?<span>: { hello?<span>: <span>string</span></span>; }</span></span></span>)<span>: <span>string</span></span>",
"summary_doc": null
}
],
"functions": [
{
"id": "function_d_0_div",
"docs": null,
"sections": [
{
"header": {
"title": "Parameters",
"anchor": {
"id": "parameters"
},
"href": null,
"doc": null
},
"content": {
"kind": "doc_entry",
"content": [
{
"id": "function_d_0_parameters_foo",
"name": "foo",
"name_href": null,
"content": "<span>: <span>number</span></span><span><span class=\"font-normal\"> = </span>1</span>",
"anchor": {
"id": "function_d_0_parameters_foo"
},
"tags": [
{
"kind": "optional"
}
],
"js_doc": null,
"source_href": null
},
{
"id": "function_d_0_parameters_bar",
"name": "bar",
"name_href": null,
"content": "<span>: <span>string</span></span><span><span class=\"font-normal\"> = </span>bar</span>",
"anchor": {
"id": "function_d_0_parameters_bar"
},
"tags": [
{
"kind": "optional"
}
],
"js_doc": null,
"source_href": null
},
{
"id": "function_d_0_parameters_baz",
"name": "baz",
"name_href": null,
"content": "<span>: { hello?<span>: <span>string</span></span>; }</span>",
"anchor": {
"id": "function_d_0_parameters_baz"
},
"tags": [
{
"kind": "optional"
}
],
"js_doc": null,
"source_href": null
}
]
}
},
{
"header": {
"title": "Return Type",
"anchor": {
"id": "return-type"
},
"href": null,
"doc": null
},
"content": {
"kind": "doc_entry",
"content": [
{
"id": "function_d_0_return",
"name": "",
"name_href": null,
"content": "<span>string</span>",
"anchor": {
"id": "function_d_0_return"
},
"tags": [],
"js_doc": null,
"source_href": null
}
]
}
}
]
}
]
}
}
],
"deprecated": null,
"source_href": null
}
]
},
"breadcrumbs_ctx": {
"parts": [
{
"name": "index",
"href": "../",
"is_symbol": false,
"is_first_symbol": false
},
{
"name": "d",
"href": "../././~/d.html",
"is_symbol": true,
"is_first_symbol": true
}
]
},
"toc_ctx": {
"usages": {
"usages": [
{
"name": "",
"content": "<div class=\"markdown\"><pre class=\"highlight\"><code>import { d } from \".\";\n</code><button class=\"context_button\" data-copy=\"import { d } from &quot;.&quot;;\n\"><svg width=\"15\" height=\"15\" viewBox=\"0 0 15 15\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\n<rect x=\"2\" y=\"2\" width=\"7\" height=\"7\" fill=\"none\"></rect>\n<rect x=\"6\" y=\"6\" width=\"7\" height=\"7\" fill=\"none\"></rect>\n<path d=\"M1.55566 2.7C1.55566 2.03726 2.09292 1.5 2.75566 1.5H8.75566C9.41841 1.5 9.95566 2.03726 9.95566 2.7V5.1H12.3557C13.0184 5.1 13.5557 5.63726 13.5557 6.3V12.3C13.5557 12.9627 13.0184 13.5 12.3557 13.5H6.35566C5.69292 13.5 5.15566 12.9627 5.15566 12.3V9.9H2.75566C2.09292 9.9 1.55566 9.36274 1.55566 8.7V2.7ZM6.35566 9.9V12.3H12.3557V6.3H9.95566V8.7C9.95566 9.36274 9.41841 9.9 8.75566 9.9H6.35566ZM8.75566 8.7V2.7H2.75566V8.7H8.75566Z\" fill=\"#232323\"></path>\n</svg>\n</button><code></code></pre>\n</div>",
"icon": null,
"additional_css": ""
}
],
"composed": false
},
"top_symbols": null,
"document_navigation": "<ul id=\"function_d_0_toc\"><li><a href=\"#parameters\" title=\"Parameters\">Parameters</a></li><li><ul><li><a href=\"#function_d_0_parameters_foo\" title=\"foo\">foo</a></li><li><a href=\"#function_d_0_parameters_bar\" title=\"bar\">bar</a></li><li><a href=\"#function_d_0_parameters_baz\" title=\"baz\">baz</a></li></ul></li><li><a href=\"#return-type\" title=\"Return Type\">Return Type</a></li><li><ul><li><a href=\"#function_d_0_return\" title=\"\"></a></li></ul>"
},
"disable_search": false,
"categories_panel": null
},
{
"html_head_ctx": {
"title": "qaz - documentation",
Expand Down
18 changes: 18 additions & 0 deletions tests/snapshots/html_test__symbol_search.snap
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,24 @@ expression: search_index
"declarationKind": "export",
"deprecated": false
},
{
"kind": [
"function"
],
"name": "d",
"file": ".",
"doc": "",
"location": {
"filename": "default",
"line": 59,
"col": 0,
"byteIndex": 961
},
"url": "././~/d.html",
"category": "",
"declarationKind": "export",
"deprecated": false
},
{
"kind": [
"function",
Expand Down
8 changes: 8 additions & 0 deletions tests/testdata/multiple/a.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,11 @@ export function qaz(a: number);
export function qaz(a: string | number) {}

export const c = (): string => "hello";

export function d(
foo: number = 1,
bar: string = "bar",
baz: { hello?: string } = {},
): string {
return foo + bar;
}

0 comments on commit 7408634

Please sign in to comment.