/** * Returns a new EXPR_RESULT node. * * <p>Statements have no type information, so this is functionally the same as calling {@code * IR.exprResult(expr)}. It exists so that a pass can be consistent about always using {@code * AstFactory} to create new nodes. */ Node exprResult(Node expr) { return IR.exprResult(expr); }
/** * Creates an EXPR_RESULT. * * @param child The expression itself. * @return Newly created EXPR node with the child as subexpression. */ static Node newExpr(Node child) { return IR.exprResult(child).srcref(child); }
/** * Creates an EXPR_RESULT. * * @param child The expression itself. * @return Newly created EXPR node with the child as subexpression. */ static Node newExpr(Node child) { return IR.exprResult(child).srcref(child); }
Node buildInstrumentationIncrementer(int lineNumber, String fileName, String identifier) { Node getNumber = buildLineNumberExpression(lineNumber, fileName, identifier); Node inc = IR.inc(getNumber, true); return IR.exprResult(inc); }
/** Creates node that make a call to a context function. */ Node callContextMethodResult(Node sourceNode, String methodName, Node... args) { return IR.exprResult(callContextMethod(sourceNode, methodName, args)) .useSourceInfoFrom(sourceNode); }
private static Node makeGeneratorMarker(int i) { Node n = IR.exprResult(IR.number(i)); n.setGeneratorMarker(true); return n; }
public Node buildConditionalStatement(int startLine, int endLine, String fileName) { Node indexLineNumber = buildLineNumberExpression(startLine, fileName, "conditionals"); Node lineNumberLiteral = IR.number(endLine); Node assignment = IR.assign(indexLineNumber, lineNumberLiteral); return IR.exprResult(assignment); }
public Node buildConditionalStatement(int startLine, int endLine, String fileName) { Node indexLineNumber = buildLineNumberExpression(startLine, fileName, "conditionals"); Node lineNumberLiteral = IR.number(endLine); Node assignment = IR.assign(indexLineNumber, lineNumberLiteral); return IR.exprResult(assignment); }
/** Returns an assign replacing the equivalent var or let declaration. */ private static Node varToAssign(Node var) { Node assign = IR.assign(var.getFirstChild().cloneNode(), var.getFirstChild().removeFirstChild()); return IR.exprResult(assign).useSourceInfoIfMissingFromForTree(var); } }
public Node buildLineAndConditionCall(String uri, int lineNo, int conditionNo) { Node indexLineNumber = buildLineDeclaration(uri, lineNo); Node conditionNumberLiteral = IR.number(conditionNo); Node indexConditionNumber = IR.getelem(indexLineNumber, conditionNumberLiteral); Node initCall = IR.string("ranCondition"); Node propertyName = IR.getprop(indexConditionNumber, initCall); Node result = IR.name("result"); Node fnCall = IR.call(propertyName, result); return IR.exprResult(fnCall); }
/** Inserts a call to $jscomp.initSymbol() before {@code n}. */ private void initSymbolBefore(Node n) { compiler.ensureLibraryInjected("es6/symbol", false); Node statement = NodeUtil.getEnclosingStatement(n); Node initSymbol = IR.exprResult(IR.call(NodeUtil.newQName(compiler, "$jscomp.initSymbol"))); statement.getParent().addChildBefore(initSymbol.useSourceInfoFromForTree(statement), statement); compiler.reportChangeToEnclosingScope(initSymbol); }
@Override void removeInternal(AbstractCompiler compiler) { Node nameNode = declarationStatement.getOnlyChild(); Node valueNode = nameNode.getFirstChild(); if (valueNode != null && NodeUtil.mayHaveSideEffects(valueNode, compiler)) { compiler.reportChangeToEnclosingScope(declarationStatement); valueNode.detach(); declarationStatement.replaceWith(IR.exprResult(valueNode).useSourceInfoFrom(valueNode)); } else { NodeUtil.deleteNode(declarationStatement, compiler); } }
private void addExtern(String export) { Node propstmt = IR.exprResult( IR.getprop(NodeUtil.newQName(compiler, "Object.prototype"), IR.string(export))); NodeUtil.setDebugInformation(propstmt, getSynthesizedExternsRoot(), export); getSynthesizedExternsRoot().addChildToBack(propstmt); compiler.reportCodeChange(); }
private static Node createFinallyJumpBlock(Node finallyName, int finallyStartState) { int jumpPoint = generatorCaseCount++; Node setReturnState = IR.exprResult(IR.assign(finallyName.cloneTree(), IR.number(jumpPoint))); Node toFinally = createStateUpdate(finallyStartState); Node returnPoint = makeGeneratorMarker(jumpPoint); Node returnBlock = IR.block(setReturnState, toFinally, createSafeBreak()); returnBlock.addChildToBack(returnPoint); return returnBlock; }
/** * Inserts a call to $jscomp.initSymbol() before {@code n}. */ private void initSymbolBefore(Node n) { compiler.ensureLibraryInjected("es6_runtime", false); Node statement = NodeUtil.getEnclosingStatement(n); Node initSymbol = IR.exprResult(IR.call(NodeUtil.newQName(compiler, "$jscomp.initSymbol"))); statement.getParent().addChildBefore(initSymbol.useSourceInfoFromForTree(statement), statement); compiler.reportCodeChange(); }
public Node buildLineAndConditionInitialisation(String uri, int lineNo, int conditionNo, int position, int length) { Node indexLineNumber = buildLineDeclaration(uri, lineNo); Node conditionNumberLiteral = IR.number(conditionNo); Node indexConditionNumber = IR.getelem(indexLineNumber, conditionNumberLiteral); Node positionLiteral = IR.number(position); Node lengthLiteral = IR.number(length); Node initCall = IR.string("init"); Node propertyName = IR.getprop(indexConditionNumber, initCall); Node fnCall = IR.call(propertyName, positionLiteral, lengthLiteral); return IR.exprResult(fnCall); }
public Node buildLineAndConditionInitialisation(String uri, int lineNo, int conditionNo, int position, int length) { Node indexLineNumber = buildLineDeclaration(uri, lineNo); Node conditionNumberLiteral = IR.number(conditionNo); Node indexConditionNumber = IR.getelem(indexLineNumber, conditionNumberLiteral); Node positionLiteral = IR.number(position); Node lengthLiteral = IR.number(length); Node initCall = IR.string("init"); Node propertyName = IR.getprop(indexConditionNumber, initCall); Node fnCall = IR.call(propertyName, positionLiteral, lengthLiteral); return IR.exprResult(fnCall); }
@Override public void visit(NodeTraversal t, Node n, Node parent) { if (n.isReturn() && n.hasChildren()) { Node retVal = n.getFirstChild(); n.removeChild(retVal); parent.replaceChild(n, IR.exprResult( IR.assign( IR.getprop(IR.name("module"), IR.string("exports")), retVal)) .useSourceInfoFromForTree(n)); } } }
@Override public void visit(NodeTraversal t, Node n, Node parent) { if (n.isReturn() && n.hasChildren()) { Node retVal = n.getFirstChild(); n.removeChild(retVal); parent.replaceChild(n, IR.exprResult( IR.assign( IR.getprop(IR.name("module"), IR.string("exports")), retVal)) .useSourceInfoFromForTree(n)); } } }
private void addExtern(String export) { Node objectPrototype = NodeUtil.newQName(compiler, "Object.prototype"); JSType objCtor = compiler.getTypeRegistry().getNativeType(JSTypeNative.OBJECT_FUNCTION_TYPE); objectPrototype.getFirstChild().setJSType(objCtor); Node propstmt = IR.exprResult(IR.getprop(objectPrototype, IR.string(export))); propstmt.useSourceInfoFromForTree(getSynthesizedExternsRoot()); propstmt.setOriginalName(export); getSynthesizedExternsRoot().addChildToBack(propstmt); compiler.reportChangeToEnclosingScope(propstmt); }