Commit 23d77528 authored by Christian Kamm's avatar Christian Kamm
Browse files

JS checks: Allow blocks after for(var ...).

Also
* check the condition of the 'for(var' statement for assignment
* allow comma expressions in 'for(var'

Reviewed-by: Erik Verbruggen
parent 9f1737b4
......@@ -587,6 +587,8 @@ bool Check::visit(Block *ast)
&& !cast<Finally *>(p)
&& !cast<ForStatement *>(p)
&& !cast<ForEachStatement *>(p)
&& !cast<LocalForStatement *>(p)
&& !cast<LocalForEachStatement *>(p)
&& !cast<DoWhileStatement *>(p)
&& !cast<WhileStatement *>(p)
&& !cast<IfStatement *>(p)
......@@ -615,8 +617,11 @@ bool Check::visit(VoidExpression *ast)
bool Check::visit(Expression *ast)
{
if (_options & WarnCommaExpression && ast->left && ast->right) {
if (!cast<ForStatement *>(parent()))
Node *p = parent();
if (!cast<ForStatement *>(p)
&& !cast<LocalForStatement *>(p)) {
warning(ast->commaToken, tr("avoid comma expressions"));
}
}
return true;
}
......@@ -681,6 +686,13 @@ bool Check::visit(ForStatement *ast)
return true;
}
bool Check::visit(LocalForStatement *ast)
{
if (ast->condition)
checkAssignInCondition(ast->condition);
return true;
}
bool Check::visit(WhileStatement *ast)
{
if (ast->expression)
......
......@@ -88,6 +88,7 @@ protected:
virtual bool visit(AST::ExpressionStatement *ast);
virtual bool visit(AST::IfStatement *ast);
virtual bool visit(AST::ForStatement *ast);
virtual bool visit(AST::LocalForStatement *ast);
virtual bool visit(AST::WhileStatement *ast);
virtual bool visit(AST::DoWhileStatement *ast);
virtual bool visit(AST::CaseClause *ast);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment