Bug reportNov 8, 2026· 0:21· 12 views
Monaco Editor 0.57.0: '/' inside regex [...] breaks tokenizer — string.invalid highlight
0:21 total
Comments · 0
Be the first to comment.
Bug reportby SceneRecap AI
mediumMonaco JavaScript/TypeScript Monarch tokenizer (basic-languages typescript/javascript): regex literal state handling of character classes [...] and the 'v' regex flag.
os: macOSdpr: 1locale: en-USbrowser: Chromium 151.0.7922.34timezone: Europe/Berlinviewport: 1280x720issue_ref: microsoft/monaco-editor#5575monaco_version: 0.57.0 (cdn.jsdelivr.net monaco-editor@0.57.0)
Repro steps
- 1.Open a page that loads Monaco Editor 0.57.0 from cdn.jsdelivr.net with language set to JavaScript.
- 2.Enter 'if (/[/]'/.test(s)) f();' and look at the coloring after the '/' inside [/].
- 3.Enter 'if (/[a/b]/.test(s)) f();' and look at the coloring of '/b]'.
- 4.Enter 'x = /a\/b/v.test(s);' and check whether it is colored as a regex literal.
- 5.As a control, enter 'const re4 = /[abc]+/gi;' and 'const re5 = /[a-z0-9_]+/u;' and compare the coloring.
Expected
A '/' inside a character class [...] is a literal character. The regex should continue until the real closing '/'. Each whole literal, including flags such as 'v', should get regexp token colors, the same as the control lines.
Actual
Line 5 shows string.invalid (red) coloring after the '/' inside [/]. On line 6, '/b]' gets non-regex colors after the '/' inside [a/b]. Line 7 with the 'v' flag produces zero regexp tokens. The control lines 10 and 11, which have no '/' inside [...], are tokenized correctly.
Evidence
visualLine 5 'if (/[/]'/.test(s)) f();' shows red, invalid-looking coloring after the '/' inside [/].
visualLine 6 'if (/[a/b]/.test(s)) f();' shows inconsistent token colors after the '/' inside [a/b].
visualLine 7 'x = /a\/b/v.test(s);' is not colored as a regex literal.
visualControl: lines 10 and 11 ('/[abc]+/gi' and '/[a-z0-9_]+/u') render with correct regex coloring. These lines work as expected.
visualThe result panel reads '✗ Tokenizer bug, lines 5 to 7'. It reports string.invalid (red) on line 5, non-regex colors for '/b]' on line 6, and zero regexp tokens for the 'v' flag on line 7.
visualThe result panel reports that lines 10 to 11, /[abc]+/, are tokenized correctly (control).
consoleThe console warns that the parser-blocking cross site script loader.js from cdn.jsdelivr.net is invoked via document.write. This looks unrelated to the tokenizer bug.
Issue markdown (copy-paste ready)
## Summary In Monaco Editor 0.57.0, a '/' inside a regex character class `[...]` is misread as the regex closing delimiter by the JavaScript tokenizer. A regex using the `v` flag also produces no regexp tokens. Ref: microsoft/monaco-editor#5575. ## Environment - Chromium 151.0.7922.34, macOS - Viewport 1280x720, dpr 1 - monaco-editor@0.57.0 from cdn.jsdelivr.net ## Steps to reproduce 1. Load Monaco 0.57.0 with language JavaScript (0s). 2. Enter the following lines (1.0s): ```js if (/[/]'/.test(s)) f(); if (/[a/b]/.test(s)) f(); x = /a\/b/v.test(s); ``` 3. Control (1.0s): ```js const re4 = /[abc]+/gi; const re5 = /[a-z0-9_]+/u; ``` ## Expected A '/' inside `[...]` is a literal character. Each regex literal, including its flags such as `v`, gets regexp token colors, the same as the control lines. ## Actual - Line 5: string.invalid (red) coloring after the '/' in `[/]` (1.0s, confirmed by the result panel at 11.0s). - Line 6: `/b]` gets non-regex colors after the '/' in `[a/b]` (1.0s, 11.0s). - Line 7: the `v` flag regex produces zero regexp tokens (1.0s, 11.0s). ## Control Lines 10 and 11 (`/[abc]+/gi`, `/[a-z0-9_]+/u`) are tokenized correctly (1.0s, 11.0s). ## Notes At 0s the console warns that loader.js is a parser-blocking cross site script invoked via document.write. This appears unrelated. ## Suggested area The Monarch JS/TS tokenizer regexp state. It should handle character classes and accept the `v` flag. *Recorded with SceneRecap.*
Your recordings could explain themselves too.
Free plan · silent recordings welcome · bug reports included.
Try SceneRecap free →