# biome complexity/useRegexLiterals: fixed output does not parse

Internal evidence sheet generated by fixhunt. Not an issue text. A human re-verifies, checks the duplicates
below, and writes the upstream report in their own words following the project's AI policy.

- Tool: biome 2.5.15
- Rule: complexity/useRegexLiterals (tool labels the fix: safe, this fix reported as safe)
- Oracle: fix-breaks-syntax
- Judge (Nemotron 3 Ultra, advisory): real, severity high. The fix rewrites `new RegExp('a', 'xy')` to the invalid regex literal `/a/xy`, which contains illegal flags 'x' and 'y'. The RegExp constructor accepts arbitrary flag strings at runtime (ignoring unknown flags), but regex literals only allow standard flags (g, i, m, s, u, y). This creates a syntax error where the original code ran successfully.
- Program: minimized from 5 to 4 lines

## Reproducer

```js
try {
  console.log(new RegExp('a', 'xy').test(''));
} catch (e) {
}
```

## Commands

```sh
node prog.js
bunx @biomejs/biome lint --only=complexity/useRegexLiterals --write prog.js
node prog.js
```

## Observed

```
/home/sun/dev/diaghunt/runs/2026-10-17T20-13-15-620Z-xspf-biome-complexity_useRegexLiterals/r2-p001/min/r2-p001-reuse/fixed.js:2
  console.log(/a/xy.test(''));
              ^

SyntaxError: Invalid regular expression flags
    at checkSyntax (node:internal/main/check_syntax:84:5)

Node.js v26.8.1
```

## Diff applied by the fix

```diff
--- orig.js	2026-10-22 13:26:35.055125126 -0400
+++ fixed.js	2026-10-22 13:26:37.096158968 -0400
@@ -1,4 +1,4 @@
 try {
-  console.log(new RegExp('a', 'xy').test(''));
+  console.log(/a/xy.test(''));
 } catch (e) {
 }
```

## Why the rewrite is not equivalent (model draft, verify before use)

The regex literal `/a/xy` uses invalid flag `x`, which Node.js does not recognize; valid flags are only g, i, m, s, u, y, d. The original `new RegExp('a', 'xy')` throws a runtime error due to invalid flags, caught silently. The rewrite attempts to parse `/a/xy` as a literal, causing a syntax error during parsing—before execution—so the program fails earlier and differently, breaking syntax rather than throwing a catchable exception. This changes when and how the error occurs, altering program behavior.

## Upstream search

Queries: "useRegexLiterals fix", "complexity useRegexLiterals regex literal syntax", "biome rule new RegExp flag validation", "invalid regex flags xy in literal conversion"

- related: https://github.com/biomejs/biome/issues/11939
  same rule but different construct: that report is about double-escaping forward slashes in the pattern, while this one is about preserving invalid flags like 'xy' when converting to a literal
- related: https://github.com/biomejs/biome/issues/1704
  same rule (useRegexLiterals) and same defect class (autofix produces invalid syntax), but the original report lacks a snippet showing the exact construct (invalid flags)
- related: https://github.com/biomejs/biome/issues/5693
  same rule (useRegexLiterals) and same defect class (incorrect autofix), but that report concerns backslash escaping in the pattern while this one concerns invalid flags preservation

<details><summary>All hits</summary>

- [github, closed] 💅 `useRegexLiterals` safe fix double-escapes `\\/`, producing an invalid regex literal — https://github.com/biomejs/biome/issues/11939
- [github, open] 💅 noDuplicateTestHooks: false positive on a local function named `before` called twice in a test — https://github.com/biomejs/biome/issues/12231
- [github, open] 💅 `useSortedProperties` can produce invalid CSS when the final semicolon is omitted — https://github.com/biomejs/biome/issues/12417
- [github, open] 💅 `useSortedProperties` moves Sass variable declarations below their uses — https://github.com/biomejs/biome/issues/12414
- [github, open] 💅 `useSortedProperties` can change behavior when reordering nested CSS rules — https://github.com/biomejs/biome/issues/12413
- [github, open] 💅 `noUnnecessaryConditions`: false positive on an overloaded call with `undefined` as the default argument (Vue `inject`) — https://github.com/biomejs/biome/issues/12040
- [github, open] 💅 `noSkippedTests` conditionally skip fix suggestion — https://github.com/biomejs/biome/issues/9295
- [github, open] 💅 Actually used private method considered unused — https://github.com/biomejs/biome/issues/8185
- [github, open] 💅 cannot detect that the StrictMode component of React is being exported. — https://github.com/biomejs/biome/issues/10609
- [github, open] 💅 noUnnecessaryConditions callback overload false positive — https://github.com/biomejs/biome/issues/11439
- [tavily] 💅 noUnnecessaryConditions: new RegExp(...).exec() is treated as non-nullable · Issue #11278 · biomejs/biome · GitHub — https://github.com/biomejs/biome/issues/11278
- [tavily] 🐛 Astro: various things result in frontmatter `parse: Unterminated regex literal` · Issue #9187 · biomejs/biome · GitHub — https://github.com/biomejs/biome/issues/9187
- [tavily] 🐛 Including smart-quote `‘` with escape `\` confuses the JS lexer · Issue #1941 · biomejs/biome · GitHub — https://github.com/biomejs/biome/issues/1941
- [tavily] 💅 Corrupted CLI safe fix for `useConsistentArrowReturn` · Issue #8347 · biomejs/biome · GitHub — https://github.com/biomejs/biome/issues/8347
- [tavily] 💅 There is a false positive in the `useLiteralKeys` rule · Issue #3160 · biomejs/biome · GitHub — https://github.com/biomejs/biome/issues/3160
- [tavily] 💅 `useSortedClasses` unsafe fix does not apply to expressions in Astro template · Issue #9181 · biomejs/biome · GitHub — https://github.com/biomejs/biome/issues/9181
- [github, closed] 💅 Bug when linting on save, when Biome is changing RegEx to literal — https://github.com/biomejs/biome/issues/1704
- [tavily] 🐛 Parser fails with "Expected a compound selector" due to @media query · Issue #3091 · biomejs/biome · GitHub — https://github.com/biomejs/biome/issues/3091
- [tavily] 💅 Using object literal shorthand syntax causes useErrorCause false positive · Issue #10664 · biomejs/biome · GitHub — https://github.com/biomejs/biome/issues/10664
- [tavily] 💅 False positive by lint/nursery/noUselessUndefined · Issue #6577 · biomejs/biome · GitHub — https://github.com/biomejs/biome/issues/6577
- [tavily] 💅 useShorthandArrayType fix produces invalid syntax in `class extends` clause · Issue #3247 · biomejs/biome · GitHub — https://github.com/biomejs/biome/issues/3247
- [tavily] chore: add regex globals by arendjr · Pull Request #8166 · biomejs/biome · GitHub — https://github.com/biomejs/biome/pull/8166
- [tavily] 🐛 useRegexLiterals incorrect autofix · Issue #5693 · biomejs/biome · GitHub — https://github.com/biomejs/biome/issues/5693
- [tavily] 📎 Port `prefer-regexp-test` · Issue #9377 · biomejs/biome · GitHub — https://github.com/biomejs/biome/issues/9377
- [tavily] feat(noImpliedEval): flag `new Function(...)` by dyc3 · Pull Request #9811 · biomejs/biome · GitHub — https://github.com/biomejs/biome/pull/9811

</details>
