MCPcopy Create free account
hub / github.com/TruthHun/BookStack / parseFnType

Function parseFnType

static/editor.md/lib/codemirror/addon/tern/tern.js:337–366  ·  view source on GitHub ↗
(text)

Source from the content-addressed store, hash-verified

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

Callers 1

updateArgHintsFunction · 0.85

Calls 1

skipMatchingFunction · 0.85

Tested by

no test coverage detected