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

Function jsdocInterpretComments

plugin/doc_comment.js:389–461  ·  view source on GitHub ↗
(node, scope, aval, comments)

Source from the content-addressed store, hash-verified

387 }
388
389 function jsdocInterpretComments(node, scope, aval, comments) {
390 var type, args, ret, foundOne, self, parsed;
391
392 for (var i = 0; i < comments.length; ++i) {
393 var comment = comments[i];
394 var decl = /(?:\n|\*)\s*@(type|param|arg(?:ument)?|returns?|this|class|constructor)(?:\s*?\n|\s+(.*))/g, m;
395 while (m = decl.exec(comment)) {
396 if (m[1] == "class" || m[1] == "constructor") {
397 self = foundOne = true;
398 continue;
399 }
400
401 if (m[2] === undefined) continue; // to avoid tags that require a type argument.
402
403 if (m[1] == "this" && (parsed = parseType(scope, m[2], 0))) {
404 self = parsed;
405 foundOne = true;
406 continue;
407 }
408
409 if (!(parsed = parseTypeOuter(scope, m[2]))) continue;
410 foundOne = true;
411
412 switch(m[1]) {
413 case "returns": case "return":
414 ret = parsed; break;
415 case "type":
416 type = parsed; break;
417 case "param": case "arg": case "argument":
418 // Possible jsdoc param name situations:
419 // employee
420 // [employee]
421 // [employee=John Doe]
422 // employee.name
423 // employees[].name
424 var name = m[2].slice(parsed.end).match(/^\s*(\[?)\s*([^\[\]\s=]+(\[\][^\[\]\s=]+)?)\s*(?:=[^\]]+\s*)?(\]?).*/);
425 if (!name) continue;
426 var argname = name[2] + (parsed.isOptional || (name[1] === '[' && name[4] === ']') ? "?" : "");
427
428 // Check to see if the jsdoc is indicating a property of a previously documented parameter
429 var isObjProp = false;
430 var parts = argname.split('.');
431 if (args && parts.length == 2) {
432 var objname = parts[0];
433 argname = parts[1];
434
435 // Go through each of the previously found parameter to find the
436 // object or array for which this new parameter should be a part
437 // of
438 var key, value;
439 for (key in args) {
440 value = args[key];
441
442 if (key === objname && value.type instanceof infer.Obj) {
443 isObjProp = true;
444 parsed.type.propagate(value.type.defProp(argname));
445 }
446 else if (key + '[]' === objname && value.type instanceof infer.Arr) {

Callers 1

interpretCommentsFunction · 0.85

Calls 3

parseTypeOuterFunction · 0.85
applyTypeFunction · 0.85
parseTypeFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…