Search in sources :

Example 1 with LetNode

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;
}
Also used : WhileLoop(org.mozilla.javascript.ast.WhileLoop) ForLoop(org.mozilla.javascript.ast.ForLoop) GeneratorExpressionLoop(org.mozilla.javascript.ast.GeneratorExpressionLoop) ArrayComprehensionLoop(org.mozilla.javascript.ast.ArrayComprehensionLoop) Loop(org.mozilla.javascript.ast.Loop) ForInLoop(org.mozilla.javascript.ast.ForInLoop) DoLoop(org.mozilla.javascript.ast.DoLoop) LetNode(org.mozilla.javascript.ast.LetNode) AstNode(org.mozilla.javascript.ast.AstNode)

Example 2 with LetNode

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();
    }
}
Also used : ScriptNode(org.mozilla.javascript.ast.ScriptNode) AstNode(org.mozilla.javascript.ast.AstNode) LetNode(org.mozilla.javascript.ast.LetNode) FunctionNode(org.mozilla.javascript.ast.FunctionNode)

Example 3 with LetNode

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;
}
Also used : LetNode(org.mozilla.javascript.ast.LetNode) ExpressionStatement(org.mozilla.javascript.ast.ExpressionStatement) VariableDeclaration(org.mozilla.javascript.ast.VariableDeclaration) AstNode(org.mozilla.javascript.ast.AstNode)

Aggregations

AstNode (org.mozilla.javascript.ast.AstNode)3 LetNode (org.mozilla.javascript.ast.LetNode)3 ArrayComprehensionLoop (org.mozilla.javascript.ast.ArrayComprehensionLoop)1 DoLoop (org.mozilla.javascript.ast.DoLoop)1 ExpressionStatement (org.mozilla.javascript.ast.ExpressionStatement)1 ForInLoop (org.mozilla.javascript.ast.ForInLoop)1 ForLoop (org.mozilla.javascript.ast.ForLoop)1 FunctionNode (org.mozilla.javascript.ast.FunctionNode)1 GeneratorExpressionLoop (org.mozilla.javascript.ast.GeneratorExpressionLoop)1 Loop (org.mozilla.javascript.ast.Loop)1 ScriptNode (org.mozilla.javascript.ast.ScriptNode)1 VariableDeclaration (org.mozilla.javascript.ast.VariableDeclaration)1 WhileLoop (org.mozilla.javascript.ast.WhileLoop)1