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

Function parseFnType

lib/web/CodeMirror/addon/tern/tern.js:344–373  ·  view source on GitHub ↗
(text)

Source from the content-addressed store, hash-verified

342 }
343
344 function parseFnType(text) {
345 var args = [], pos = 3;
346
347 function skipMatching(upto) {
348 var depth = 0, start = pos;
349 for (;;) {
350 var next = text.charAt(pos);
351 if (upto.test(next) && !depth) return text.slice(start, pos);
352 if (/[{\[\(]/.test(next)) ++depth;
353 else if (/[}\]\)]/.test(next)) --depth;
354 ++pos;
355 }
356 }
357
358 // Parse arguments
359 if (text.charAt(pos) != ")") for (;;) {
360 var name = text.slice(pos).match(/^([^, \(\[\{]+): /);
361 if (name) {
362 pos += name[0].length;
363 name = name[1];
364 }
365 args.push({name: name, type: skipMatching(/[\),]/)});
366 if (text.charAt(pos) == ")") break;
367 pos += 2;
368 }
369
370 var rettype = text.slice(pos).match(/^\) -> (.*)$/);
371
372 return {args: args, rettype: rettype && rettype[1]};
373 }
374
375 // Moving to the definition of something
376

Callers 1

updateArgHintsFunction · 0.85

Calls 3

skipMatchingFunction · 0.85
matchMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected