* of this transformation has alternating var lists and assignment
* statements. The currentVar variable holds the most recently inserted
* statement, if that statement was a JsVars; otherwise it holds null.
*/
JsVars currentVar = null;
Iterator<JsVar> varsIterator = x.iterator();
while (varsIterator.hasNext()) {
JsVar var = varsIterator.next();
if (namesToPredefine.contains(var.getName())) {
// The var was predefined
if (var.getInitExpr() != null) {
// If it has an initializer, add an assignment statement
JsBinaryOperation asg =
new JsBinaryOperation(var.getSourceInfo(), JsBinaryOperator.ASG, makeRefViaJslink(
var.getName(), var.getSourceInfo()), var.getInitExpr());
ctx.insertBefore(asg.makeStmt());
currentVar = null;
}
} else {
// The var was not predefined; add it to a var list
if (currentVar == null) {
currentVar = new JsVars(x.getSourceInfo());
ctx.insertBefore(currentVar);
}
currentVar.add(var);
}
}
ctx.removeMe();
}