Skip to content

Commit 212e0ef

Browse files
TypeScript: Fixed keyword false positives (#3001)
1 parent fdd291c commit 212e0ef

File tree

3 files changed

+55
-3
lines changed

3 files changed

+55
-3
lines changed

components/prism-typescript.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
Prism.languages.typescript.keyword.push(
1515
/\b(?:abstract|as|declare|implements|is|keyof|readonly|require)\b/,
1616
// keywords that have to be followed by an identifier
17-
// eslint-disable-next-line regexp/no-dupe-characters-character-class
18-
/\b(?:asserts|infer|interface|module|namespace|type)(?!\s*[^\s_${}*a-zA-Z\xA0-\uFFFF])/
17+
/\b(?:asserts|infer|interface|module|namespace|type)\b(?=\s*(?:[{_$a-zA-Z\xA0-\uFFFF]|$))/,
18+
// This is for `import type *, {}`
19+
/\btype\b(?=\s*(?:[\{*]|$))/
1920
);
2021

2122
// doesn't work with TS because TS is too complex

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: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { infer, inference, infer } from 'module'
2+
// ~~~~~ ✅
3+
4+
import { type, typeDefs, type } from 'module'
5+
// ~~~~ ✅
6+
7+
import { const, constants, const } from 'module'
8+
// ~~~~~ ✅
9+
10+
----------------------------------------------------
11+
12+
[
13+
["keyword", "import"],
14+
["punctuation", "{"],
15+
" infer",
16+
["punctuation", ","],
17+
" inference",
18+
["punctuation", ","],
19+
" infer ",
20+
["punctuation", "}"],
21+
["keyword", "from"],
22+
["string", "'module'"],
23+
24+
["comment", "// ~~~~~ ✅"],
25+
26+
["keyword", "import"],
27+
["punctuation", "{"],
28+
" type",
29+
["punctuation", ","],
30+
" typeDefs",
31+
["punctuation", ","],
32+
" type ",
33+
["punctuation", "}"],
34+
["keyword", "from"],
35+
["string", "'module'"],
36+
37+
["comment", "// ~~~~ ✅"],
38+
39+
["keyword", "import"],
40+
["punctuation", "{"],
41+
["keyword", "const"],
42+
["punctuation", ","],
43+
" constants",
44+
["punctuation", ","],
45+
["keyword", "const"],
46+
["punctuation", "}"],
47+
["keyword", "from"],
48+
["string", "'module'"],
49+
50+
["comment", "// ~~~~~ ✅"]
51+
]

0 commit comments

Comments
 (0)