Skip to content

Stop special-casing ZWNJ and ZWJ in the regexp identity escape tests - #5161

Merged
gibson042 merged 2 commits into
tc39:mainfrom
hexbinoct:zwnj-zwj-id-continue
Nov 6, 2026
Merged

gibson042 merged 2 commits into
tc39:mainfrom
hexbinoct:zwnj-zwj-id-continue

Conversation

@hexbinoct

Copy link
Copy Markdown
Contributor

Fixes #5160.

Unicode 15.1 added U+200C and U+200D to ID_Continue, and tc39/ecma262#3074 removed their special case from the spec. In a non-u RegExp literal without Annex B, a backslash followed by an ID_Continue code unit is an early error, so a backslash followed by ZWNJ is now a SyntaxError, just like /\a/.

S7.8.5_A1.4_T2.js and S7.8.5_A2.4_T2.js accept a SyntaxError only when the code unit is in ID_Continue, and they still listed ZWNJ and ZWJ next to $ as exceptions that must parse. This PR leaves $ as the only exception, since it is still an IdentifierPart that is not ID_Continue.

The tests now pass whichever Unicode version an engine uses: ZWNJ may parse (before 15.1) or throw (15.1 and later).

Every engine in CI implements the Annex B IdentityEscape grammar and never throws here, so none of them shows the failure. To check the change, I ran both tests under a wrapper around eval that rejects a backslash followed by any ID_Continue code unit, the way an engine without Annex B would. The current tests fail at U+200C and the new ones pass. They also pass when ZWNJ and ZWJ are treated as pre-15.1 (not ID_Continue). And they still fail when the wrapper also wrongly rejects \$. Lint is clean, and both tests pass on Node and engine262.

LLM disclosure: Claude Opus 5.5 helped me write and check this change; I reviewed the result.

@hexbinoct
hexbinoct requested a review from a team as a code owner November 2, 2026 14:10
@github-actions

github-actions Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

2 new or modified tests were run on 7 engines.

View workflow run

Test Engine262 GraalJS JavaScriptCore QuickJS SpiderMonkey V8 XS
language/literals/regexp/S7.8.5_A1.4_T2.js ❌ ✅ ✅ ✅ ✅ ✅ ✅
language/literals/regexp/S7.8.5_A2.4_T2.js ❌ ✅ ✅ ✅ ✅ ✅ ✅

Comment on lines 13 to 23

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var LineTerminator = ((cu === 0x000A) || (cu === 0x000D) || (cu === 0x2028) || (cu === 0x2029));
if (LineTerminator === false) {

@hexbinoct

Copy link
Copy Markdown
Contributor Author

Thanks, applied all four in 8c7e30e. With Elimination gone, the 11 syntax characters it used to skip are now checked too, and both tests still pass on Node and engine262 and in the no-Annex-B model from the description.

hexbinoct and others added 2 commits November 6, 2026 10:28
Unicode 15.1 added U+200C and U+200D to ID_Continue, and ecma262 dropped their special case in tc39/ecma262#3074. Without Annex B, a backslash followed by either one is now an early error in a non-u RegExp literal, like any other ID_Continue code unit. These two tests still required both to parse, so they failed on such an engine.

Only $ remains an IdentifierPart that is not ID_Continue.
Drop the Elimination list, since the code unit is always backslash
escaped, and explain when a SyntaxError is acceptable.

Co-authored-by: Richard Gibson <1199584+gibson042@users.noreply.github.com>
@gibson042
gibson042 force-pushed the zwnj-zwj-id-continue branch from 8c7e30e to 1de958b Compare November 6, 2026 15:28
@gibson042
gibson042 merged commit e4fbf57 into tc39:main Nov 6, 2026
24 of 25 checks 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.

Handling <ZWNJ> and <ZWJ> as ID_CONTINUE

3 participants