Commit 11695629f12925c586702453beaee5f4825d0ebd

Michał Lytek 2018-10-18T20:34:53

Enhance definitions in TypeScript component (#1522) Add missing keywords & built-ins to the TypeScript definition.

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"]
 ]
 
 ----------------------------------------------------