Enhance definitions in TypeScript component (#1522) Add missing keywords & built-ins to the TypeScript definition.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
diff --git a/components/prism-typescript.js b/components/prism-typescript.js
index fc8f288..78a6e1b 100644
--- a/components/prism-typescript.js
+++ b/components/prism-typescript.js
@@ -1,7 +1,7 @@
Prism.languages.typescript = Prism.languages.extend('javascript', {
// From JavaScript Prism keyword list and TypeScript language spec: https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#221-reserved-words
- 'keyword': /\b(?:as|async|await|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally|for|from|function|get|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|set|static|super|switch|this|throw|try|typeof|var|void|while|with|yield|module|declare|constructor|namespace|abstract|require|type)\b/,
- 'builtin': /\b(?:string|Function|any|number|boolean|Array|symbol|console)\b/,
+ 'keyword': /\b(?:abstract|as|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|var|void|while|with|yield)\b/,
+ 'builtin': /\b(?:string|Function|any|number|boolean|Array|symbol|console|Promise|unknown|never)\b/,
});
-Prism.languages.ts = Prism.languages.typescript;
\ No newline at end of file
+Prism.languages.ts = Prism.languages.typescript;
diff --git a/components/prism-typescript.min.js b/components/prism-typescript.min.js
index bded558..f406c6b 100644
--- a/components/prism-typescript.min.js
+++ b/components/prism-typescript.min.js
@@ -1 +1 @@
-Prism.languages.typescript=Prism.languages.extend("javascript",{keyword:/\b(?:as|async|await|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally|for|from|function|get|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|set|static|super|switch|this|throw|try|typeof|var|void|while|with|yield|module|declare|constructor|namespace|abstract|require|type)\b/,builtin:/\b(?:string|Function|any|number|boolean|Array|symbol|console)\b/}),Prism.languages.ts=Prism.languages.typescript;
\ No newline at end of file
+Prism.languages.typescript=Prism.languages.extend("javascript",{keyword:/\b(?:abstract|as|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|var|void|while|with|yield)\b/,builtin:/\b(?:string|Function|any|number|boolean|Array|symbol|console|Promise|unknown|never)\b/}),Prism.languages.ts=Prism.languages.typescript;
\ No newline at end of file
diff --git a/tests/languages/typescript/builtin_feature.test b/tests/languages/typescript/builtin_feature.test
index f0f23f9..6430d93 100644
--- a/tests/languages/typescript/builtin_feature.test
+++ b/tests/languages/typescript/builtin_feature.test
@@ -6,6 +6,9 @@ boolean
Array
symbol
console
+Promise
+unknown
+never
----------------------------------------------------
@@ -17,7 +20,10 @@ console
["builtin", "boolean"],
["builtin", "Array"],
["builtin", "symbol"],
- ["builtin", "console"]
+ ["builtin", "console"],
+ ["builtin", "Promise"],
+ ["builtin", "unknown"],
+ ["builtin", "never"]
]
----------------------------------------------------
diff --git a/tests/languages/typescript/keyword_feature.test b/tests/languages/typescript/keyword_feature.test
index e94154e..9e19b36 100644
--- a/tests/languages/typescript/keyword_feature.test
+++ b/tests/languages/typescript/keyword_feature.test
@@ -1,10 +1,16 @@
+abstract
+as
+async
+await
break
case
catch
class;
const
+constructor
continue
debugger
+declare
default
delete
do
@@ -14,6 +20,7 @@ export
extends;
finally
for
+from
function
get
if
@@ -22,14 +29,21 @@ import
in
instanceof;
interface;
+is
+keyof
let
+module
+namespace
new;
null
+of
package
private
protected
public
+readonly
return
+require
set
static
super
@@ -37,27 +51,30 @@ switch
this
throw
try
+type
typeof
var
void
while
with
yield
-module
-declare
-constructor
-enum
----------------------------------------------------
[
+ ["keyword", "abstract"],
+ ["keyword", "as"],
+ ["keyword", "async"],
+ ["keyword", "await"],
["keyword", "break"],
["keyword", "case"],
["keyword", "catch"],
["keyword", "class"], ["punctuation", ";"],
["keyword", "const"],
+ ["keyword", "constructor"],
["keyword", "continue"],
["keyword", "debugger"],
+ ["keyword", "declare"],
["keyword", "default"],
["keyword", "delete"],
["keyword", "do"],
@@ -67,6 +84,7 @@ enum
["keyword", "extends"], ["punctuation", ";"],
["keyword", "finally"],
["keyword", "for"],
+ ["keyword", "from"],
["keyword", "function"],
["keyword", "get"],
["keyword", "if"],
@@ -75,14 +93,21 @@ enum
["keyword", "in"],
["keyword", "instanceof"], ["punctuation", ";"],
["keyword", "interface"], ["punctuation", ";"],
+ ["keyword", "is"],
+ ["keyword", "keyof"],
["keyword", "let"],
+ ["keyword", "module"],
+ ["keyword", "namespace"],
["keyword", "new"], ["punctuation", ";"],
["keyword", "null"],
+ ["keyword", "of"],
["keyword", "package"],
["keyword", "private"],
["keyword", "protected"],
["keyword", "public"],
+ ["keyword", "readonly"],
["keyword", "return"],
+ ["keyword", "require"],
["keyword", "set"],
["keyword", "static"],
["keyword", "super"],
@@ -90,16 +115,13 @@ enum
["keyword", "this"],
["keyword", "throw"],
["keyword", "try"],
+ ["keyword", "type"],
["keyword", "typeof"],
["keyword", "var"],
["keyword", "void"],
["keyword", "while"],
["keyword", "with"],
- ["keyword", "yield"],
- ["keyword", "module"],
- ["keyword", "declare"],
- ["keyword", "constructor"],
- ["keyword", "enum"]
+ ["keyword", "yield"]
]
----------------------------------------------------