Node createThis(JSType thisType) { Node result = IR.thisNode(); if (isAddingTypes()) { result.setJSType(checkNotNull(thisType)); } return result; }
private Node baseCall(String baseClass, String methodName, Node arguments) { Preconditions.checkNotNull(baseClass); Preconditions.checkNotNull(methodName); String baseMethodName; if (methodName.equals("constructor")) { baseMethodName = baseClass + ".call"; } else { baseMethodName = Joiner.on('.').join(baseClass, "prototype", methodName, "call"); } Node methodCall = NodeUtil.newQName(compiler, baseMethodName); Node callNode = IR.call(methodCall, IR.thisNode()); if (arguments != null) { callNode.addChildrenToBack(arguments); } return callNode; }
/** Creates a THIS node with the correct type for the given function node. */ Node createThisForFunction(Node functionNode) { final Node result = IR.thisNode(); if (isAddingTypes()) { result.setJSType(getTypeOfThisForFunctionNode(functionNode)); } return result; }
String nodeName = name.substring(0, endPos); if ("this".equals(nodeName)) { node = IR.thisNode(); } else { node = newName(compiler, nodeName);
String nodeName = name.substring(0, endPos); if ("this".equals(nodeName)) { node = IR.thisNode(); } else if ("super".equals(nodeName)) { node = IR.superNode();
private void visitSuperGet(Node superGet) { Node name = superGet.getLastChild().cloneTree(); Node callSuperGet = IR.call( NodeUtil.newQName(compiler, CALL_SUPER_GET).srcrefTree(superGet), IR.thisNode().srcref(superGet), superGet.isGetProp() ? renameProperty(name) : name); replace(superGet, callSuperGet); reportEs6Change(); }
private void visitSuperGet(Node superGet) { Node name = superGet.getLastChild().cloneTree(); Node callSuperGet = IR.call( NodeUtil.newQName(compiler, CALL_SUPER_GET).srcrefTree(superGet), IR.thisNode().srcref(superGet), superGet.isGetProp() ? renameProperty(name) : name); replace(superGet, callSuperGet); compiler.ensureLibraryInjected("es6_dart_runtime", false); compiler.reportChangeToEnclosingScope(callSuperGet); }
private void visitSuperSet(Node superSet) { Preconditions.checkArgument(superSet.isAssign()); // First, recurse on the assignment's right-hand-side. NodeTraversal.traverseEs6(compiler, superSet.getLastChild(), this); Node rhs = superSet.getLastChild(); Node superGet = superSet.getFirstChild(); Node name = superGet.getLastChild().cloneTree(); Node callSuperSet = IR.call( NodeUtil.newQName(compiler, CALL_SUPER_SET).srcrefTree(superSet), IR.thisNode().srcref(superSet), superGet.isGetProp() ? renameProperty(name) : name, rhs.cloneTree()); replace(superSet, callSuperSet); reportEs6Change(); }
private void visitSuperSet(Node superSet) { checkArgument(superSet.isAssign()); // First, recurse on the assignment's right-hand-side. NodeTraversal.traverse(compiler, superSet.getLastChild(), this); Node rhs = superSet.getLastChild(); Node superGet = superSet.getFirstChild(); Node name = superGet.getLastChild().cloneTree(); Node callSuperSet = IR.call( NodeUtil.newQName(compiler, CALL_SUPER_SET).srcrefTree(superSet), IR.thisNode().srcref(superSet), superGet.isGetProp() ? renameProperty(name) : name, rhs.cloneTree()); replace(superSet, callSuperSet); compiler.ensureLibraryInjected("es6_dart_runtime", false); compiler.reportChangeToEnclosingScope(callSuperSet); }
hoistRoot .getParent() .addChildAfter(IR.var(IR.name(GENERATOR_THIS), IR.thisNode()), hoistRoot);
private void addSyntheticConstructor(Node classNode) { Node superClass = classNode.getSecondChild(); Node classMembers = classNode.getLastChild(); Node memberDef; if (superClass.isEmpty()) { memberDef = IR.memberFunctionDef("constructor", IR.function(IR.name(""), IR.paramList(), IR.block())); } else { if (!superClass.isQualifiedName()) { // This will be reported as an error in Es6ToEs3Converter. return; } Node body = IR.block(); if (!classNode.isFromExterns()) { Node exprResult = IR.exprResult(IR.call( IR.getprop(superClass.cloneTree(), IR.string("apply")), IR.thisNode(), IR.name("arguments"))); body.addChildrenToFront(exprResult); } Node constructor = IR.function( IR.name(""), IR.paramList(IR.name("var_args")), body); memberDef = IR.memberFunctionDef("constructor", constructor); } memberDef.useSourceInfoIfMissingFromForTree(classNode); classMembers.addChildToFront(memberDef); }
JSDocInfo oldJSDocInfo = NodeUtil.getBestJSDocInfo(node); Node globalRef = defineOnWindow ? IR.name(WINDOW_NAME) : IR.thisNode(); Node string = IR.string(name); Node getprop = IR.getprop(globalRef, string);
Node thisVar = IR.constNode(name, IR.thisNode()); thisVar.useSourceInfoIfMissingFromForTree(scopeRoot); scopeRoot.addChildToFront(thisVar);
Node thisVar = IR.constNode(name, IR.thisNode().setJSType(context.getThisType())); NodeUtil.addFeatureToScript(t.getCurrentScript(), Feature.CONST_DECLARATIONS); thisVar.useSourceInfoIfMissingFromForTree(scopeBody);
enclosingCall.addChildAfter(IR.thisNode(), callTarget); enclosingCall.useSourceInfoIfMissingFromForTree(enclosingCall); compiler.reportCodeChange();
n.removeChildAfter(newCallTarget); n.addChildToBack(IR.thisNode().srcref(n));