org.mozilla.javascript.ast.AstNode Java Examples

The following examples show how to use org.mozilla.javascript.ast.AstNode. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ConstraintGenUtil.java    From SJS with Apache License 2.0 6 votes vote down vote up
public static List<String> getPropertyNames(ObjectLiteral ol){
	List<String> propNames = new ArrayList<String>();
	for (ObjectProperty op : ol.getElements()){
		AstNode left = op.getLeft();
		if (left instanceof Name){
			propNames.add(((Name)left).getIdentifier());
		} else if (left instanceof StringLiteral){
			String identifier = ConstraintGenUtil.removeQuotes(((StringLiteral)left).toSource());
			propNames.add(identifier);
		} else {
			System.err.println(left.getClass().getName() + " " + left.toSource());
			throw new Error("unsupported case in getPropertyNames()");
		}
	}
	return propNames;
}
 
Example #2
Source File: Parser.java    From JsDroidCmd with Mozilla Public License 2.0 6 votes vote down vote up
private IfStatement ifStatement()
    throws IOException
{
    if (currentToken != Token.IF) codeBug();
    consumeToken();
    int pos = ts.tokenBeg, lineno = ts.lineno, elsePos = -1;
    ConditionData data = condition();
    AstNode ifTrue = statement(), ifFalse = null;
    if (matchToken(Token.ELSE)) {
        elsePos = ts.tokenBeg - pos;
        ifFalse = statement();
    }
    int end = getNodeEnd(ifFalse != null ? ifFalse : ifTrue);
    IfStatement pn = new IfStatement(pos, end - pos);
    pn.setCondition(data.condition);
    pn.setParens(data.lp - pos, data.rp - pos);
    pn.setThenPart(ifTrue);
    pn.setElsePart(ifFalse);
    pn.setElsePosition(elsePos);
    pn.setLineno(lineno);
    return pn;
}
 
Example #3
Source File: Parser.java    From JsDroidCmd with Mozilla Public License 2.0 6 votes vote down vote up
/**
 * Xml attribute expression:<p>
 *   {@code @attr}, {@code @ns::attr}, {@code @ns::*}, {@code @ns::*},
 *   {@code @*}, {@code @*::attr}, {@code @*::*}, {@code @ns::[expr]},
 *   {@code @*::[expr]}, {@code @[expr]} <p>
 * Called if we peeked an '@' token.
 */
private AstNode attributeAccess()
    throws IOException
{
    int tt = nextToken(), atPos = ts.tokenBeg;

    switch (tt) {
      // handles: @name, @ns::name, @ns::*, @ns::[expr]
      case Token.NAME:
          return propertyName(atPos, ts.getString(), 0);

      // handles: @*, @*::name, @*::*, @*::[expr]
      case Token.MUL:
          saveNameTokenData(ts.tokenBeg, "*", ts.lineno);
          return propertyName(atPos, "*", 0);

      // handles @[expr]
      case Token.LB:
          return xmlElemRef(atPos, null, -1);

      default:
          reportError("msg.no.name.after.xmlAttr");
          return makeErrorNode();
    }
}
 
Example #4
Source File: DirectionalConstraintSolver.java    From SJS with Apache License 2.0 6 votes vote down vote up
/**
 * conservative check that returns false only for terms that obviously do not represent methods
 *
 * TODO move this code inside ITypeTerm??
 * @param t
 * @return
 */
private boolean possiblyAMethodTerm(ITypeTerm t) {
    if (ConstraintGenUtil.isNullUndefinedLitOrVoidOp(t)) {
        return false;
    }
    if (t instanceof ExpressionTerm) {
        ExpressionTerm et = (ExpressionTerm) t;
        AstNode node = et.getNode();
        if (node != null) {
            return !(node instanceof NumberLiteral
                    || node instanceof StringLiteral);
        }
    }
    return !(t instanceof ArrayLiteralTerm
            || t instanceof MapLiteralTerm
            || t instanceof ObjectLiteralTerm
            || t instanceof TypeConstantTerm);
}
 
Example #5
Source File: ConstraintFactory.java    From SJS with Apache License 2.0 6 votes vote down vote up
/**
 * Find or create a term representing a FunctionNode (function definition). The
 * created FunctionTerm provides methods for accessing the terms corresponding to the
 * function's parameters and return type. The boolean flag isMethod indicates whether
 * the function is a method.
 */
public FunctionTerm findOrCreateFunctionTerm(FunctionNode fun, FunctionTerm.FunctionKind funType) {
    if (!functionTerms.containsKey(fun)){
        FunctionTerm var = new FunctionTerm(fun, funType);
        var.setReturnVariable(this.findOrCreateFunctionReturnTerm(var, fun.getParamCount()));
        List<AstNode> params = fun.getParams();
        List<NameDeclarationTerm> paramVars = new ArrayList<NameDeclarationTerm>();
        for (int i=0; i < params.size(); i++){
            AstNode param = params.get(i);
            if (param instanceof Name){
                NameDeclarationTerm paramCV = this.findOrCreateNameDeclarationTerm((Name)param);
                paramVars.add(paramCV);
            } else {
                throw new Error("unimplemented case in findOrCreateFunctionVariable");
            }
        }
        var.setParamVariables(paramVars);
        functionTerms.put(fun, var);
    }
    return functionTerms.get(fun);
}
 
Example #6
Source File: Parser.java    From JsDroidCmd with Mozilla Public License 2.0 6 votes vote down vote up
private AstNode name(int ttFlagged, int tt) throws IOException {
    String nameString = ts.getString();
    int namePos = ts.tokenBeg, nameLineno = ts.lineno;
    if (0 != (ttFlagged & TI_CHECK_LABEL) && peekToken() == Token.COLON) {
        // Do not consume colon.  It is used as an unwind indicator
        // to return to statementHelper.
        Label label = new Label(namePos, ts.tokenEnd - namePos);
        label.setName(nameString);
        label.setLineno(ts.lineno);
        return label;
    }
    // Not a label.  Unfortunately peeking the next token to check for
    // a colon has biffed ts.tokenBeg, ts.tokenEnd.  We store the name's
    // bounds in instance vars and createNameNode uses them.
    saveNameTokenData(namePos, nameString, nameLineno);

    if (compilerEnv.isXmlAvailable()) {
        return propertyName(-1, nameString, 0);
    } else {
        return createNameNode(true, Token.NAME);
    }
}
 
Example #7
Source File: ConstraintVisitor.java    From SJS with Apache License 2.0 6 votes vote down vote up
/**
 * Create constraints for an object literal.
 */
private ITypeTerm processObjectLiteralForObject(ObjectLiteral n) {
	ITypeTerm expTerm = findOrCreateObjectLiteralTerm(n);
	ObjectLiteral o = (ObjectLiteral)n;
	for (ObjectProperty prop : o.getElements()){
		AstNode left = prop.getLeft();
		AstNode right = prop.getRight();
		if (left instanceof Name){
			String identifier = ((Name)left).getIdentifier();

			// for object literal o = { name_1 : exp_1, ..., name_k : exp_k } generate
			// a constraint |exp_i| <: prop(|o|, name_i)

			ITypeTerm propTerm = findOrCreatePropertyAccessTerm(expTerm, identifier, null);
			ITypeTerm valTerm = processExpression(right);
			processCopy(right, valTerm, propTerm, n.getLineno(), null);
		}
	}
	return expTerm;
}
 
Example #8
Source File: Parser.java    From JsDroidCmd with Mozilla Public License 2.0 6 votes vote down vote up
private AstNode shiftExpr()
    throws IOException
{
    AstNode pn = addExpr();
    for (;;) {
        int tt = peekToken(), opPos = ts.tokenBeg;
        switch (tt) {
          case Token.LSH:
          case Token.URSH:
          case Token.RSH:
            consumeToken();
            pn = new InfixExpression(tt, pn, addExpr(), opPos);
            continue;
        }
        break;
    }
    return pn;
}
 
Example #9
Source File: IRFactory.java    From JsDroidCmd with Mozilla Public License 2.0 6 votes vote down vote up
private Node transformReturn(ReturnStatement node) {
    boolean expClosure = Boolean.TRUE.equals(node.getProp(Node.EXPRESSION_CLOSURE_PROP));
    boolean isArrow = Boolean.TRUE.equals(node.getProp(Node.ARROW_FUNCTION_PROP));
    if (expClosure) {
        if (!isArrow) {
            decompiler.addName(" ");
        }
    } else {
        decompiler.addToken(Token.RETURN);
    }
    AstNode rv = node.getReturnValue();
    Node value = rv == null ? null : transform(rv);
    if (!expClosure) decompiler.addEOL(Token.SEMI);
    return rv == null
        ? new Node(Token.RETURN, node.getLineno())
        : new Node(Token.RETURN, value, node.getLineno());
}
 
Example #10
Source File: IRFactory.java    From JsDroidCmd with Mozilla Public License 2.0 6 votes vote down vote up
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;
}
 
Example #11
Source File: ConstraintVisitor.java    From SJS with Apache License 2.0 6 votes vote down vote up
/**
 * call a function through a closure
 */
private void processClosureCall(FunctionCall fc) {

	AstNode target = fc.getTarget();
	ITypeTerm funVar = processExpression(target);

	// for call foo(E_1,...,E_n), equate the type of the call to ret(foo)
	FunctionCallTerm callTerm = findOrCreateFunctionCallTerm(fc);
	callTerm.setTarget(funVar);
	ITypeTerm retTerm = findOrCreateFunctionReturnTerm(funVar, fc.getArguments().size(), fc.getLineno(), fc);
	addTypeEqualityConstraint(callTerm, retTerm, fc.getLineno(), null);

	// for call foo(E_1,...,E_n), generate constraints |E_i| <: Param(foo,i)
	for (int i=0; i < fc.getArguments().size(); i++){
		AstNode arg = fc.getArguments().get(i);
		ITypeTerm argExp = processExpression(arg);
		ITypeTerm paramExp = findOrCreateFunctionParamTerm(funVar, i, fc.getArguments().size(), fc.getLineno());
		processCopy(arg, argExp, paramExp,
				fc.getLineno(), (solution) ->
						subtypeError("bad argument " + shortSrc(arg) + " passed to function",
								solution.typeOfTerm(argExp), solution.typeOfTerm(paramExp), locationOf(arg)));
	}
}
 
Example #12
Source File: ConstraintVisitor.java    From SJS with Apache License 2.0 6 votes vote down vote up
/**
 * For a function definition (FunctionNode), create constraints equating its
 * parameters to param(.) variables, and equate the type of the function name
 * to the type of the entire function definition.
 */
private void createFunctionNodeConstraints(FunctionNode node, ITypeTerm funTerm){
	// if the function has a name, equate the types of the function node and the function name
	Name funName = node.getFunctionName();
	if (funName != null){
		ITypeTerm nameTerm = findOrCreateNameDeclarationTerm(funName);
		addSubTypeConstraint(funTerm, nameTerm, node.getLineno(), null);
	}

	// for a function f with params v1, v2, ... generate param(|f|,i) = |v_i|
	for (int i=0; i < node.getParamCount(); i++){
		AstNode param = node.getParams().get(i);
		if (param instanceof Name){
			Name name = (Name)param;
			ITypeTerm nameVar = findOrCreateNameDeclarationTerm(name);
			ITypeTerm paramVar = findOrCreateFunctionParamTerm(funTerm, i, node.getParamCount(), node.getLineno());
			addTypeEqualityConstraint(paramVar, nameVar, param.getLineno(), null);
		} else {
			error("createFunctionNodeConstraints: unexpected parameter type", node);
		}
	}

}
 
Example #13
Source File: Parser.java    From JsDroidCmd with Mozilla Public License 2.0 6 votes vote down vote up
private ThrowStatement throwStatement()
    throws IOException
{
    if (currentToken != Token.THROW) codeBug();
    consumeToken();
    int pos = ts.tokenBeg, lineno = ts.lineno;
    if (peekTokenOrEOL() == Token.EOL) {
        // ECMAScript does not allow new lines before throw expression,
        // see bug 256617
        reportError("msg.bad.throw.eol");
    }
    AstNode expr = expr();
    ThrowStatement pn = new ThrowStatement(pos, getNodeEnd(expr), expr);
    pn.setLineno(lineno);
    return pn;
}
 
Example #14
Source File: MapLiteralTerm.java    From SJS with Apache License 2.0 6 votes vote down vote up
public List<String> getPropertyNames(){
	List<String> propNames = new ArrayList<String>();
	ObjectLiteral ol = (ObjectLiteral)this.getNode();
	for (ObjectProperty op : ol.getElements()){
		AstNode left = op.getLeft();
		if (left instanceof Name){
			propNames.add(((Name)left).getIdentifier());
		} else if (left instanceof StringLiteral){
			String identifier = ConstraintGenUtil.removeQuotes(((StringLiteral)left).toSource());
			propNames.add(identifier);
		} else {
			System.err.println(left.getClass().getName() + " " + left.toSource());
			throw new Error("unsupported case in getPropertyNames()");
		}
	}
	return propNames;
}
 
Example #15
Source File: Parser.java    From JsDroidCmd with Mozilla Public License 2.0 5 votes vote down vote up
private void warnTrailingComma(int pos, List<?> elems, int commaPos) {
    if (compilerEnv.getWarnTrailingComma()) {
        // back up from comma to beginning of line or array/objlit
        if (!elems.isEmpty()) {
            pos = ((AstNode)elems.get(0)).getPosition();
        }
        pos = Math.max(pos, lineBeginningFor(commaPos));
        addWarning("msg.extra.trailing.comma", pos, commaPos - pos);
    }
}
 
Example #16
Source File: Parser.java    From JsDroidCmd with Mozilla Public License 2.0 5 votes vote down vote up
void markDestructuring(AstNode node) {
    if (node instanceof DestructuringForm) {
        ((DestructuringForm)node).setIsDestructuring(true);
    } else if (node instanceof ParenthesizedExpression) {
        markDestructuring(((ParenthesizedExpression)node).getExpression());
    }
}
 
Example #17
Source File: ConstraintGenUtil.java    From SJS with Apache License 2.0 5 votes vote down vote up
@Override
public boolean visit(AstNode node) {
	if (node instanceof ReturnStatement){
		ReturnStatement rs = (ReturnStatement)node;
		if (rs.getReturnValue() != null){
			if (ConstraintGenUtil.findEnclosingFunction(node) == fun){
				returnsValue = true;
			}
		}
	}
	return true;
}
 
Example #18
Source File: ConstraintGenUtil.java    From SJS with Apache License 2.0 5 votes vote down vote up
/**
 * Check if an AstNode corresponds to the "this" reference.
 *
 * @param node
 * @return
 */
public static boolean isThis(AstNode node){
	if (node instanceof KeywordLiteral){
		KeywordLiteral kw = (KeywordLiteral)node;
		if (kw.toSource().equals("this")){
			return true;
		}
	}
	return false;
}
 
Example #19
Source File: Parser.java    From JsDroidCmd with Mozilla Public License 2.0 5 votes vote down vote up
private AstNode addExpr()
    throws IOException
{
    AstNode pn = mulExpr();
    for (;;) {
        int tt = peekToken(), opPos = ts.tokenBeg;
        if (tt == Token.ADD || tt == Token.SUB) {
            consumeToken();
            pn = new InfixExpression(tt, pn, mulExpr(), opPos);
            continue;
        }
        break;
    }
    return pn;
}
 
Example #20
Source File: ConstraintGenUtil.java    From SJS with Apache License 2.0 5 votes vote down vote up
/**
 * find the function definition that immediately surrounds a given AST node.
 * Returns null if there is no surrounding function.
 *
 */
public static FunctionNode findEnclosingFunction(AstNode node) {
	AstNode current = node;
	while (current != null && !(current instanceof FunctionNode)){
		current = current.getParent();
	}
	FunctionNode fun = (FunctionNode)current;
	return fun;
}
 
Example #21
Source File: Parser.java    From JsDroidCmd with Mozilla Public License 2.0 5 votes vote down vote up
private ObjectProperty methodDefinition(int pos, AstNode propName, int entryKind)
    throws IOException
{
    FunctionNode fn = function(FunctionNode.FUNCTION_EXPRESSION);
    // We've already parsed the function name, so fn should be anonymous.
    Name name = fn.getFunctionName();
    if (name != null && name.length() != 0) {
        reportError("msg.bad.prop");
    }
    ObjectProperty pn = new ObjectProperty(pos);
    switch (entryKind) {
    case GET_ENTRY:
        pn.setIsGetterMethod();
        fn.setFunctionIsGetterMethod();
        break;
    case SET_ENTRY:
        pn.setIsSetterMethod();
        fn.setFunctionIsSetterMethod();
        break;
    case METHOD_ENTRY:
        pn.setIsNormalMethod();
        fn.setFunctionIsNormalMethod();
        break;
    }
    int end = getNodeEnd(fn);
    pn.setLeft(propName);
    pn.setRight(fn);
    pn.setLength(end - pos);
    return pn;
}
 
Example #22
Source File: Parser.java    From JsDroidCmd with Mozilla Public License 2.0 5 votes vote down vote up
private AstNode defaultXmlNamespace()
    throws IOException
{
    if (currentToken != Token.DEFAULT) codeBug();
    consumeToken();
    mustHaveXML();
    setRequiresActivation();
    int lineno = ts.lineno, pos = ts.tokenBeg;

    if (!(matchToken(Token.NAME) && "xml".equals(ts.getString()))) {
        reportError("msg.bad.namespace");
    }
    if (!(matchToken(Token.NAME) && "namespace".equals(ts.getString()))) {
        reportError("msg.bad.namespace");
    }
    if (!matchToken(Token.ASSIGN)) {
        reportError("msg.bad.namespace");
    }

    AstNode e = expr();
    UnaryExpression dxmln = new UnaryExpression(pos, getNodeEnd(e) - pos);
    dxmln.setOperator(Token.DEFAULTNAMESPACE);
    dxmln.setOperand(e);
    dxmln.setLineno(lineno);

    ExpressionStatement es = new ExpressionStatement(dxmln, true);
    return es;
}
 
Example #23
Source File: Parser.java    From JsDroidCmd with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Parse a JavaScript 1.7 Array comprehension.
 * @param result the first expression after the opening left-bracket
 * @param pos start of LB token that begins the array comprehension
 * @return the array comprehension or an error node
 */
private AstNode arrayComprehension(AstNode result, int pos)
    throws IOException
{
    List<ArrayComprehensionLoop> loops =
            new ArrayList<ArrayComprehensionLoop>();
    while (peekToken() == Token.FOR) {
        loops.add(arrayComprehensionLoop());
    }
    int ifPos = -1;
    ConditionData data = null;
    if (peekToken() == Token.IF) {
        consumeToken();
        ifPos = ts.tokenBeg - pos;
        data = condition();
    }
    mustMatchToken(Token.RB, "msg.no.bracket.arg");
    ArrayComprehension pn = new ArrayComprehension(pos, ts.tokenEnd - pos);
    pn.setResult(result);
    pn.setLoops(loops);
    if (data != null) {
        pn.setIfPosition(ifPos);
        pn.setFilter(data.condition);
        pn.setFilterLp(data.lp - pos);
        pn.setFilterRp(data.rp - pos);
    }
    return pn;
}
 
Example #24
Source File: ConstraintVisitor.java    From SJS with Apache License 2.0 5 votes vote down vote up
/**
 * assignment to an object property
 */
private void processAssignToProperty(Assignment a, AstNode left, AstNode right, ITypeTerm expTerm) throws Error {

	PropertyGet pg = (PropertyGet)left;
	AstNode base = pg.getTarget();
	Name prop = pg.getProperty();
	ITypeTerm pgTerm = findOrCreateExpressionTerm(pg);

	ITypeTerm baseTerm;
	if (base instanceof KeywordLiteral && ConstraintGenUtil.isThis(base)){
		baseTerm = findOrCreateThisTerm(base);
	} else {
		baseTerm = generateReceiverConstraints(pg);
	}

	int assignLineNo = a.getLineno();
	// detect assignments of the form C.prototype.foo = ...
	if (base instanceof PropertyGet) {
		PropertyGet basePG = (PropertyGet) base;
		String baseProp = basePG.getProperty().getIdentifier();
		if (baseProp.equals("prototype")) {
			checkForValidProtoPropAssign(a, pg, assignLineNo, basePG);
		}
	}
	ITypeTerm leftTerm = findOrCreatePropertyAccessTerm(baseTerm, prop.getIdentifier(), null);
	ITypeTerm rightTerm = processExpression(right);
	addTypeEqualityConstraint(pgTerm, leftTerm, assignLineNo, (solution) ->
			typeEqualityError("incompatible types",
					solution.typeOfTerm(leftTerm), solution.typeOfTerm(pgTerm), locationOf(pg)));
	addTypeEqualityConstraint(expTerm, leftTerm, assignLineNo, (solution) ->
			typeEqualityError("incompatible types",
					solution.typeOfTerm(leftTerm), solution.typeOfTerm(expTerm), locationOf(a)));
	processCopy(right, rightTerm, leftTerm, assignLineNo,
			(solution) -> badPropertyWrite(pg, solution.typeOfTerm(baseTerm), hasType(leftTerm, solution) ? solution.typeOfTerm(leftTerm) : null, solution.typeOfTerm(rightTerm)));
}
 
Example #25
Source File: Parser.java    From JsDroidCmd with Mozilla Public License 2.0 5 votes vote down vote up
private AstNode andExpr()
    throws IOException
{
    AstNode pn = bitOrExpr();
    if (matchToken(Token.AND)) {
        int opPos = ts.tokenBeg;
        pn = new InfixExpression(Token.AND, pn, andExpr(), opPos);
    }
    return pn;
}
 
Example #26
Source File: Parser.java    From JsDroidCmd with Mozilla Public License 2.0 5 votes vote down vote up
private AstNode orExpr()
    throws IOException
{
    AstNode pn = andExpr();
    if (matchToken(Token.OR)) {
        int opPos = ts.tokenBeg;
        pn = new InfixExpression(Token.OR, pn, orExpr(), opPos);
    }
    return pn;
}
 
Example #27
Source File: ConstraintVisitor.java    From SJS with Apache License 2.0 5 votes vote down vote up
/**
 * generate constraints for initializers
 */
private void processVariableInitializer(AstNode node) throws Error {
	VariableInitializer vi = (VariableInitializer)node;
	AstNode varname = vi.getTarget();
	AstNode initializer = vi.getInitializer();
	if (varname instanceof Name){
           ITypeTerm leftTerm = findOrCreateNameDeclarationTerm((Name)varname); // declaration of variable, so no need to create ITerm for expression
		if (initializer != null){
			ITypeTerm rightTerm = processExpression(initializer);
			processCopy(initializer, rightTerm, leftTerm,
					node.getLineno(), (solution) -> subtypeError("bad initialization of " + varname.toSource(),
							solution.typeOfTerm(rightTerm), solution.typeOfTerm(leftTerm), locationOf(node)));
		}
		// in case of multiple declarations of same identifier,
		// equate the type of this particular Name to the type of
		// the canonical Name
           ITypeTerm localTerm = factory.findOrCreateNameDeclTermNoLookup((Name) varname);
           if (localTerm != leftTerm) {
               addTypeEqualityConstraint(localTerm, leftTerm, node.getLineno(),
                       (solution) -> typeEqualityError("different declarations within the same scope must have the same type",
                               solution.typeOfTerm(localTerm), solution.typeOfTerm(leftTerm), locationOf(node)));

           }
	} else {
		error("unsupported type of VariableInitializer", varname);
	}
}
 
Example #28
Source File: ClassDefScanner.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Helper to report error for given node position in ast tree.
 */
private RuntimeException reportError(final AstNode node, final String message, Object... params) {
  throw Context.reportRuntimeError(String.format(message, params),
      source.getAbsolutePath(),
      node.getLineno(), // seems to always be the line before?
      node.debugPrint(),
      0 // line-offset is unknown?
  );
}
 
Example #29
Source File: ConstraintGenUtil.java    From SJS with Apache License 2.0 5 votes vote down vote up
/**
 * Tests if an object literal is an object by checking that all
 * properties are unquoted.
 */
static boolean isObject(ObjectLiteral o){
	boolean result = (o.getElements().size() > 0);
	for (ObjectProperty prop : o.getElements()){
		AstNode left = prop.getLeft();
		result = result && (left instanceof Name);
	}
	return result;
}
 
Example #30
Source File: IRFactory.java    From JsDroidCmd with Mozilla Public License 2.0 5 votes vote down vote up
private Node transformAssignment(Assignment node) {
    AstNode left = removeParens(node.getLeft());
    Node target = null;
    if (isDestructuring(left)) {
        decompile(left);
        target = left;
    } else {
        target = transform(left);
    }
    decompiler.addToken(node.getType());
    return createAssignment(node.getType(),
                            target,
                            transform(node.getRight()));
}