Repository navigation
JS: a semicolon after a newline still ends the statement - #139
Merged
tdewolff merged 1 commit intoNov 16, 2026
Merged
Conversation
parseStmt only consumed a trailing `;` when no line terminator came
before it, so in `if (a) b\n; else c` and `do a()\n; while (b)` the `;`
became an empty statement and the `else` / `while` failed to parse.
ASI only inserts a semicolon when the next token is not allowed, so for
statements that end with a semicolon (expression, var, return, break,
continue, throw, debugger, do-while) the `;` is their terminator.
Blocks and other statements keep the old behaviour (`{}\n;` is still a
block and an empty statement).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A
;on the line after a statement was turned into an empty statement, so these valid programs failed to parse (and minify refused them):parseStmtonly consumed the trailing;when there was no line terminator before it. ASI only inserts a semicolon when the next token is not allowed by the grammar, and;is allowed, so the;is the terminator of the statement, not a new empty statement. Node, V8 and the spec agree (if (a) return\n; else bis valid too).The change keeps that
!p.prevLTcheck for blocks and other compound statements, so{}\n;still gives a block plus an empty statement (the case from dead295). For statements that end with a semicolon (expression, var/let/const, return, break, continue, throw, debugger, do-while, directive) the;is now consumed after a newline as well.Found by running the parser over tc39/test262-parser-tests: the
pass/files 209fc98bea7b9d67, 3c0c251ad455218d, 4efcd175a5db8b47 and 639b9076cc56e57c failed before and parse now. Thefail/andearly/results are unchanged.Tests: 9 new cases in
TestJS; 8 fail before the change, anda\n;\n;changes froma; ; ;toa; ;.go test ./...passes, and minify'sgo test ./...passes against this branch. With it: