Skip to content

Fix regex literals starting with equals#36

Open
davejcameron wants to merge 1 commit into
dy:mainfrom
davejcameron:dc.subscript-regex-equals
Open

Fix regex literals starting with equals#36
davejcameron wants to merge 1 commit into
dy:mainfrom
davejcameron:dc.subscript-regex-equals

Conversation

@davejcameron
Copy link
Copy Markdown
Contributor

@davejcameron davejcameron commented May 14, 2026

Problem

Regex literals whose pattern starts with = are valid in expression positions, but the parser rejects them before reading the regex body.

value.replace(/=/g, "")
value.replace(/=>/g, ":")

Those should parse and evaluate as regex literals, while compound assignment such as a /= b should still parse as assignment.

Fix

Allow = as the first regex pattern character when the / token is parsed in a prefix-expression position. The existing left-operand check still leaves division and /= assignment handling to their operator parsers.

Add focused regex feature coverage for replace(/=/g, ...) and replace(/=>/g, ...).

Validation

  • node --input-type=module -e 'import { parse } from "./subscript.js"; import "./feature/regex.js"; console.log(JSON.stringify(parse("x.replace(/=/g, \\\"\\\")"))); console.log(JSON.stringify(parse("x.replace(/=>/g, \\\":\\\")"))); console.log(JSON.stringify(parse("a /= b")))'
  • node --import ./test/https-loader.js test/feature/regex.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant