1
0
mirror of https://github.com/robertkrimen/otto synced 2025-10-05 19:19:10 +08:00

Allow semicolon in nested do-while statements. (#463)

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>
This commit is contained in:
Steven Hartland 2022-11-28 11:25:15 +00:00 committed by GitHub
parent 762556bdd2
commit a5b0adea00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 0 deletions

View File

@ -617,6 +617,8 @@ func TestParser(t *testing.T) {
} while (0)
`, nil)
test(`do do; while(0); while(0);`, nil)
test(`
(function(){
try {

View File

@ -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)