Skip to content

Commit

Permalink
Merge pull request dop251#34 from vanackere/master
Browse files Browse the repository at this point in the history
Add missing idx to ast.ForStatement / ast.ForInStatement
  • Loading branch information
dop251 authored Jun 21, 2017
2 parents 0971883 + 6672e9d commit a6ed999
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions parser/statement.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package parser

import (
"github.com/dop251/goja/ast"
"github.com/dop251/goja/file"
"github.com/dop251/goja/token"
)

Expand Down Expand Up @@ -356,21 +357,22 @@ func (self *_parser) parseIterationStatement() ast.Statement {
return self.parseStatement()
}

func (self *_parser) parseForIn(into ast.Expression) *ast.ForInStatement {
func (self *_parser) parseForIn(idx file.Idx, into ast.Expression) *ast.ForInStatement {

// Already have consumed "<into> in"

source := self.parseExpression()
self.expect(token.RIGHT_PARENTHESIS)

return &ast.ForInStatement{
For: idx,
Into: into,
Source: source,
Body: self.parseIterationStatement(),
}
}

func (self *_parser) parseFor(initializer ast.Expression) *ast.ForStatement {
func (self *_parser) parseFor(idx file.Idx, initializer ast.Expression) *ast.ForStatement {

// Already have consumed "<initializer> ;"

Expand All @@ -387,6 +389,7 @@ func (self *_parser) parseFor(initializer ast.Expression) *ast.ForStatement {
self.expect(token.RIGHT_PARENTHESIS)

return &ast.ForStatement{
For: idx,
Initializer: initializer,
Test: test,
Update: update,
Expand Down Expand Up @@ -435,11 +438,11 @@ func (self *_parser) parseForOrForInStatement() ast.Statement {
self.nextStatement()
return &ast.BadStatement{From: idx, To: self.idx}
}
return self.parseForIn(left[0])
return self.parseForIn(idx, left[0])
}

self.expect(token.SEMICOLON)
return self.parseFor(&ast.SequenceExpression{Sequence: left})
return self.parseFor(idx, &ast.SequenceExpression{Sequence: left})
}

func (self *_parser) parseVariableStatement() *ast.VariableStatement {
Expand Down

0 comments on commit a6ed999

Please sign in to comment.