use of org.mozilla.javascript.ast.LetNode in project HL4A by HL4A.
the class IRFactory method transformVariables.
private Node transformVariables(VariableDeclaration node) {
decompiler.addToken(node.getType());
transformVariableInitializers(node);
// Might be most robust to have parser record whether it was
// a variable declaration statement, possibly as a node property.
AstNode parent = node.getParent();
if (!(parent instanceof Loop) && !(parent instanceof LetNode)) {
decompiler.addEOL(Token.SEMI);
}
return node;
}
use of org.mozilla.javascript.ast.LetNode in project HL4A by HL4A.
the class IRFactory method transformLetNode.
private Node transformLetNode(LetNode node) {
pushScope(node);
try {
decompiler.addToken(Token.LET);
decompiler.addToken(Token.LP);
Node vars = transformVariableInitializers(node.getVariables());
decompiler.addToken(Token.RP);
node.addChildToBack(vars);
boolean letExpr = node.getType() == Token.LETEXPR;
if (node.getBody() != null) {
if (letExpr) {
decompiler.addName(" ");
} else {
decompiler.addEOL(Token.LC);
}
node.addChildToBack(transform(node.getBody()));
if (!letExpr) {
decompiler.addEOL(Token.RC);
}
}
return node;
} finally {
popScope();
}
}
use of org.mozilla.javascript.ast.LetNode in project HL4A by HL4A.
the class Parser method let.
// have to pass in 'let' kwd position to compute kid offsets properly
private AstNode let(boolean isStatement, int pos) throws IOException {
LetNode pn = new LetNode(pos);
pn.setLineno(ts.lineno);
if (mustMatchToken(Token.LP, "msg.no.paren.after.let"))
pn.setLp(ts.tokenBeg - pos);
pushScope(pn);
try {
VariableDeclaration vars = variables(Token.LET, ts.tokenBeg, isStatement);
pn.setVariables(vars);
if (mustMatchToken(Token.RP, "msg.no.paren.let")) {
pn.setRp(ts.tokenBeg - pos);
}
if (isStatement && peekToken() == Token.LC) {
// let statement
consumeToken();
// position stmt at LC
int beg = ts.tokenBeg;
AstNode stmt = statements();
mustMatchToken(Token.RC, "msg.no.curly.let");
stmt.setLength(ts.tokenEnd - beg);
pn.setLength(ts.tokenEnd - pos);
pn.setBody(stmt);
pn.setType(Token.LET);
} else {
// let expression
AstNode expr = expr();
pn.setLength(getNodeEnd(expr) - pos);
pn.setBody(expr);
if (isStatement) {
// let expression in statement context
ExpressionStatement es = new ExpressionStatement(pn, !insideFunction());
es.setLineno(pn.getLineno());
return es;
}
}
} finally {
popScope();
}
return pn;
}
Aggregations