Skip to content

Commit fe98d53

Browse files
TypeScript: Updated keywords (#2861)
1 parent 80d475e commit fe98d53

File tree

4 files changed

+300
-114
lines changed

4 files changed

+300
-114
lines changed

components/prism-typescript.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,16 @@
77
greedy: true,
88
inside: null // see below
99
},
10-
// From JavaScript Prism keyword list and TypeScript language spec: https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#221-reserved-words
11-
'keyword': /\b(?:abstract|as|asserts|async|await|break|case|catch|class|const|constructor|continue|debugger|declare|default|delete|do|else|enum|export|extends|finally|for|from|function|get|if|implements|import|in|instanceof|interface|is|keyof|let|module|namespace|new|null|of|package|private|protected|public|readonly|return|require|set|static|super|switch|this|throw|try|type|typeof|undefined|var|void|while|with|yield)\b/,
1210
'builtin': /\b(?:string|Function|any|number|boolean|Array|symbol|console|Promise|unknown|never)\b/,
1311
});
1412

13+
// The keywords TypeScript adds to JavaScript
14+
Prism.languages.typescript.keyword.push(
15+
/\b(?:abstract|as|declare|implements|is|keyof|readonly|require)\b/,
16+
// keywords that have to be followed by an identifier
17+
/\b(?:asserts|infer|interface|module|namespace|type)(?!\s*[^\s_${}*a-zA-Z\xA0-\uFFFF])/
18+
)
19+
1520
// doesn't work with TS because TS is too complex
1621
delete Prism.languages.typescript['parameter'];
1722

components/prism-typescript.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
export interface R<T> {
2+
data: T;
3+
total: number;
4+
type?: string;
5+
}
6+
7+
----------------------------------------------------
8+
9+
[
10+
["keyword", "export"],
11+
["keyword", "interface"],
12+
["class-name", [
13+
["constant", "R"],
14+
["operator", "<"],
15+
["constant", "T"],
16+
["operator", ">"]
17+
]],
18+
["punctuation", "{"],
19+
20+
"\r\n data",
21+
["operator", ":"],
22+
["constant", "T"],
23+
["punctuation", ";"],
24+
25+
"\r\n total",
26+
["operator", ":"],
27+
["builtin", "number"],
28+
["punctuation", ";"],
29+
30+
"\r\n type",
31+
["operator", "?"],
32+
["operator", ":"],
33+
["builtin", "string"],
34+
["punctuation", ";"],
35+
36+
["punctuation", "}"]
37+
]

0 commit comments

Comments
 (0)