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

Function similarType

lib/infer.js:229–258  ·  view source on GitHub ↗
(a, b, depth)

Source from the content-addressed store, hash-verified

227 }
228
229 function similarType(a, b, depth) {
230 if (!a || depth >= 5) return b;
231 if (!a || a == b) return a;
232 if (!b) return a;
233 if (a.constructor != b.constructor) return false;
234 if (a.constructor == Arr) {
235 var innerA = a.getProp("<i>").getType(false);
236 if (!innerA) return b;
237 var innerB = b.getProp("<i>").getType(false);
238 if (!innerB || similarType(innerA, innerB, depth + 1)) return b;
239 } else if (a.constructor == Obj) {
240 var propsA = 0, propsB = 0, same = 0;
241 for (var prop in a.props) {
242 propsA++;
243 if (prop in b.props && similarAVal(a.props[prop], b.props[prop], depth + 1))
244 same++;
245 }
246 for (var prop in b.props) propsB++;
247 if (propsA && propsB && same < Math.max(propsA, propsB) / 2) return false;
248 return propsA > propsB ? a : b;
249 } else if (a.constructor == Fn) {
250 if (a.args.length != b.args.length ||
251 !a.args.every(function(tp, i) { return similarAVal(tp, b.args[i], depth + 1); }) ||
252 !similarAVal(a.retval, b.retval, depth + 1) || !similarAVal(a.self, b.self, depth + 1))
253 return false;
254 return a;
255 } else {
256 return false;
257 }
258 }
259
260 var simplifyTypes = exports.simplifyTypes = function(types) {
261 var found = [];

Callers 2

similarAValFunction · 0.85
infer.jsFile · 0.85

Calls 1

similarAValFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…