Skip to content

Commit 0f73bba

Browse files
committed
fix: don't add links to reserved keywords in declaration signatures
See [email protected] types.
1 parent 7c07870 commit 0f73bba

File tree

1 file changed

+73
-1
lines changed

1 file changed

+73
-1
lines changed

lib/declaration-signature-html.ts

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,78 @@ import type { DeclarationUrlFn } from "./declaration-url";
33
import { domPurify } from "./dom-purify";
44
import { highlighter } from "./highlighter";
55

6+
const reservedKeywords = new Set([
7+
"any",
8+
"as",
9+
"async",
10+
"await",
11+
"bigint",
12+
"boolean",
13+
"break",
14+
"case",
15+
"catch",
16+
"class",
17+
"const",
18+
"constructor",
19+
"continue",
20+
"debugger",
21+
"declare",
22+
"default",
23+
"delete",
24+
"do",
25+
"else",
26+
"enum",
27+
"export",
28+
"extends",
29+
"false",
30+
"finally",
31+
"for",
32+
"from",
33+
"function",
34+
"get",
35+
"if",
36+
"implements",
37+
"import",
38+
"in",
39+
"instanceof",
40+
"interface",
41+
"let",
42+
"module",
43+
"namespace",
44+
"never",
45+
"new",
46+
"null",
47+
"number",
48+
"object",
49+
"of",
50+
"package",
51+
"private",
52+
"protected",
53+
"public",
54+
"readonly",
55+
"require",
56+
"return",
57+
"set",
58+
"static",
59+
"string",
60+
"super",
61+
"switch",
62+
"symbol",
63+
"this",
64+
"throw",
65+
"true",
66+
"try",
67+
"type",
68+
"typeof",
69+
"undefined",
70+
"unknown",
71+
"var",
72+
"void",
73+
"while",
74+
"with",
75+
"yield",
76+
]);
77+
678
export const declarationSignatureHtml = (
779
declaration: AllExtractedDeclaration,
880
declarationUrl: DeclarationUrlFn,
@@ -21,7 +93,7 @@ export const declarationSignatureHtml = (
2193
}
2294
const text = firstChild.value;
2395
const url = declarationUrl(text);
24-
if (text === declaration.name || !url) {
96+
if (text === declaration.name || !url || reservedKeywords.has(text)) {
2597
return;
2698
}
2799
if (node.properties["style"] === "color:#E36209;--shiki-dark:#FFAB70") {

0 commit comments

Comments
 (0)