Skip to content

Commit

Permalink
Wrap labeled statement to better test its positions
Browse files Browse the repository at this point in the history
  • Loading branch information
tyamagu2 committed Jul 25, 2023
1 parent a9d7d31 commit fd20922
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1110,15 +1110,16 @@ func TestPosition(t *testing.T) {
is(node.Idx0(), 40)
is(parser.slice(node.Idx0(), node.Idx1()), "break")

parser = newParser("", "xyz: for (i = 0; i < 10; i++) { if (i == 5) continue xyz; }", 1, nil)
parser = newParser("", "(function(){ xyz: for (i = 0; i < 10; i++) { if (i == 5) continue xyz; } })", 1, nil)
program, err = parser.parse()
is(err, nil)
node = program.Body[0].(*ast.LabelledStatement)
is(node.Idx0(), 1)
block = program.Body[0].(*ast.ExpressionStatement).Expression.(*ast.FunctionLiteral).Body.(*ast.BlockStatement)
node = block.List[0].(*ast.LabelledStatement)
is(node.Idx0(), 14)
is(parser.slice(node.Idx0(), node.Idx1()), "xyz: for (i = 0; i < 10; i++) { if (i == 5) continue xyz; }")
block = program.Body[0].(*ast.LabelledStatement).Statement.(*ast.ForStatement).Body.(*ast.BlockStatement)
block = node.(*ast.LabelledStatement).Statement.(*ast.ForStatement).Body.(*ast.BlockStatement)
node = block.List[0].(*ast.IfStatement).Consequent.(*ast.BranchStatement)
is(node.Idx0(), 45)
is(node.Idx0(), 58)
is(parser.slice(node.Idx0(), node.Idx1()), "continue xyz")

parser = newParser("", "(function(){ return; })", 1, nil)
Expand Down

0 comments on commit fd20922

Please sign in to comment.