mirror of
https://github.com/robertkrimen/otto
synced 2025-10-05 19:19:10 +08:00
[#148] Fixed style
This commit is contained in:
parent
9f65b62899
commit
54a2be367f
|
@ -203,7 +203,7 @@ func (self *_parser) parseVariableDeclarationList(var_ file.Idx) []ast.Expressio
|
|||
comments := self.findComments(false)
|
||||
|
||||
decl := self.parseVariableDeclaration(&declarationList)
|
||||
if self.mode & StoreComments != 0 {
|
||||
if self.mode&StoreComments != 0 {
|
||||
self.commentMap.AddComments(decl, comments, ast.LEADING)
|
||||
self.commentMap.AddComments(decl, self.findComments(false), ast.TRAILING)
|
||||
}
|
||||
|
@ -300,7 +300,7 @@ func (self *_parser) parseObjectProperty() ast.Property {
|
|||
Value: self.parseAssignmentExpression(),
|
||||
}
|
||||
|
||||
if self.mode & StoreComments != 0 {
|
||||
if self.mode&StoreComments != 0 {
|
||||
self.commentMap.AddComments(exp.Value, comments, ast.KEY)
|
||||
self.commentMap.AddComments(exp.Value, comments2, ast.COLON)
|
||||
}
|
||||
|
@ -317,7 +317,7 @@ func (self *_parser) parseObjectLiteral() ast.Expression {
|
|||
// Leading comments for object literal
|
||||
comments := self.findComments(false)
|
||||
property := self.parseObjectProperty()
|
||||
if self.mode & StoreComments != 0 {
|
||||
if self.mode&StoreComments != 0 {
|
||||
self.commentMap.AddComments(property.Value, comments, ast.LEADING)
|
||||
self.commentMap.AddComments(property.Value, comments2, ast.LEADING)
|
||||
}
|
||||
|
@ -338,7 +338,9 @@ func (self *_parser) parseObjectLiteral() ast.Expression {
|
|||
Value: value,
|
||||
}
|
||||
|
||||
if self.mode & StoreComments != 0 { self.commentMap.AddComments(exp, comments2, ast.FINAL) }
|
||||
if self.mode&StoreComments != 0 {
|
||||
self.commentMap.AddComments(exp, comments2, ast.FINAL)
|
||||
}
|
||||
self.consumeComments(exp, ast.FINAL)
|
||||
|
||||
return exp
|
||||
|
@ -359,7 +361,7 @@ func (self *_parser) parseArrayLiteral() ast.Expression {
|
|||
// This kind of comment requires a special empty expression node.
|
||||
empty := &ast.EmptyExpression{self.idx, self.idx}
|
||||
|
||||
if self.mode & StoreComments != 0 {
|
||||
if self.mode&StoreComments != 0 {
|
||||
self.commentMap.AddComments(empty, comments, ast.LEADING)
|
||||
self.commentMap.AddComments(empty, comments2, ast.LEADING)
|
||||
}
|
||||
|
@ -373,7 +375,7 @@ func (self *_parser) parseArrayLiteral() ast.Expression {
|
|||
}
|
||||
|
||||
exp := self.parseAssignmentExpression()
|
||||
if self.mode & StoreComments != 0 {
|
||||
if self.mode&StoreComments != 0 {
|
||||
self.commentMap.AddComments(exp, comments, ast.LEADING)
|
||||
self.commentMap.AddComments(exp, comments2, ast.LEADING)
|
||||
}
|
||||
|
@ -395,7 +397,9 @@ func (self *_parser) parseArrayLiteral() ast.Expression {
|
|||
}
|
||||
|
||||
// This is where comments after a possible trailing comma are added
|
||||
if self.mode & StoreComments != 0 { self.commentMap.AddComments(array, comments2, ast.FINAL) }
|
||||
if self.mode&StoreComments != 0 {
|
||||
self.commentMap.AddComments(array, comments2, ast.FINAL)
|
||||
}
|
||||
|
||||
return array
|
||||
}
|
||||
|
@ -406,7 +410,9 @@ func (self *_parser) parseArgumentList() (argumentList []ast.Expression, idx0, i
|
|||
for {
|
||||
comments := self.findComments(false)
|
||||
exp := self.parseAssignmentExpression()
|
||||
if self.mode & StoreComments != 0 { self.commentMap.AddComments(exp, comments, ast.LEADING) }
|
||||
if self.mode&StoreComments != 0 {
|
||||
self.commentMap.AddComments(exp, comments, ast.LEADING)
|
||||
}
|
||||
argumentList = append(argumentList, exp)
|
||||
if self.token != token.COMMA {
|
||||
break
|
||||
|
@ -427,7 +433,9 @@ func (self *_parser) parseCallExpression(left ast.Expression) ast.Expression {
|
|||
RightParenthesis: idx1,
|
||||
}
|
||||
|
||||
if self.mode & StoreComments != 0 { self.commentMap.AddComments(exp, self.findComments(false), ast.TRAILING) }
|
||||
if self.mode&StoreComments != 0 {
|
||||
self.commentMap.AddComments(exp, self.findComments(false), ast.TRAILING)
|
||||
}
|
||||
return exp
|
||||
}
|
||||
|
||||
|
@ -480,7 +488,9 @@ func (self *_parser) parseNewExpression() ast.Expression {
|
|||
node.RightParenthesis = idx1
|
||||
}
|
||||
|
||||
if self.mode & StoreComments != 0 { self.commentMap.AddComments(node, self.findComments(false), ast.TRAILING) }
|
||||
if self.mode&StoreComments != 0 {
|
||||
self.commentMap.AddComments(node, self.findComments(false), ast.TRAILING)
|
||||
}
|
||||
|
||||
return node
|
||||
}
|
||||
|
@ -494,7 +504,9 @@ func (self *_parser) parseLeftHandSideExpression() ast.Expression {
|
|||
left = self.parsePrimaryExpression()
|
||||
}
|
||||
|
||||
if self.mode & StoreComments != 0 { self.commentMap.AddComments(left, self.findComments(false), ast.TRAILING) }
|
||||
if self.mode&StoreComments != 0 {
|
||||
self.commentMap.AddComments(left, self.findComments(false), ast.TRAILING)
|
||||
}
|
||||
|
||||
for {
|
||||
if self.token == token.PERIOD {
|
||||
|
@ -524,7 +536,9 @@ func (self *_parser) parseLeftHandSideExpressionAllowCall() ast.Expression {
|
|||
left = self.parsePrimaryExpression()
|
||||
}
|
||||
|
||||
if self.mode & StoreComments != 0 { self.commentMap.AddComments(left, self.findComments(false), ast.TRAILING) }
|
||||
if self.mode&StoreComments != 0 {
|
||||
self.commentMap.AddComments(left, self.findComments(false), ast.TRAILING)
|
||||
}
|
||||
|
||||
for {
|
||||
if self.token == token.PERIOD {
|
||||
|
@ -567,7 +581,9 @@ func (self *_parser) parsePostfixExpression() ast.Expression {
|
|||
Postfix: true,
|
||||
}
|
||||
|
||||
if self.mode & StoreComments != 0 { self.commentMap.AddComments(exp, self.findComments(false), ast.TRAILING) }
|
||||
if self.mode&StoreComments != 0 {
|
||||
self.commentMap.AddComments(exp, self.findComments(false), ast.TRAILING)
|
||||
}
|
||||
|
||||
return exp
|
||||
}
|
||||
|
@ -593,7 +609,9 @@ func (self *_parser) parseUnaryExpression() ast.Expression {
|
|||
Operand: self.parseUnaryExpression(),
|
||||
}
|
||||
|
||||
if self.mode & StoreComments != 0 { self.commentMap.AddComments(exp.Operand, comments, ast.LEADING) }
|
||||
if self.mode&StoreComments != 0 {
|
||||
self.commentMap.AddComments(exp.Operand, comments, ast.LEADING)
|
||||
}
|
||||
return exp
|
||||
case token.INCREMENT, token.DECREMENT:
|
||||
tkn := self.token
|
||||
|
@ -603,7 +621,9 @@ func (self *_parser) parseUnaryExpression() ast.Expression {
|
|||
comments := self.findComments(false)
|
||||
|
||||
operand := self.parseUnaryExpression()
|
||||
if self.mode & StoreComments != 0 { self.commentMap.AddComments(operand, comments, ast.LEADING) }
|
||||
if self.mode&StoreComments != 0 {
|
||||
self.commentMap.AddComments(operand, comments, ast.LEADING)
|
||||
}
|
||||
switch operand.(type) {
|
||||
case *ast.Identifier, *ast.DotExpression, *ast.BracketExpression:
|
||||
default:
|
||||
|
@ -638,7 +658,9 @@ func (self *_parser) parseMultiplicativeExpression() ast.Expression {
|
|||
Right: next(),
|
||||
}
|
||||
|
||||
if self.mode & StoreComments != 0 { self.commentMap.AddComments(left.(*ast.BinaryExpression).Right, comments, ast.LEADING) }
|
||||
if self.mode&StoreComments != 0 {
|
||||
self.commentMap.AddComments(left.(*ast.BinaryExpression).Right, comments, ast.LEADING)
|
||||
}
|
||||
}
|
||||
|
||||
return left
|
||||
|
@ -660,7 +682,9 @@ func (self *_parser) parseAdditiveExpression() ast.Expression {
|
|||
Right: next(),
|
||||
}
|
||||
|
||||
if self.mode & StoreComments != 0 { self.commentMap.AddComments(left.(*ast.BinaryExpression).Right, comments, ast.LEADING) }
|
||||
if self.mode&StoreComments != 0 {
|
||||
self.commentMap.AddComments(left.(*ast.BinaryExpression).Right, comments, ast.LEADING)
|
||||
}
|
||||
}
|
||||
|
||||
return left
|
||||
|
@ -683,7 +707,9 @@ func (self *_parser) parseShiftExpression() ast.Expression {
|
|||
Right: next(),
|
||||
}
|
||||
|
||||
if self.mode & StoreComments != 0 { self.commentMap.AddComments(left.(*ast.BinaryExpression).Right, comments, ast.LEADING) }
|
||||
if self.mode&StoreComments != 0 {
|
||||
self.commentMap.AddComments(left.(*ast.BinaryExpression).Right, comments, ast.LEADING)
|
||||
}
|
||||
}
|
||||
|
||||
return left
|
||||
|
@ -713,7 +739,9 @@ func (self *_parser) parseRelationalExpression() ast.Expression {
|
|||
Comparison: true,
|
||||
}
|
||||
|
||||
if self.mode & StoreComments != 0 { self.commentMap.AddComments(exp.Right, comments, ast.LEADING) }
|
||||
if self.mode&StoreComments != 0 {
|
||||
self.commentMap.AddComments(exp.Right, comments, ast.LEADING)
|
||||
}
|
||||
return exp
|
||||
case token.INSTANCEOF:
|
||||
tkn := self.token
|
||||
|
@ -727,7 +755,9 @@ func (self *_parser) parseRelationalExpression() ast.Expression {
|
|||
Right: self.parseRelationalExpression(),
|
||||
}
|
||||
|
||||
if self.mode & StoreComments != 0 { self.commentMap.AddComments(exp.Right, comments, ast.LEADING) }
|
||||
if self.mode&StoreComments != 0 {
|
||||
self.commentMap.AddComments(exp.Right, comments, ast.LEADING)
|
||||
}
|
||||
return exp
|
||||
case token.IN:
|
||||
if !allowIn {
|
||||
|
@ -744,7 +774,9 @@ func (self *_parser) parseRelationalExpression() ast.Expression {
|
|||
Right: self.parseRelationalExpression(),
|
||||
}
|
||||
|
||||
if self.mode & StoreComments != 0 { self.commentMap.AddComments(exp.Right, comments, ast.LEADING) }
|
||||
if self.mode&StoreComments != 0 {
|
||||
self.commentMap.AddComments(exp.Right, comments, ast.LEADING)
|
||||
}
|
||||
return exp
|
||||
}
|
||||
|
||||
|
@ -769,7 +801,9 @@ func (self *_parser) parseEqualityExpression() ast.Expression {
|
|||
Comparison: true,
|
||||
}
|
||||
|
||||
if self.mode & StoreComments != 0 { self.commentMap.AddComments(left.(*ast.BinaryExpression).Right, comments, ast.LEADING) }
|
||||
if self.mode&StoreComments != 0 {
|
||||
self.commentMap.AddComments(left.(*ast.BinaryExpression).Right, comments, ast.LEADING)
|
||||
}
|
||||
}
|
||||
|
||||
return left
|
||||
|
@ -791,7 +825,9 @@ func (self *_parser) parseBitwiseAndExpression() ast.Expression {
|
|||
Right: next(),
|
||||
}
|
||||
|
||||
if self.mode & StoreComments != 0 { self.commentMap.AddComments(left.(*ast.BinaryExpression).Right, comments, ast.LEADING) }
|
||||
if self.mode&StoreComments != 0 {
|
||||
self.commentMap.AddComments(left.(*ast.BinaryExpression).Right, comments, ast.LEADING)
|
||||
}
|
||||
}
|
||||
|
||||
return left
|
||||
|
@ -813,7 +849,9 @@ func (self *_parser) parseBitwiseExclusiveOrExpression() ast.Expression {
|
|||
Right: next(),
|
||||
}
|
||||
|
||||
if self.mode & StoreComments != 0 { self.commentMap.AddComments(left.(*ast.BinaryExpression).Right, comments, ast.LEADING) }
|
||||
if self.mode&StoreComments != 0 {
|
||||
self.commentMap.AddComments(left.(*ast.BinaryExpression).Right, comments, ast.LEADING)
|
||||
}
|
||||
}
|
||||
|
||||
return left
|
||||
|
@ -835,7 +873,9 @@ func (self *_parser) parseBitwiseOrExpression() ast.Expression {
|
|||
Right: next(),
|
||||
}
|
||||
|
||||
if self.mode & StoreComments != 0 { self.commentMap.AddComments(left.(*ast.BinaryExpression).Right, comments, ast.LEADING) }
|
||||
if self.mode&StoreComments != 0 {
|
||||
self.commentMap.AddComments(left.(*ast.BinaryExpression).Right, comments, ast.LEADING)
|
||||
}
|
||||
}
|
||||
|
||||
return left
|
||||
|
@ -857,7 +897,9 @@ func (self *_parser) parseLogicalAndExpression() ast.Expression {
|
|||
Right: next(),
|
||||
}
|
||||
|
||||
if self.mode & StoreComments != 0 { self.commentMap.AddComments(left.(*ast.BinaryExpression).Right, comments, ast.LEADING) }
|
||||
if self.mode&StoreComments != 0 {
|
||||
self.commentMap.AddComments(left.(*ast.BinaryExpression).Right, comments, ast.LEADING)
|
||||
}
|
||||
}
|
||||
|
||||
return left
|
||||
|
@ -879,7 +921,9 @@ func (self *_parser) parseLogicalOrExpression() ast.Expression {
|
|||
Right: next(),
|
||||
}
|
||||
|
||||
if self.mode & StoreComments != 0 { self.commentMap.AddComments(left.(*ast.BinaryExpression).Right, comments, ast.LEADING) }
|
||||
if self.mode&StoreComments != 0 {
|
||||
self.commentMap.AddComments(left.(*ast.BinaryExpression).Right, comments, ast.LEADING)
|
||||
}
|
||||
}
|
||||
|
||||
return left
|
||||
|
@ -895,7 +939,9 @@ func (self *_parser) parseConditionlExpression() ast.Expression {
|
|||
comments1 := self.findComments(false)
|
||||
|
||||
consequent := self.parseAssignmentExpression()
|
||||
if self.mode & StoreComments != 0 { self.commentMap.AddComments(consequent, comments1, ast.LEADING) }
|
||||
if self.mode&StoreComments != 0 {
|
||||
self.commentMap.AddComments(consequent, comments1, ast.LEADING)
|
||||
}
|
||||
|
||||
self.expect(token.COLON)
|
||||
|
||||
|
@ -907,7 +953,9 @@ func (self *_parser) parseConditionlExpression() ast.Expression {
|
|||
Alternate: self.parseAssignmentExpression(),
|
||||
}
|
||||
|
||||
if self.mode & StoreComments != 0 { self.commentMap.AddComments(exp.Alternate, comments2, ast.LEADING) }
|
||||
if self.mode&StoreComments != 0 {
|
||||
self.commentMap.AddComments(exp.Alternate, comments2, ast.LEADING)
|
||||
}
|
||||
return exp
|
||||
}
|
||||
|
||||
|
@ -965,7 +1013,9 @@ func (self *_parser) parseAssignmentExpression() ast.Expression {
|
|||
Right: self.parseAssignmentExpression(),
|
||||
}
|
||||
|
||||
if self.mode & StoreComments != 0 { self.commentMap.AddComments(exp.Right, comments, ast.LEADING) }
|
||||
if self.mode&StoreComments != 0 {
|
||||
self.commentMap.AddComments(exp.Right, comments, ast.LEADING)
|
||||
}
|
||||
|
||||
return exp
|
||||
}
|
||||
|
@ -995,7 +1045,7 @@ func (self *_parser) parseExpression() ast.Expression {
|
|||
}
|
||||
}
|
||||
|
||||
if self.mode & StoreComments != 0 {
|
||||
if self.mode&StoreComments != 0 {
|
||||
self.commentMap.AddComments(left, comments, ast.LEADING)
|
||||
self.commentMap.AddComments(left, statementComments, ast.LEADING)
|
||||
}
|
||||
|
|
|
@ -286,12 +286,11 @@ func (self *_parser) position(idx file.Idx) file.Position {
|
|||
// Comments on the same line will be grouped together and returned.
|
||||
// After the first line break, comments will be added as statement comments.
|
||||
func (self *_parser) findComments(ignoreLineBreak bool) []*ast.Comment {
|
||||
if self.mode & StoreComments == 0 {
|
||||
if self.mode&StoreComments == 0 {
|
||||
return nil
|
||||
}
|
||||
comments := make([]*ast.Comment, 0)
|
||||
|
||||
|
||||
newline := false
|
||||
|
||||
for self.implicitSemicolon == false || ignoreLineBreak {
|
||||
|
|
|
@ -9,7 +9,9 @@ func (self *_parser) parseBlockStatement() *ast.BlockStatement {
|
|||
node := &ast.BlockStatement{}
|
||||
|
||||
// Find comments before the leading brace
|
||||
if self.mode & StoreComments != 0 { self.commentMap.AddComments(node, self.findComments(false), ast.LEADING) }
|
||||
if self.mode&StoreComments != 0 {
|
||||
self.commentMap.AddComments(node, self.findComments(false), ast.LEADING)
|
||||
}
|
||||
|
||||
node.LeftBrace = self.expect(token.LEFT_BRACE)
|
||||
node.List = self.parseStatementList()
|
||||
|
@ -19,7 +21,9 @@ func (self *_parser) parseBlockStatement() *ast.BlockStatement {
|
|||
node.RightBrace = self.expect(token.RIGHT_BRACE)
|
||||
|
||||
// Find comments after the trailing brace
|
||||
if self.mode & StoreComments != 0 { self.commentMap.AddComments(node, self.findComments(false), ast.TRAILING) }
|
||||
if self.mode&StoreComments != 0 {
|
||||
self.commentMap.AddComments(node, self.findComments(false), ast.TRAILING)
|
||||
}
|
||||
|
||||
return node
|
||||
}
|
||||
|
@ -112,7 +116,9 @@ func (self *_parser) parseStatement() ast.Statement {
|
|||
Statement: statement,
|
||||
}
|
||||
|
||||
if self.mode & StoreComments != 0 { self.commentMap.AddComments(exp, comments, ast.TRAILING) }
|
||||
if self.mode&StoreComments != 0 {
|
||||
self.commentMap.AddComments(exp, comments, ast.TRAILING)
|
||||
}
|
||||
|
||||
return exp
|
||||
}
|
||||
|
@ -131,7 +137,9 @@ func (self *_parser) parseTryStatement() ast.Statement {
|
|||
Body: self.parseBlockStatement(),
|
||||
}
|
||||
|
||||
if self.mode & StoreComments != 0 { self.commentMap.AddComments(node.Body, self.findComments(true), ast.TRAILING) }
|
||||
if self.mode&StoreComments != 0 {
|
||||
self.commentMap.AddComments(node.Body, self.findComments(true), ast.TRAILING)
|
||||
}
|
||||
|
||||
if self.token == token.CATCH {
|
||||
catch := self.idx
|
||||
|
@ -145,7 +153,9 @@ func (self *_parser) parseTryStatement() ast.Statement {
|
|||
} else {
|
||||
identifier := self.parseIdentifier()
|
||||
|
||||
if self.mode & StoreComments != 0 { self.commentMap.AddComments(identifier, comments, ast.LEADING) }
|
||||
if self.mode&StoreComments != 0 {
|
||||
self.commentMap.AddComments(identifier, comments, ast.LEADING)
|
||||
}
|
||||
|
||||
self.expect(token.RIGHT_PARENTHESIS)
|
||||
node.Catch = &ast.CatchStatement{
|
||||
|
@ -155,7 +165,9 @@ func (self *_parser) parseTryStatement() ast.Statement {
|
|||
}
|
||||
}
|
||||
|
||||
if self.mode & StoreComments != 0 { self.commentMap.AddComments(node.Catch, self.findComments(true), ast.TRAILING) }
|
||||
if self.mode&StoreComments != 0 {
|
||||
self.commentMap.AddComments(node.Catch, self.findComments(true), ast.TRAILING)
|
||||
}
|
||||
}
|
||||
|
||||
if self.token == token.FINALLY {
|
||||
|
@ -165,7 +177,9 @@ func (self *_parser) parseTryStatement() ast.Statement {
|
|||
|
||||
node.Finally = self.parseBlockStatement()
|
||||
|
||||
if self.mode & StoreComments != 0 { self.commentMap.AddComments(node.Finally, comments, ast.LEADING) }
|
||||
if self.mode&StoreComments != 0 {
|
||||
self.commentMap.AddComments(node.Finally, comments, ast.LEADING)
|
||||
}
|
||||
}
|
||||
|
||||
if node.Catch == nil && node.Finally == nil {
|
||||
|
@ -185,7 +199,9 @@ func (self *_parser) parseFunctionParameterList() *ast.ParameterList {
|
|||
self.expect(token.IDENTIFIER)
|
||||
} else {
|
||||
identifier := self.parseIdentifier()
|
||||
if self.mode & StoreComments != 0 { self.commentMap.AddComments(identifier, comments, ast.LEADING) }
|
||||
if self.mode&StoreComments != 0 {
|
||||
self.commentMap.AddComments(identifier, comments, ast.LEADING)
|
||||
}
|
||||
list = append(list, identifier)
|
||||
}
|
||||
if self.token != token.RIGHT_PARENTHESIS {
|
||||
|
@ -264,12 +280,16 @@ func (self *_parser) parseDebuggerStatement() ast.Statement {
|
|||
Debugger: idx,
|
||||
}
|
||||
|
||||
if self.mode & StoreComments != 0 { self.commentMap.AddComments(node, comments, ast.TRAILING) }
|
||||
if self.mode&StoreComments != 0 {
|
||||
self.commentMap.AddComments(node, comments, ast.TRAILING)
|
||||
}
|
||||
|
||||
self.semicolon()
|
||||
|
||||
if !self.skippedLineBreak {
|
||||
if self.mode & StoreComments != 0 { self.commentMap.AddComments(node, self.findComments(false), ast.TRAILING) }
|
||||
if self.mode&StoreComments != 0 {
|
||||
self.commentMap.AddComments(node, self.findComments(false), ast.TRAILING)
|
||||
}
|
||||
}
|
||||
|
||||
return node
|
||||
|
@ -369,7 +389,9 @@ func (self *_parser) parseWithStatement() ast.Statement {
|
|||
self.expect(token.RIGHT_PARENTHESIS)
|
||||
|
||||
// Add the key comments
|
||||
if self.mode & StoreComments != 0 { self.commentMap.AddComments(node, comments, ast.KEY) }
|
||||
if self.mode&StoreComments != 0 {
|
||||
self.commentMap.AddComments(node, comments, ast.KEY)
|
||||
}
|
||||
|
||||
// Find the leading comments for the body
|
||||
comments = self.findComments(true)
|
||||
|
@ -377,7 +399,9 @@ func (self *_parser) parseWithStatement() ast.Statement {
|
|||
node.Body = self.parseStatement()
|
||||
|
||||
// Add the body comments
|
||||
if self.mode & StoreComments != 0 { self.commentMap.AddComments(node.Body, comments, ast.LEADING) }
|
||||
if self.mode&StoreComments != 0 {
|
||||
self.commentMap.AddComments(node.Body, comments, ast.LEADING)
|
||||
}
|
||||
|
||||
// Move the trailing comments to the with statement
|
||||
self.commentMap.MoveComments(node.Body, node, ast.TRAILING)
|
||||
|
@ -393,7 +417,9 @@ func (self *_parser) parseCaseStatement() *ast.CaseStatement {
|
|||
Case: self.idx,
|
||||
}
|
||||
|
||||
if self.mode & StoreComments != 0 { self.commentMap.AddComments(node, self.findComments(true), ast.LEADING) }
|
||||
if self.mode&StoreComments != 0 {
|
||||
self.commentMap.AddComments(node, self.findComments(true), ast.LEADING)
|
||||
}
|
||||
|
||||
// Consume current comments
|
||||
self.consumeComments(node, ast.LEADING)
|
||||
|
@ -406,15 +432,21 @@ func (self *_parser) parseCaseStatement() *ast.CaseStatement {
|
|||
comments = self.findComments(true)
|
||||
|
||||
node.Test = self.parseExpression()
|
||||
if self.mode & StoreComments != 0 { self.commentMap.AddComments(node.Test, comments, ast.LEADING) }
|
||||
if self.mode&StoreComments != 0 {
|
||||
self.commentMap.AddComments(node.Test, comments, ast.LEADING)
|
||||
}
|
||||
|
||||
comments = self.findComments(true)
|
||||
if self.mode & StoreComments != 0 { self.commentMap.AddComments(node.Test, comments, ast.TRAILING) }
|
||||
if self.mode&StoreComments != 0 {
|
||||
self.commentMap.AddComments(node.Test, comments, ast.TRAILING)
|
||||
}
|
||||
}
|
||||
|
||||
self.expect(token.COLON)
|
||||
|
||||
if self.mode & StoreComments != 0 { self.commentMap.AddComments(node.Test, self.findComments(false), ast.TRAILING) }
|
||||
if self.mode&StoreComments != 0 {
|
||||
self.commentMap.AddComments(node.Test, self.findComments(false), ast.TRAILING)
|
||||
}
|
||||
|
||||
for {
|
||||
if self.token == token.EOF ||
|
||||
|
@ -426,7 +458,9 @@ func (self *_parser) parseCaseStatement() *ast.CaseStatement {
|
|||
consequent := self.parseStatement()
|
||||
node.Consequent = append(node.Consequent, consequent)
|
||||
|
||||
if self.mode & StoreComments != 0 { self.commentMap.AddComments(consequent, self.findComments(false), ast.TRAILING) }
|
||||
if self.mode&StoreComments != 0 {
|
||||
self.commentMap.AddComments(consequent, self.findComments(false), ast.TRAILING)
|
||||
}
|
||||
}
|
||||
|
||||
return node
|
||||
|
@ -449,13 +483,17 @@ func (self *_parser) parseForIn(into ast.Expression) *ast.ForInStatement {
|
|||
comments := self.findComments(true)
|
||||
|
||||
source := self.parseExpression()
|
||||
if self.mode & StoreComments != 0 { self.commentMap.AddComments(source, comments, ast.LEADING) }
|
||||
if self.mode&StoreComments != 0 {
|
||||
self.commentMap.AddComments(source, comments, ast.LEADING)
|
||||
}
|
||||
|
||||
self.expect(token.RIGHT_PARENTHESIS)
|
||||
|
||||
comments = self.findComments(true)
|
||||
body := self.parseIterationStatement()
|
||||
if self.mode & StoreComments != 0 { self.commentMap.AddComments(body, comments, ast.LEADING) }
|
||||
if self.mode&StoreComments != 0 {
|
||||
self.commentMap.AddComments(body, comments, ast.LEADING)
|
||||
}
|
||||
|
||||
forin := &ast.ForInStatement{
|
||||
Into: into,
|
||||
|
@ -478,7 +516,9 @@ func (self *_parser) parseFor(initializer ast.Expression) *ast.ForStatement {
|
|||
|
||||
if self.token != token.SEMICOLON {
|
||||
test = self.parseExpression()
|
||||
if self.mode & StoreComments != 0 { self.commentMap.AddComments(test, comments, ast.LEADING) }
|
||||
if self.mode&StoreComments != 0 {
|
||||
self.commentMap.AddComments(test, comments, ast.LEADING)
|
||||
}
|
||||
}
|
||||
self.expect(token.SEMICOLON)
|
||||
|
||||
|
@ -486,14 +526,18 @@ func (self *_parser) parseFor(initializer ast.Expression) *ast.ForStatement {
|
|||
|
||||
if self.token != token.RIGHT_PARENTHESIS {
|
||||
update = self.parseExpression()
|
||||
if self.mode & StoreComments != 0 { self.commentMap.AddComments(update, comments, ast.LEADING) }
|
||||
if self.mode&StoreComments != 0 {
|
||||
self.commentMap.AddComments(update, comments, ast.LEADING)
|
||||
}
|
||||
}
|
||||
self.expect(token.RIGHT_PARENTHESIS)
|
||||
|
||||
comments = self.findComments(true)
|
||||
|
||||
body := self.parseIterationStatement()
|
||||
if self.mode & StoreComments != 0 { self.commentMap.AddComments(body, comments, ast.LEADING) }
|
||||
if self.mode&StoreComments != 0 {
|
||||
self.commentMap.AddComments(body, comments, ast.LEADING)
|
||||
}
|
||||
|
||||
forstatement := &ast.ForStatement{
|
||||
Initializer: initializer,
|
||||
|
@ -551,13 +595,17 @@ func (self *_parser) parseForOrForInStatement() ast.Statement {
|
|||
return &ast.BadStatement{From: idx, To: self.idx}
|
||||
}
|
||||
|
||||
if self.mode & StoreComments != 0 { self.commentMap.AddComments(left[0], comments, ast.LEADING) }
|
||||
if self.mode&StoreComments != 0 {
|
||||
self.commentMap.AddComments(left[0], comments, ast.LEADING)
|
||||
}
|
||||
return self.parseForIn(left[0])
|
||||
}
|
||||
|
||||
self.expect(token.SEMICOLON)
|
||||
initializer := &ast.SequenceExpression{Sequence: left}
|
||||
if self.mode & StoreComments != 0 { self.commentMap.AddComments(initializer, comments, ast.LEADING) }
|
||||
if self.mode&StoreComments != 0 {
|
||||
self.commentMap.AddComments(initializer, comments, ast.LEADING)
|
||||
}
|
||||
return self.parseFor(initializer)
|
||||
}
|
||||
|
||||
|
@ -574,12 +622,16 @@ func (self *_parser) parseVariableStatement() *ast.VariableStatement {
|
|||
|
||||
self.commentMap.MoveComments(statement.List[len(statement.List)-1], statement, ast.TRAILING)
|
||||
|
||||
if self.mode & StoreComments != 0 { self.commentMap.AddComments(statement, self.findComments(true), ast.TRAILING) }
|
||||
if self.mode&StoreComments != 0 {
|
||||
self.commentMap.AddComments(statement, self.findComments(true), ast.TRAILING)
|
||||
}
|
||||
|
||||
self.semicolon()
|
||||
|
||||
if self.skippedLineBreak {
|
||||
if self.mode & StoreComments != 0 { self.commentMap.AddComments(statement, self.findComments(false), ast.TRAILING) }
|
||||
if self.mode&StoreComments != 0 {
|
||||
self.commentMap.AddComments(statement, self.findComments(false), ast.TRAILING)
|
||||
}
|
||||
}
|
||||
|
||||
return statement
|
||||
|
@ -597,7 +649,9 @@ func (self *_parser) parseDoWhileStatement() ast.Statement {
|
|||
comments := self.findComments(true)
|
||||
|
||||
node := &ast.DoWhileStatement{}
|
||||
if self.mode & StoreComments != 0 { self.commentMap.AddComments(node, comments, ast.KEY) }
|
||||
if self.mode&StoreComments != 0 {
|
||||
self.commentMap.AddComments(node, comments, ast.KEY)
|
||||
}
|
||||
if self.token == token.LEFT_BRACE {
|
||||
node.Body = self.parseBlockStatement()
|
||||
} else {
|
||||
|
@ -610,11 +664,15 @@ func (self *_parser) parseDoWhileStatement() ast.Statement {
|
|||
|
||||
self.expect(token.LEFT_PARENTHESIS)
|
||||
node.Test = self.parseExpression()
|
||||
if self.mode & StoreComments != 0 { self.commentMap.AddComments(node.Test, comments, ast.LEADING) }
|
||||
if self.mode&StoreComments != 0 {
|
||||
self.commentMap.AddComments(node.Test, comments, ast.LEADING)
|
||||
}
|
||||
|
||||
self.expect(token.RIGHT_PARENTHESIS)
|
||||
|
||||
if self.mode & StoreComments != 0 { self.commentMap.AddComments(node.Test, self.findComments(false), ast.TRAILING) }
|
||||
if self.mode&StoreComments != 0 {
|
||||
self.commentMap.AddComments(node.Test, self.findComments(false), ast.TRAILING)
|
||||
}
|
||||
|
||||
return node
|
||||
}
|
||||
|
@ -631,7 +689,9 @@ func (self *_parser) parseWhileStatement() ast.Statement {
|
|||
}
|
||||
|
||||
// Add the while comments
|
||||
if self.mode & StoreComments != 0 { self.commentMap.AddComments(node, comments, ast.KEY) }
|
||||
if self.mode&StoreComments != 0 {
|
||||
self.commentMap.AddComments(node, comments, ast.KEY)
|
||||
}
|
||||
|
||||
self.expect(token.RIGHT_PARENTHESIS)
|
||||
|
||||
|
@ -641,7 +701,9 @@ func (self *_parser) parseWhileStatement() ast.Statement {
|
|||
node.Body = self.parseIterationStatement()
|
||||
|
||||
// Adding the comments prior to the body
|
||||
if self.mode & StoreComments != 0 { self.commentMap.AddComments(node.Body, comments, ast.LEADING) }
|
||||
if self.mode&StoreComments != 0 {
|
||||
self.commentMap.AddComments(node.Body, comments, ast.LEADING)
|
||||
}
|
||||
|
||||
// Move the trailing comments to the while statement
|
||||
self.commentMap.MoveComments(node.Body, node, ast.TRAILING)
|
||||
|
@ -659,7 +721,9 @@ func (self *_parser) parseIfStatement() ast.Statement {
|
|||
Test: self.parseExpression(),
|
||||
}
|
||||
|
||||
if self.mode & StoreComments != 0 { self.commentMap.AddComments(node, comments, ast.KEY) }
|
||||
if self.mode&StoreComments != 0 {
|
||||
self.commentMap.AddComments(node, comments, ast.KEY)
|
||||
}
|
||||
|
||||
self.expect(token.RIGHT_PARENTHESIS)
|
||||
|
||||
|
@ -671,7 +735,7 @@ func (self *_parser) parseIfStatement() ast.Statement {
|
|||
node.Consequent = self.parseStatement()
|
||||
}
|
||||
|
||||
if self.mode & StoreComments != 0 {
|
||||
if self.mode&StoreComments != 0 {
|
||||
self.commentMap.AddComments(node.Consequent, comments, ast.LEADING)
|
||||
self.commentMap.AddComments(node.Consequent, self.findComments(true), ast.TRAILING)
|
||||
}
|
||||
|
@ -682,7 +746,7 @@ func (self *_parser) parseIfStatement() ast.Statement {
|
|||
|
||||
node.Alternate = self.parseStatement()
|
||||
|
||||
if self.mode & StoreComments != 0 {
|
||||
if self.mode&StoreComments != 0 {
|
||||
self.commentMap.AddComments(node.Alternate, comments, ast.LEADING)
|
||||
self.commentMap.AddComments(node.Alternate, self.findComments(false), ast.TRAILING)
|
||||
}
|
||||
|
@ -697,7 +761,9 @@ func (self *_parser) parseSourceElement() ast.Statement {
|
|||
|
||||
statement := self.parseStatement()
|
||||
|
||||
if self.mode & StoreComments != 0 { self.commentMap.AddComments(statement, statementComment, ast.LEADING) }
|
||||
if self.mode&StoreComments != 0 {
|
||||
self.commentMap.AddComments(statement, statementComment, ast.LEADING)
|
||||
}
|
||||
|
||||
return statement
|
||||
}
|
||||
|
@ -770,7 +836,9 @@ func (self *_parser) parseBreakStatement() ast.Statement {
|
|||
Token: token.BREAK,
|
||||
}
|
||||
|
||||
if self.mode & StoreComments != 0 { self.commentMap.AddComments(breakStatement, breakComments, ast.TRAILING) }
|
||||
if self.mode&StoreComments != 0 {
|
||||
self.commentMap.AddComments(breakStatement, breakComments, ast.TRAILING)
|
||||
}
|
||||
|
||||
return breakStatement
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user