Skip to content

Fix regex literals starting with equals#36

Merged
dy merged 1 commit into
dy:mainfrom
davejcameron:dc.subscript-regex-equals
May 18, 2026
Merged

Fix regex literals starting with equals#36
dy merged 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

@dy dy merged commit a488b56 into dy:main May 18, 2026
1 check passed
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.

2 participants