Skip to content

Report the correct column number for syntax errors#1582

Merged
saghul merged 1 commit into
quickjs-ng:masterfrom
littledivy:fix/parse-error-column
Jul 17, 2026
Merged

Report the correct column number for syntax errors#1582
saghul merged 1 commit into
quickjs-ng:masterfrom
littledivy:fix/parse-error-column

Conversation

@littledivy

Copy link
Copy Markdown
Contributor

A SyntaxError always reported column 1, regardless of where the offending token was. s->col_num is not advanced during normal token scanning (it stays 1 except on a few number-literal error paths), and the line came from the parser state rather than the token, so the column (and occasionally the line) was wrong.

The fix reports the token's line and computes the column as the 1-based offset of the token from the start of its source line.

source before after
hocuspocus( 1:1 1:12
let x = ; 1:1 1:9
1 + + ; 1:1 1:7
let z = @ on line 2 2:1 2:9

Disclaimer: This is an AI-assisted patch from the v8x project.

Comment thread quickjs.c Outdated
backtrace_flags = 0;
if (s->cur_func && s->cur_func->backtrace_barrier)
backtrace_flags = JS_BACKTRACE_FLAG_SINGLE_LEVEL;
// v82jsc patch: report the V8-compatible 1-based column of the offending

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you please reword this comment to be more on point? Also use /* */

@littledivy littledivy Jul 17, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

reworded to a single comment about deriving the column from the token offset.

A SyntaxError always reported column 1, regardless of where the offending
token was. s->col_num is not advanced during normal token scanning (it
stays 1 except on a few number-literal error paths), and the line number
was taken from the parser state rather than the token, so both the column
and occasionally the line were wrong.

Report the token's line and compute the column as the 1-based offset of the
token from the start of its source line, so e.g. `hocuspocus(` now points at
1:12 instead of 1:1.
@littledivy
littledivy force-pushed the fix/parse-error-column branch from 6b8ba6f to a342b99 Compare July 17, 2026 13:06
@saghul
saghul merged commit 65e766e into quickjs-ng:master Jul 17, 2026
128 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.

2 participants