Skip to content

Fix column reporting for invalid number literals - #1498

Merged
saghul merged 2 commits into
quickjs-ng:masterfrom
uxxca1:master
May 21, 2026
Merged

saghul merged 2 commits into
quickjs-ng:masterfrom
uxxca1:master

Conversation

@uxxca1

@uxxca1 uxxca1 commented May 20, 2026 •

Copy link
Copy Markdown
Contributor

next_token() reports invalid number literals before it reaches the common token finalization path, where the token column is normally computed. Because js_parse_error() uses s->col_num for the error backtrace, these syntax errors could point to a stale column instead of the start of the current numeric token.

This updates s->col_num before throwing the invalid number literal error, using the same column calculation as the normal token path.

@uxxca1

uxxca1 commented May 20, 2026 •

Copy link
Copy Markdown
Contributor Author

When I run the following test.js:

function fun() {
    let a = 123bcd;
}

V8(chrome) throws this error:
Uncaught SyntaxError: Invalid or unexpected token (at test:2:13)

But QuickJS reports:
SyntaxError: invalid number literal
at test.js:2:5

This makes it look like QuickJS reports an inaccurate column number in the stack trace when throwing an invalid number literal error.

@saghul

saghul commented May 20, 2026

Copy link
Copy Markdown
Contributor

Can you add a test please?

@uxxca1

uxxca1 commented May 20, 2026

Copy link
Copy Markdown
Contributor Author

I can add a regression test. My plan is to put it in api-test.c, since this checks the exception stack location reported by JS_Eval. It would assert that an invalid number literal like 123bcd reports line 2, column 13. Let me know if you’d prefer this in the JS tests under tests/ instead.

@saghul

saghul commented May 20, 2026

Copy link
Copy Markdown
Contributor

I think it would be simpler and match similar tests to have it in JS.

@uxxca1

uxxca1 commented May 20, 2026

Copy link
Copy Markdown
Contributor Author

Understood. Just to confirm, you’d prefer this as a JS test under tests/ rather than in api-test.c, right? Should I add it to tests/test_language.js, or would a separate test file be better?

@saghul

saghul commented May 20, 2026

Copy link
Copy Markdown
Contributor

Separate test file I think.

@uxxca1

uxxca1 commented May 21, 2026

Copy link
Copy Markdown
Contributor Author

OK. Added a JS regression test under tests/ that checks the reported stack location for an invalid number literal. It fails with the stale column before the fix and passes with the updated tokenizer column handling.

@saghul
saghul merged commit 9584b58 into quickjs-ng:master May 21, 2026
122 of 124 checks passed
@saghul

saghul commented May 21, 2026

Copy link
Copy Markdown
Contributor

GHA is acting up today... unrelated test failures.

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