Skip to content

Commit

Permalink
Allow semicolon in nested do-while statements. (#463)
Browse files Browse the repository at this point in the history
In nested do-while statements, a semicolon after the inner `while` threw
a parsing error. This change checks for the optional semicolon.

Co-authored-by: Brian Graham <bcgraham+github@gmail.com>
  • Loading branch information
stevenh and bcgraham committed Nov 28, 2022
1 parent 762556b commit a5b0ade
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,8 @@ func TestParser(t *testing.T) {
} while (0)
`, nil)

test(`do do; while(0); while(0);`, nil)

test(`
(function(){
try {
Expand Down
3 changes: 3 additions & 0 deletions parser/statement.go
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,9 @@ func (self *_parser) parseDoWhileStatement() ast.Statement {
node.Test = self.parseExpression()
self.expect(token.RIGHT_PARENTHESIS)

self.implicitSemicolon = true
self.optionalSemicolon()

if self.mode&StoreComments != 0 {
self.comments.CommentMap.AddComments(node, comments, ast.LEADING)
self.comments.CommentMap.AddComments(node, doComments, ast.DO)
Expand Down

0 comments on commit a5b0ade

Please sign in to comment.