public static Node paramList(Node... params) { Node paramList = paramList(); for (Node param : params) { checkState(param.isName() || param.isRest()); paramList.addChildToBack(param); } return paramList; }
public static Node paramList(Node ... params) { Node paramList = paramList(); for (Node param : params) { Preconditions.checkState(param.isName() || param.isRest()); paramList.addChildToBack(param); } return paramList; }
public static Node paramList(List<Node> params) { Node paramList = paramList(); for (Node param : params) { Preconditions.checkState(param.isName() || param.isRest()); paramList.addChildToBack(param); } return paramList; }
Node createZeroArgFunction(String name, Node body, @Nullable JSType returnType) { FunctionType functionType = isAddingTypes() ? registry.createFunctionType(returnType) : null; return createFunction(name, IR.paramList(), body, functionType); }
public static Node emptyFunction() { return IR.function(IR.name(""), IR.paramList(), IR.block()); }
/** * Infer the parameter types from the doc info alone. */ FunctionTypeBuilder inferParameterTypes(JSDocInfo info) { // Create a fake args parent. Node lp = IR.paramList(); for (String name : info.getParameterNames()) { lp.addChildToBack(IR.name(name)); } return inferParameterTypes(lp, info); }
/** * Infer the parameter types from the doc info alone. */ FunctionTypeBuilder inferParameterTypes(JSDocInfo info) { // Create a fake args parent. Node lp = IR.paramList(); for (String name : info.getParameterNames()) { lp.addChildToBack(IR.name(name)); } return inferParameterTypes(lp, info); }
Node createZeroArgArrowFunctionForExpression(Node expression) { Node result = IR.arrowFunction(IR.name(""), IR.paramList(), expression); if (isAddingTypes()) { // It feels like we should be adding type-of-this here, but it should remain unknown, // because you're allowed to supply any kind of value of `this` when calling an arrow // function. It will just be ignored in favor of the `this` in the scope where the // arrow was defined. FunctionType functionType = new FunctionBuilder(registry) .withReturnType(expression.getJSTypeRequired()) .withParamsNode(IR.paramList()) .build(); result.setJSType(functionType); } return result; }
public Node buildBranchRecordingFunction(String uri, int id, int lineNo, int conditionNo) { Node params = IR.paramList(IR.name("result")); Node name = IR.name(format("visit%d_%d_%d", id, lineNo, conditionNo)); Node lineAndConditionCall = buildLineAndConditionCall(uri, lineNo, conditionNo); Node body = IR.block(lineAndConditionCall); body.addChildToBack(IR.returnNode(IR.name("result"))); return IR.function(name, params, body); } }
public Node buildBranchRecordingFunction(String uri, int id, int lineNo, int conditionNo) { Node params = IR.paramList(IR.name("result")); Node name = IR.name(format("visit%d_%d_%d", id, lineNo, conditionNo)); Node lineAndConditionCall = buildLineAndConditionCall(uri, lineNo, conditionNo); Node body = IR.block(lineAndConditionCall); body.addChildToBack(IR.returnNode(IR.name("result"))); return IR.function(name, params, body); } }
/** * Adds the generated setter for a readonly property. * @see https://www.polymer-project.org/0.8/docs/devguide/properties.html#read-only */ private Node makeReadOnlySetter(String propName, String qualifiedPath) { String setterName = "_set" + propName.substring(0, 1).toUpperCase() + propName.substring(1); Node fnNode = IR.function(IR.name(""), IR.paramList(IR.name(propName)), IR.block()); Node exprResNode = IR.exprResult( IR.assign(NodeUtil.newQName(compiler, qualifiedPath + setterName), fnNode)); JSDocInfoBuilder info = new JSDocInfoBuilder(true); // This is overriding a generated function which was added to the interface in // {@code addInterfaceExterns}. info.recordOverride(); exprResNode.getFirstChild().setJSDocInfo(info.build()); return exprResNode; }
/** * Adds the generated setter for a readonly property. * * @see https://www.polymer-project.org/0.8/docs/devguide/properties.html#read-only */ private Node makeReadOnlySetter(String propName, String qualifiedPath) { String setterName = "_set" + propName.substring(0, 1).toUpperCase() + propName.substring(1); Node fnNode = IR.function(IR.name(""), IR.paramList(IR.name(propName)), IR.block()); compiler.reportChangeToChangeScope(fnNode); Node exprResNode = IR.exprResult(IR.assign(NodeUtil.newQName(compiler, qualifiedPath + setterName), fnNode)); JSDocInfoBuilder info = new JSDocInfoBuilder(true); // This is overriding a generated function which was added to the interface in // {@code createExportsAndExterns}. info.recordOverride(); exprResNode.getFirstChild().setJSDocInfo(info.build()); return exprResNode; }
Node processComputedPropertyGetter(ComputedPropertyGetterTree tree) { maybeWarnForFeature(tree, Feature.COMPUTED_PROPERTIES); Node key = transform(tree.property); Node body = transform(tree.body); Node function = IR.function(IR.name(""), IR.paramList(), body); function.useSourceInfoIfMissingFromForTree(body); Node n = newNode(Token.COMPUTED_PROP, key, function); n.putBooleanProp(Node.COMPUTED_PROP_GETTER, true); n.putBooleanProp(Node.STATIC_MEMBER, tree.isStatic); return n; }
Node processComputedPropertyGetter(ComputedPropertyGetterTree tree) { maybeWarnEs6Feature(tree, Feature.COMPUTED_PROPERTIES); Node key = transform(tree.property); Node body = transform(tree.body); Node function = IR.function(IR.name(""), IR.paramList(), body); function.useSourceInfoIfMissingFromForTree(body); Node n = newNode(Token.COMPUTED_PROP, key, function); n.putBooleanProp(Node.COMPUTED_PROP_GETTER, true); n.putBooleanProp(Node.STATIC_MEMBER, tree.isStatic); return n; }
/** * Adds a computed property method, with the name of the marker, to the class. * * <pre>{@code * class C { * ['instance_of__C']() {} * } * }</pre> */ private Node addMarkerToClass(String markerName, @Nullable String unused, Node classMembers) { Node function = IR.function(IR.name(""), IR.paramList(), IR.block()); Node member = IR.computedProp(IR.string(markerName), function); member.putBooleanProp(Node.COMPUTED_PROP_METHOD, true); classMembers.addChildToBack(member); compiler.reportChangeToEnclosingScope(member); compiler.reportChangeToChangeScope(function); NodeUtil.addFeatureToScript(traversal.getCurrentScript(), Feature.COMPUTED_PROPERTIES); return classMembers; }
Node processComputedPropertySetter(ComputedPropertySetterTree tree) { maybeWarnEs6Feature(tree, Feature.COMPUTED_PROPERTIES); Node key = transform(tree.property); Node body = transform(tree.body); Node paramList = IR.paramList(safeProcessName(tree.parameter)); Node function = IR.function(IR.name(""), paramList, body); function.useSourceInfoIfMissingFromForTree(body); Node n = newNode(Token.COMPUTED_PROP, key, function); n.putBooleanProp(Node.COMPUTED_PROP_SETTER, true); n.putBooleanProp(Node.STATIC_MEMBER, tree.isStatic); return n; }
Node processGetAccessor(GetAccessorTree tree) { Node key = processObjectLitKeyAsString(tree.propertyName); key.setType(Token.GETTER_DEF); Node body = transform(tree.body); Node dummyName = IR.name(""); setSourceInfo(dummyName, tree.body); Node paramList = IR.paramList(); setSourceInfo(paramList, tree.body); Node value = newNode(Token.FUNCTION, dummyName, paramList, body); setSourceInfo(value, tree.body); key.addChildToFront(value); maybeProcessType(value, tree.returnType); key.setStaticMember(tree.isStatic); return key; }
/** Adds an ES5 getter to the given object literal to use an an export. */ private void addExport(Node definePropertiesLit, String exportedName, LocalQName localQName) { Node exportedValue = NodeUtil.newQName(compiler, localQName.qName); Node getterFunction = IR.function(IR.name(""), IR.paramList(), IR.block(IR.returnNode(exportedValue))); getterFunction.useSourceInfoFromForTree(localQName.nodeForSourceInfo); Node objLit = IR.objectlit( IR.stringKey("enumerable", IR.trueNode()), IR.stringKey("get", getterFunction)); definePropertiesLit.addChildToBack(IR.stringKey(exportedName, objLit)); compiler.reportChangeToChangeScope(getterFunction); }
Node processSetAccessor(SetAccessorTree tree) { Node key = processObjectLitKeyAsString(tree.propertyName); key.setType(Token.SETTER_DEF); Node body = transform(tree.body); Node dummyName = IR.name(""); setSourceInfo(dummyName, tree.propertyName); Node paramList = IR.paramList( safeProcessName(tree.parameter)); setSourceInfo(paramList, tree.parameter); maybeProcessType(paramList.getFirstChild(), tree.type); Node value = newNode(Token.FUNCTION, dummyName, paramList, body); setSourceInfo(value, tree.body); key.addChildToFront(value); key.setStaticMember(tree.isStatic); return key; }
private void addGetterExport( Node script, Node forSourceInfo, Node objLit, String exportedName, String localName) { // Type checker doesn't infer getters so mark the return as unknown. // { /** @return {?} */ get foo() { return foo; } } Node getter = Node.newString(Token.GETTER_DEF, exportedName); getter.putBooleanProp(Node.MODULE_EXPORT, true); objLit.addChildToBack(getter); Node name = NodeUtil.newQName(compiler, localName); Node function = IR.function(IR.name(""), IR.paramList(), IR.block(IR.returnNode(name))); getter.addChildToFront(function); JSDocInfoBuilder builder = new JSDocInfoBuilder(true); builder.recordReturnType( new JSTypeExpression(new Node(Token.QMARK), script.getSourceFileName())); getter.setJSDocInfo(builder.build()); getter.useSourceInfoIfMissingFromForTree(forSourceInfo); compiler.reportChangeToEnclosingScope(getter.getFirstChild().getLastChild()); compiler.reportChangeToEnclosingScope(getter); }