MCPcopy Create free account
hub / github.com/OpenEndedGroup/Field2 / inferClass

Function inferClass

lib/web/tern/infer.js:1277–1325  ·  view source on GitHub ↗
(node, scope, name)

Source from the content-addressed store, hash-verified

1275 }
1276
1277 function inferClass(node, scope, name) {
1278 if (!name && node.id) name = node.id.name
1279
1280 var sup = cx.protos.Object, supCtor, delayed
1281 if (node.superClass) {
1282 if (node.superClass.type == "Literal" && node.superClass.value == null) {
1283 sup = null
1284 } else {
1285 var supVal = infer(node.superClass, scope), supProto
1286 supCtor = supVal.getFunctionType()
1287 if (supCtor && (supProto = supCtor.getProp("prototype").getObjType())) {
1288 sup = supProto
1289 } else {
1290 supCtor = supVal
1291 delayed = supVal.getProp("prototype")
1292 }
1293 }
1294 }
1295 var proto = new Obj(sup, name && name + ".prototype")
1296 if (delayed) delayed.propagate(new HasProto(proto))
1297
1298 return withSuper(supCtor, delayed || sup, function() {
1299 var ctor, body = node.body.body
1300 for (var i = 0; i < body.length; i++)
1301 if (body[i].kind == "constructor") ctor = body[i].value
1302 var fn = node.objType = ctor ? infer(ctor, scope) : new Fn(name, ANull, [], null, ANull)
1303 fn.originNode = node.id || ctor || node
1304
1305 var inst = getInstance(proto, fn)
1306 fn.self.addType(inst)
1307 fn.defProp("prototype", node).addType(proto)
1308 for (var i = 0; i < body.length; i++) {
1309 var method = body[i], target
1310 if (method.kind == "constructor") continue
1311 var pName = propName(method, scope)
1312 if (pName == "<i>" || method.kind == "set") {
1313 target = ANull
1314 } else {
1315 target = (method.static ? fn : proto).defProp(pName, method.key)
1316 target.initializer = true
1317 if (method.kind == "get") target = new IsCallee(inst, [], null, target)
1318 }
1319 infer(method.value, scope, target)
1320 var methodFn = target.getFunctionType()
1321 if (methodFn) methodFn.self.addType(inst)
1322 }
1323 return fn
1324 })
1325 }
1326
1327 function arrayLiteralType(elements, scope, inner) {
1328 var tuple = elements.length > 1 && elements.length < 6

Callers 1

infer.jsFile · 0.85

Calls 3

inferFunction · 0.85
withSuperFunction · 0.85
propagateMethod · 0.80

Tested by

no test coverage detected