Skip to content

Commit

Permalink
TypeScript: Fixed keyword false positives (#3001)
Browse files Browse the repository at this point in the history
  • Loading branch information
RunDevelopment committed Jul 19, 2021
1 parent fdd291c commit 212e0ef
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 3 deletions.
5 changes: 3 additions & 2 deletions components/prism-typescript.js
Expand Up @@ -14,8 +14,9 @@
Prism.languages.typescript.keyword.push(
/\b(?:abstract|as|declare|implements|is|keyof|readonly|require)\b/,
// keywords that have to be followed by an identifier
// eslint-disable-next-line regexp/no-dupe-characters-character-class
/\b(?:asserts|infer|interface|module|namespace|type)(?!\s*[^\s_${}*a-zA-Z\xA0-\uFFFF])/
/\b(?:asserts|infer|interface|module|namespace|type)\b(?=\s*(?:[{_$a-zA-Z\xA0-\uFFFF]|$))/,
// This is for `import type *, {}`
/\btype\b(?=\s*(?:[\{*]|$))/
);

// doesn't work with TS because TS is too complex
Expand Down
2 changes: 1 addition & 1 deletion components/prism-typescript.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 51 additions & 0 deletions tests/languages/typescript/issue3000.test
@@ -0,0 +1,51 @@
import { infer, inference, infer } from 'module'
// ~~~~~ ✅

import { type, typeDefs, type } from 'module'
// ~~~~ ✅

import { const, constants, const } from 'module'
// ~~~~~ ✅

----------------------------------------------------

[
["keyword", "import"],
["punctuation", "{"],
" infer",
["punctuation", ","],
" inference",
["punctuation", ","],
" infer ",
["punctuation", "}"],
["keyword", "from"],
["string", "'module'"],

["comment", "// ~~~~~ ✅"],

["keyword", "import"],
["punctuation", "{"],
" type",
["punctuation", ","],
" typeDefs",
["punctuation", ","],
" type ",
["punctuation", "}"],
["keyword", "from"],
["string", "'module'"],

["comment", "// ~~~~ ✅"],

["keyword", "import"],
["punctuation", "{"],
["keyword", "const"],
["punctuation", ","],
" constants",
["punctuation", ","],
["keyword", "const"],
["punctuation", "}"],
["keyword", "from"],
["string", "'module'"],

["comment", "// ~~~~~ ✅"]
]

0 comments on commit 212e0ef

Please sign in to comment.