mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-26 09:33:49 +01:00
Merge pull request #2451 from neuralsim/fixSyntaxHighlighting
fixed syntax highlighting (don't highlight partial tokens/keywords)
This commit is contained in:
commit
ff15d2d730
@ -288,13 +288,15 @@ export function Root(props: IProps): React.ReactElement {
|
|||||||
.getLanguages()
|
.getLanguages()
|
||||||
.find((l: any) => l.id === "javascript")
|
.find((l: any) => l.id === "javascript")
|
||||||
.loader();
|
.loader();
|
||||||
l.language.tokenizer.root.unshift(["ns", { token: "ns" }]);
|
// replaced the bare tokens with regexes surrounded by \b, e.g. \b{token}\b which matches a word-break on either side
|
||||||
for (const symbol of symbols) l.language.tokenizer.root.unshift([symbol, { token: "netscriptfunction" }]);
|
// this prevents the highlighter from highlighting pieces of variables that start with a reserved token name
|
||||||
|
l.language.tokenizer.root.unshift([new RegExp('\\bns\\b'), { token: "ns" }]);
|
||||||
|
for (const symbol of symbols) l.language.tokenizer.root.unshift([new RegExp(`\\b${symbol}\\b`), { token: "netscriptfunction" }]);
|
||||||
const otherKeywords = ["let", "const", "var", "function"];
|
const otherKeywords = ["let", "const", "var", "function"];
|
||||||
const otherKeyvars = ["true", "false", "null", "undefined"];
|
const otherKeyvars = ["true", "false", "null", "undefined"];
|
||||||
otherKeywords.forEach((k) => l.language.tokenizer.root.unshift([k, { token: "otherkeywords" }]));
|
otherKeywords.forEach((k) => l.language.tokenizer.root.unshift([new RegExp(`\\b${k}\\b`), { token: "otherkeywords" }]));
|
||||||
otherKeyvars.forEach((k) => l.language.tokenizer.root.unshift([k, { token: "otherkeyvars" }]));
|
otherKeyvars.forEach((k) => l.language.tokenizer.root.unshift([new RegExp(`\\b${k}\\b`), { token: "otherkeyvars" }]));
|
||||||
l.language.tokenizer.root.unshift(["this", { token: "this" }]);
|
l.language.tokenizer.root.unshift([new RegExp('\\bthis\\b'), { token: "this" }]);
|
||||||
})();
|
})();
|
||||||
|
|
||||||
const source = (libSource + "").replace(/export /g, "");
|
const source = (libSource + "").replace(/export /g, "");
|
||||||
|
Loading…
Reference in New Issue
Block a user