Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/languages/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,13 @@ export default function(hljs) {
nextChar === "<" ||
// the , gives away that this is not HTML
// `<T, A extends keyof T, V>`
nextChar === ","
nextChar === "," ||
// TypeScript type assertion with array notation
// `<string[]>`, `<number[]>`, `<T[]>`, etc.
nextChar === "[" ||
// TypeScript optional type assertion
// `<string?>`, etc.
nextChar === "?"
) {
response.ignoreMatch();
return;
Expand Down Expand Up @@ -86,6 +92,13 @@ export default function(hljs) {
return;
}
}

// TypeScript type assertions with whitespace before brackets or question mark
// `<string []>`, `<T []>`, `<string ?>`, `<T ?>`
if ((m = afterMatch.match(/^\s*\[\]/)) || (m = afterMatch.match(/^\s+\?/))) {
response.ignoreMatch();
return;
}
}
};
const KEYWORDS = {
Expand Down