microsoft / microsoft/monaco-editor
[Bug] Syntax Highlighting Issue with Regex Containing Backtick in JavaScript
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 46.8k
- Forks
- 4.1k
- Avg merge
- 17h 58m
- Merged PRs (30d)
- 1
Description
Reproducible in vscode.dev or in VS Code Desktop?
- Not reproducible in vscode.dev or VS Code Desktop
Reproducible in the monaco editor playground?
- Not reproducible in the monaco editor playground
Monaco Editor Playground Link
Monaco Editor Playground Code
const obj = {
regex: /^[^%$`+'\[<>~/"^\]\\]+$/
};
// Sample function to highlight normal syntax usage
function sampleFunction() {
console.log("This should be highlighted as a function call.");
}
// Variable declaration to show syntax highlighting
const exampleVar = "This text should be highlighted as a string.";
// Another regex to show that syntax highlighting works outside the problematic regex
const anotherRegex = /^[\w\s]+$/;
sampleFunction();
console.log(exampleVar);
console.log(anotherRegex);
Reproduction Steps
- Put the editor in Javascript mode.
- Assign the following regex to an object property.
/^[^%$`+'[<>~/"^]\]+$/
- Include some additional code following the object containing the property assigned the regex value, to clearly demonstrate the issue where subsequent code lacks proper syntax highlighting
Actual (Problematic) Behavior
Upon encountering the backtick (`) within the regex (/^[^%$`+'[<>~/"^]\]+$/), the syntax highlighter malfunctions, mistakenly treating the code segment from the backtick onward as a string literal.
Expected Behavior
The expected behavior is for the syntax highlighter to accurately recognize and highlight the entire regular expression, including and following the backtick (`), as part of the regex pattern, without mistaking it for the beginning of a string literal. This ensures that the remaining code following the regex is unaffected and properly highlighted, mirroring the functionality observed in vscode.dev, where similar patterns are correctly interpreted and highlighted.
Additional Context
Correct syntax highlighting in vscode.dev:
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked Monaco Editor Playground reproduction in JavaScript mode and inspect highlighting after the regex containing a backtick. Compare the affected code with the vscode.dev behavior; done means the full regex is highlighted correctly and subsequent function, string, and variable code retains proper syntax highlighting.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100