microsoft / microsoft/monaco-editor

[Bug] Syntax Highlighting Issue with Regex Containing Backtick in JavaScript

Open
#4,382 0 comments 0 reactions 0 assignees View on GitHub

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?
Monaco Editor Playground Link

https://microsoft.github.io/monaco-editor/playground.html?source=v0.46.0#XQAAAAJAAwAAAAAAAABBqQkHQ5NjdMjwa-jY7SIQ9S7DNlzs5W-mwj0fe1ZCDRFc9ws9XQE0SJE1jc2VKxhaLFIw9vEWSxW3yscw3IMC3VciAKctgAboa7AaZZDHLgrLqPRv_fRv2RyIokydlTdTYccsu6v6jDrc8jQ8uzS17Jr6ID5LHt078cBAh08bwxhURTLWW1DJ-Z_eJmjdyZZqCwPJSH7_evR3VFlrSo2VjQD6oKYXwTN7rGPig3-4dDo7LrvjGsWpvU-2FEw7PfULuwf0gELP-zcNF0yVfZ8K7aRSHJ625IvzvAlzVVBhNCyfB2MBSn6HG8Eb0O67JUM989mK50LKpP7lyocU1BimhlnxRmA5JOO3U9YjG3aa7jwrHABvrrAZLrcThlFgg3_kUanXF3kf8eTPK2oLpsifL15HzcsaH2tZVT41x89eL3spQTSPkUePBNRO0Zon3ROkgjsWKOn-uYiAxaN7M5vZKDWQFyWNpRlYaD_-dseGKxwv8wbji8_588TWFdOTP6kYeucgKTOLkvqR-DlL5MhKK6Bz4FxI771Qe9h3mK3soRkC952KrqN24DYpboedafcvfiSf4DQS6zHYxGkN6Rqc62ZpgxjzCKEGEnolkPMTcYKVUVo3NAYhRYQptfypFDZh9Z0bvsjHKRGjHnqEe1cr_cQNp3opv5Ld2XaemP9EnoIA

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
  1. Put the editor in Javascript mode.
  2. Assign the following regex to an object property.

/^[^%$`+'[<>~/"^]\]+$/

  1. 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.

image

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:
image

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.