Search in sources :

Example 1 with ParenthesizedExpression

use of org.mozilla.javascript.ast.ParenthesizedExpression in project st-js by st-js.

the class RhinoJavaScriptBuilder method paren.

/**
 * {@inheritDoc}
 */
@Override
public AstNode paren(AstNode expr) {
    ParenthesizedExpression paren = new ParenthesizedExpression();
    paren.setExpression(expr);
    return paren;
}
Also used : ParenthesizedExpression(org.mozilla.javascript.ast.ParenthesizedExpression)

Example 2 with ParenthesizedExpression

use of org.mozilla.javascript.ast.ParenthesizedExpression in project HL4A by HL4A.

the class Parser method parenExpr.

private AstNode parenExpr() throws IOException {
    boolean wasInForInit = inForInit;
    inForInit = false;
    try {
        Comment jsdocNode = getAndResetJsDoc();
        int lineno = ts.lineno;
        int begin = ts.tokenBeg;
        AstNode e = (peekToken() == Token.RP ? new EmptyExpression(begin) : expr());
        if (peekToken() == Token.FOR) {
            return generatorExpression(e, begin);
        }
        ParenthesizedExpression pn = new ParenthesizedExpression(e);
        if (jsdocNode == null) {
            jsdocNode = getAndResetJsDoc();
        }
        if (jsdocNode != null) {
            pn.setJsDocNode(jsdocNode);
        }
        mustMatchToken(Token.RP, "msg.no.paren");
        if (e.getType() == Token.EMPTY && peekToken() != Token.ARROW) {
            reportError("msg.syntax");
            return makeErrorNode();
        }
        pn.setLength(ts.tokenEnd - pn.getPosition());
        pn.setLineno(lineno);
        return pn;
    } finally {
        inForInit = wasInForInit;
    }
}
Also used : ParenthesizedExpression(org.mozilla.javascript.ast.ParenthesizedExpression) Comment(org.mozilla.javascript.ast.Comment) AstNode(org.mozilla.javascript.ast.AstNode) EmptyExpression(org.mozilla.javascript.ast.EmptyExpression)

Example 3 with ParenthesizedExpression

use of org.mozilla.javascript.ast.ParenthesizedExpression in project HL4A by HL4A.

the class IRFactory method transformParenExpr.

private Node transformParenExpr(ParenthesizedExpression node) {
    AstNode expr = node.getExpression();
    decompiler.addToken(Token.LP);
    int count = 1;
    while (expr instanceof ParenthesizedExpression) {
        decompiler.addToken(Token.LP);
        count++;
        expr = ((ParenthesizedExpression) expr).getExpression();
    }
    Node result = transform(expr);
    for (int i = 0; i < count; i++) {
        decompiler.addToken(Token.RP);
    }
    result.putProp(Node.PARENTHESIZED_PROP, Boolean.TRUE);
    return result;
}
Also used : ParenthesizedExpression(org.mozilla.javascript.ast.ParenthesizedExpression) ScriptNode(org.mozilla.javascript.ast.ScriptNode) AstNode(org.mozilla.javascript.ast.AstNode) LetNode(org.mozilla.javascript.ast.LetNode) FunctionNode(org.mozilla.javascript.ast.FunctionNode) AstNode(org.mozilla.javascript.ast.AstNode)

Example 4 with ParenthesizedExpression

use of org.mozilla.javascript.ast.ParenthesizedExpression in project HL4A by HL4A.

the class Parser method arrowFunction.

private AstNode arrowFunction(AstNode params) throws IOException {
    // line number where source starts
    int baseLineno = ts.lineno;
    // start of "function" kwd
    int functionSourceStart = params != null ? params.getPosition() : -1;
    FunctionNode fnNode = new FunctionNode(functionSourceStart);
    fnNode.setFunctionType(FunctionNode.ARROW_FUNCTION);
    fnNode.setJsDocNode(getAndResetJsDoc());
    // Would prefer not to call createDestructuringAssignment until codegen,
    // but the symbol definitions have to happen now, before body is parsed.
    Map<String, Node> destructuring = new HashMap<String, Node>();
    Set<String> paramNames = new HashSet<String>();
    PerFunctionVariables savedVars = new PerFunctionVariables(fnNode);
    try {
        if (params instanceof ParenthesizedExpression) {
            fnNode.setParens(0, params.getLength());
            AstNode p = ((ParenthesizedExpression) params).getExpression();
            if (!(p instanceof EmptyExpression)) {
                arrowFunctionParams(fnNode, p, destructuring, paramNames);
            }
        } else {
            arrowFunctionParams(fnNode, params, destructuring, paramNames);
        }
        if (!destructuring.isEmpty()) {
            Node destructuringNode = new Node(Token.COMMA);
            // Add assignment helper for each destructuring parameter
            for (Map.Entry<String, Node> param : destructuring.entrySet()) {
                Node assign = createDestructuringAssignment(Token.VAR, param.getValue(), createName(param.getKey()));
                destructuringNode.addChildToBack(assign);
            }
            fnNode.putProp(Node.DESTRUCTURING_PARAMS, destructuringNode);
        }
        fnNode.setBody(parseFunctionBody(FunctionNode.ARROW_FUNCTION, fnNode));
        fnNode.setEncodedSourceBounds(functionSourceStart, ts.tokenEnd);
        fnNode.setLength(ts.tokenEnd - functionSourceStart);
    } finally {
        savedVars.restore();
    }
    if (fnNode.isGenerator()) {
        reportError("msg.arrowfunction.generator");
        return makeErrorNode();
    }
    fnNode.setSourceName(sourceURI);
    fnNode.setBaseLineno(baseLineno);
    fnNode.setEndLineno(ts.lineno);
    return fnNode;
}
Also used : ParenthesizedExpression(org.mozilla.javascript.ast.ParenthesizedExpression) HashMap(java.util.HashMap) ScriptNode(org.mozilla.javascript.ast.ScriptNode) AstNode(org.mozilla.javascript.ast.AstNode) LetNode(org.mozilla.javascript.ast.LetNode) ErrorNode(org.mozilla.javascript.ast.ErrorNode) FunctionNode(org.mozilla.javascript.ast.FunctionNode) FunctionNode(org.mozilla.javascript.ast.FunctionNode) XmlString(org.mozilla.javascript.ast.XmlString) EmptyExpression(org.mozilla.javascript.ast.EmptyExpression) Map(java.util.Map) HashMap(java.util.HashMap) AstNode(org.mozilla.javascript.ast.AstNode) HashSet(java.util.HashSet)

Aggregations

ParenthesizedExpression (org.mozilla.javascript.ast.ParenthesizedExpression)4 AstNode (org.mozilla.javascript.ast.AstNode)3 EmptyExpression (org.mozilla.javascript.ast.EmptyExpression)2 FunctionNode (org.mozilla.javascript.ast.FunctionNode)2 LetNode (org.mozilla.javascript.ast.LetNode)2 ScriptNode (org.mozilla.javascript.ast.ScriptNode)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Comment (org.mozilla.javascript.ast.Comment)1 ErrorNode (org.mozilla.javascript.ast.ErrorNode)1 XmlString (org.mozilla.javascript.ast.XmlString)1