Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeScript: Updated keywords #2861

Merged
merged 1 commit into from May 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 7 additions & 2 deletions components/prism-typescript.js
Expand Up @@ -7,11 +7,16 @@
greedy: true,
inside: null // see below
},
// From JavaScript Prism keyword list and TypeScript language spec: https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#221-reserved-words
'keyword': /\b(?:abstract|as|asserts|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|undefined|var|void|while|with|yield)\b/,
'builtin': /\b(?:string|Function|any|number|boolean|Array|symbol|console|Promise|unknown|never)\b/,
});

// The keywords TypeScript adds to JavaScript
Prism.languages.typescript.keyword.push(
/\b(?:abstract|as|declare|implements|is|keyof|readonly|require)\b/,
// keywords that have to be followed by an identifier
/\b(?:asserts|infer|interface|module|namespace|type)(?!\s*[^\s_${}*a-zA-Z\xA0-\uFFFF])/
)

// doesn't work with TS because TS is too complex
delete Prism.languages.typescript['parameter'];

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.

37 changes: 37 additions & 0 deletions tests/languages/typescript/issue2860.test
@@ -0,0 +1,37 @@
export interface R<T> {
data: T;
total: number;
type?: string;
}

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

[
["keyword", "export"],
["keyword", "interface"],
["class-name", [
["constant", "R"],
["operator", "<"],
["constant", "T"],
["operator", ">"]
]],
["punctuation", "{"],

"\r\n data",
["operator", ":"],
["constant", "T"],
["punctuation", ";"],

"\r\n total",
["operator", ":"],
["builtin", "number"],
["punctuation", ";"],

"\r\n type",
["operator", "?"],
["operator", ":"],
["builtin", "string"],
["punctuation", ";"],

["punctuation", "}"]
]