Skip to content

Fix '/' after a template literal in the arrow function lookahead - #1887

Open
trackoor wants to merge 1 commit into
quickjs-ng:masterfrom
trackoor:fix-template-division-arrow
Open

trackoor wants to merge 1 commit into
quickjs-ng:masterfrom
trackoor:fix-template-division-arrow

Conversation

@trackoor

@trackoor trackoor commented Nov 4, 2026

Copy link
Copy Markdown

js_parse_skip_parens_token() decides whether '/' starts a regexp from
the previous token, and is_regexp_allowed() did not list TOK_TEMPLATE.
After a complete template literal the '/' is a division, but it was
scanned as a regexp that hid the rest of the parenthesized list, so
(a = 8 / 2) => a failed with "expecting ';'". When the bogus
regexp was unterminated, as in (t / 2), the expression was
evaluated correctly but a deferred "unexpected line terminator in
regexp" SyntaxError was left pending and reported after the script
ran (the same symptom as the private field case fixed earlier).

Treat a complete template as an operand. A template part ending in
'${' is followed by an expression, where a regexp may start, so it is
handled like '('.

Fixes #1886

js_parse_skip_parens_token() decides whether '/' starts a regexp from
the previous token, and is_regexp_allowed() did not list TOK_TEMPLATE.
After a complete template literal the '/' is a division, but it was
scanned as a regexp that hid the rest of the parenthesized list, so
`(a = `8` / 2) => a` failed with "expecting ';'". When the bogus
regexp was unterminated, as in `(`t` / 2)`, the expression was
evaluated correctly but a deferred "unexpected line terminator in
regexp" SyntaxError was left pending and reported after the script
ran (the same symptom as the private field case fixed earlier).

Treat a complete template as an operand. A template part ending in
'${' is followed by an expression, where a regexp may start, so it is
handled like '('.

This branch has not been deployed

No deployments
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.

/ after a template literal inside parentheses is scanned as a regexp: (a = 8 / 2) => a is a SyntaxError

1 participant