MCPcopy
hub / github.com/ternjs/tern / inferClass

Function inferClass

lib/infer.js:1301–1349  ·  view source on GitHub ↗
(node, scope, name)

Source from the content-addressed store, hash-verified

1299 }
1300
1301 function inferClass(node, scope, name) {
1302 if (!name && node.id) name = node.id.name;
1303
1304 var sup = cx.protos.Object, supCtor, delayed;
1305 if (node.superClass) {
1306 if (node.superClass.type == "Literal" && node.superClass.value == null) {
1307 sup = null;
1308 } else {
1309 var supVal = infer(node.superClass, scope), supProto;
1310 supCtor = supVal.getFunctionType();
1311 if (supCtor && (supProto = supCtor.getProp("prototype").getObjType())) {
1312 sup = supProto;
1313 } else {
1314 supCtor = supVal;
1315 delayed = supVal.getProp("prototype");
1316 }
1317 }
1318 }
1319 var proto = new Obj(sup, name && name + ".prototype");
1320 if (delayed) delayed.propagate(new HasProto(proto));
1321
1322 return withSuper(supCtor, delayed || sup, function() {
1323 var ctor, body = node.body.body;
1324 for (var i = 0; i < body.length; i++)
1325 if (body[i].kind == "constructor") ctor = body[i].value;
1326 var fn = node.objType = ctor ? infer(ctor, scope) : new Fn(name, ANull, [], null, ANull);
1327 fn.originNode = node.id || ctor || node;
1328
1329 var inst = getInstance(proto, fn);
1330 fn.self.addType(inst);
1331 fn.defProp("prototype", node).addType(proto);
1332 for (var i = 0; i < body.length; i++) {
1333 var method = body[i], target;
1334 if (method.kind == "constructor") continue;
1335 var pName = propName(method, scope);
1336 if (pName == "<i>" || method.kind == "set") {
1337 target = ANull;
1338 } else {
1339 target = (method.static ? fn : proto).defProp(pName, method.key);
1340 target.initializer = true;
1341 if (method.kind == "get") target = new IsCallee(inst, [], null, target);
1342 }
1343 infer(method.value, scope, target);
1344 var methodFn = target.getFunctionType();
1345 if (methodFn) methodFn.self.addType(inst);
1346 }
1347 return fn;
1348 });
1349 }
1350
1351 function arrayLiteralType(elements, scope, inner) {
1352 var tuple = elements.length > 1 && elements.length < 6;

Callers 1

infer.jsFile · 0.85

Calls 2

inferFunction · 0.85
withSuperFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…