use of org.mozilla.javascript.ast.NumberLiteral in project HL4A by HL4A.
the class Parser method destructuringObject.
boolean destructuringObject(ObjectLiteral node, int variableType, String tempName, Node parent, List<String> destructuringNames) {
boolean empty = true;
int setOp = variableType == Token.CONST ? Token.SETCONST : Token.SETNAME;
for (ObjectProperty prop : node.getElements()) {
int lineno = 0;
// tokenStream isn't set. Deal with it.
if (ts != null) {
lineno = ts.lineno;
}
AstNode id = prop.getLeft();
Node rightElem = null;
if (id instanceof Name) {
Node s = Node.newString(((Name) id).getIdentifier());
rightElem = new Node(Token.GETPROP, createName(tempName), s);
} else if (id instanceof StringLiteral) {
Node s = Node.newString(((StringLiteral) id).getValue());
rightElem = new Node(Token.GETPROP, createName(tempName), s);
} else if (id instanceof NumberLiteral) {
Node s = createNumber((int) ((NumberLiteral) id).getNumber());
rightElem = new Node(Token.GETELEM, createName(tempName), s);
} else {
throw codeBug();
}
rightElem.setLineno(lineno);
AstNode value = prop.getRight();
if (value.getType() == Token.NAME) {
String name = ((Name) value).getIdentifier();
parent.addChildToBack(new Node(setOp, createName(Token.BINDNAME, name, null), rightElem));
if (variableType != -1) {
defineSymbol(variableType, name, true);
destructuringNames.add(name);
}
} else {
parent.addChildToBack(destructuringAssignmentHelper(variableType, value, rightElem, currentScriptOrFn.getNextTempName()));
}
empty = false;
}
return empty;
}
use of org.mozilla.javascript.ast.NumberLiteral in project HL4A by HL4A.
the class Node method newNumber.
public static Node newNumber(double number) {
NumberLiteral n = new NumberLiteral();
n.setNumber(number);
return n;
}
Aggregations