MCPcopy Index your code
hub / github.com/ternjs/tern / applyType

Function applyType

plugin/doc_comment.js:490–524  ·  view source on GitHub ↗
(type, self, args, ret, node, aval)

Source from the content-addressed store, hash-verified

488 function isFunExpr(node) { return node.type == "FunctionExpression" || node.type == "ArrowFunctionExpression" }
489
490 function applyType(type, self, args, ret, node, aval) {
491 var fn;
492 if (node.type == "VariableDeclaration") {
493 var decl = node.declarations[0];
494 if (decl.init && isFunExpr(decl.init)) fn = decl.init.scope.fnType;
495 } else if (node.type == "FunctionDeclaration") {
496 fn = node.scope.fnType;
497 } else if (node.type == "AssignmentExpression") {
498 if (isFunExpr(node.right))
499 fn = node.right.scope.fnType;
500 } else if (node.type == "CallExpression" || node.type === "ClassDeclaration") {
501 } else { // An object property
502 if (isFunExpr(node.value)) fn = node.value.scope.fnType;
503 }
504
505 if (fn && (args || ret || self)) {
506 if (args) for (var i = 0; i < fn.argNames.length; ++i) {
507 var name = fn.argNames[i], known = args[name];
508 if (!known && (known = args[name + "?"]))
509 fn.argNames[i] += "?";
510 if (known) propagateWithWeight(known, fn.args[i]);
511 }
512 if (ret) {
513 if (fn.retval == infer.ANull) fn.retval = new infer.AVal;
514 propagateWithWeight(ret, fn.retval);
515 }
516 if (self === true) {
517 var proto = fn.getProp("prototype").getObjType();
518 self = proto && {type: infer.getInstance(proto, fn)};
519 }
520 if (self) propagateWithWeight(self, fn.self);
521 } else if (type) {
522 propagateWithWeight(type, aval);
523 }
524 }
525});

Callers 1

jsdocInterpretCommentsFunction · 0.85

Calls 2

isFunExprFunction · 0.85
propagateWithWeightFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…