regexp literal after for/if/while header causes SyntaxError in js_parse_skip_parens_token
Maintainers usually reply within 5 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 48/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- c, javascript
- Domain
- compilers
Research direction
Start by reading js_parse_skip_parens_token(), is_regexp_allowed(), and js_parse_regexp() in the parser; the issue identifies these as the paths involved in the incorrect lookahead and pending exception. Reproduce with the supplied snippets and trace how parsing handles / after each listed header. Done means all snippets parse and the IIFE leaves no pending syntax error.
Written by the indexing model from the issue text.
Description
var f1 = (fn = function(e){ for (var r in e) /data-/gi.test(r); var s = "#"; }) => fn;
var f2 = (fn = function(){ for (var x in {a:1}) /[)]/.test(x); }) => fn;
var f3 = (fn = function(){ if (1) /[)]/.test(")"); }) => fn;
var f4 = (fn = function(){ while (0) /[)]/.test(")"); }) => fn;
var f5 = (fn = function(){ with ({}) /[)]/.test(")"); }) => fn;
var f6 = (fn = async function(){ for await (var x of [1]) /[)]/.test(")"); }) => fn;
All the valid snippets above fail to parse with SyntaxError: expecting ';'. In addition, for an IIFE like:
(function(e){ for (var r in e) /data-/gi.test(r); var s = "#"; })({a:1});
JS_Eval() succeeds, but JS_GetException(ctx) still returns a pending SyntaxError: unexpected end of regexp.
The root cause is that is_regexp_allowed(')') always returns FALSE inside js_parse_skip_parens_token(). However, after the closing ) of a for (...), for await (...), if (...), while (...), or with (...) header, a statement follows and / starts a regexp literal rather than division. Treating / as division breaks paren matching during lookahead and also leaves an uncleared exception in rt->current_exception when js_parse_regexp() fails. Could you help look into fixing this?
- Dominant language
- C
- Stars
- 11.1k
- Forks
- 1.2k
- PR merge metrics
- No merged PRs in 30d
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from bellard/quickjs
-
Difficulty 1/5 Under an hour Newbie friendliness 75/100
Maintainers usually reply within 5 days
-
RegExp: patterns with more than 255 capture groups fail with "too many captures"Possibly taken @andreasrosdal claimed this 3 days ago. Open
Difficulty 4/5 3-5 days Newbie friendliness 25/100
bellard/quickjs#624 · 1 comment ·
Maintainers usually reply within 5 days
-
(comment on #611) `function g(a, d = (a = 10)) { return a; }` returns the argument instead of 10Open
Difficulty 4/5 3-5 days Newbie friendliness 30/100
Maintainers usually reply within 5 days
-
Difficulty 4/5 3-5 days Newbie friendliness 30/100
Maintainers usually reply within 5 days
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
bellard/quickjs#611 · 1 comment ·
Maintainers usually reply within 5 days
Similar issues
-
documentation good first issue help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
JulianKemmerer/PipelineC#409 ·
-
Linux build fails without libspeechd-dev, which INSTALL.md doesn't list and CMake reports as foundOpen
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
-
needs-playtest slice
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Life-Framework/Life-Framework#4861 ·
Maintainers usually reply within 1 day