Skip to content

Commit

Permalink
Enhance definitions in TypeScript component (#1522)
Browse files Browse the repository at this point in the history
Add missing keywords & built-ins to the TypeScript definition.
  • Loading branch information
MichalLytek authored and mAAdhaTTah committed Oct 18, 2018
1 parent 716923f commit 1169562
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 14 deletions.
6 changes: 3 additions & 3 deletions components/prism-typescript.js
Original file line number Diff line number Diff line change
@@ -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;
Prism.languages.ts = Prism.languages.typescript;
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.

8 changes: 7 additions & 1 deletion tests/languages/typescript/builtin_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ boolean
Array
symbol
console
Promise
unknown
never

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

Expand All @@ -17,7 +20,10 @@ console
["builtin", "boolean"],
["builtin", "Array"],
["builtin", "symbol"],
["builtin", "console"]
["builtin", "console"],
["builtin", "Promise"],
["builtin", "unknown"],
["builtin", "never"]
]

----------------------------------------------------
Expand Down
40 changes: 31 additions & 9 deletions tests/languages/typescript/keyword_feature.test
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
abstract
as
async
await
break
case
catch
class;
const
constructor
continue
debugger
declare
default
delete
do
Expand All @@ -14,6 +20,7 @@ export
extends;
finally
for
from
function
get
if
Expand All @@ -22,42 +29,52 @@ 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
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"],
Expand All @@ -67,6 +84,7 @@ enum
["keyword", "extends"], ["punctuation", ";"],
["keyword", "finally"],
["keyword", "for"],
["keyword", "from"],
["keyword", "function"],
["keyword", "get"],
["keyword", "if"],
Expand All @@ -75,31 +93,35 @@ 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"],
["keyword", "switch"],
["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"]
]

----------------------------------------------------
Expand Down

0 comments on commit 1169562

Please sign in to comment.