MCPcopy Index your code
hub / github.com/jsdoc/jsdoc / astnodeToMemberof

Method astnodeToMemberof

lib/jsdoc/src/parser.js:358–447  ·  view source on GitHub ↗

* Given a node, determine what the node is a member of. * @param {node} node * @returns {string} The long name of the node that this is a member of.

(node)

Source from the content-addressed store, hash-verified

356 * @returns {string} The long name of the node that this is a member of.
357 */
358 astnodeToMemberof(node) {
359 let basename;
360 let doclet;
361 let scope;
362
363 const result = {};
364 const type = node.type;
365
366 if ( (type === Syntax.FunctionDeclaration || type === Syntax.FunctionExpression ||
367 type === Syntax.ArrowFunctionExpression || type === Syntax.VariableDeclarator) &&
368 node.enclosingScope ) {
369 doclet = this._getDocletById(node.enclosingScope.nodeId);
370
371 if (!doclet) {
372 result.memberof = jsdoc.name.LONGNAMES.ANONYMOUS + jsdoc.name.SCOPE.PUNC.INNER;
373 }
374 else {
375 result.memberof = doclet.longname + jsdoc.name.SCOPE.PUNC.INNER;
376 }
377 }
378 else if (type === Syntax.ClassPrivateProperty || type === Syntax.ClassProperty) {
379 doclet = this._getDocletById(node.enclosingScope.nodeId);
380
381 if (!doclet) {
382 result.memberof = jsdoc.name.LONGNAMES.ANONYMOUS + jsdoc.name.SCOPE.PUNC.INSTANCE;
383 }
384 else {
385 result.memberof = doclet.longname + jsdoc.name.SCOPE.PUNC.INSTANCE;
386 }
387 }
388 else if (type === Syntax.MethodDefinition && node.kind === 'constructor') {
389 doclet = this._getDocletById(node.enclosingScope.nodeId);
390
391 // global classes aren't a member of anything
392 if (doclet.memberof) {
393 result.memberof = doclet.memberof + jsdoc.name.SCOPE.PUNC.INNER;
394 }
395 }
396 // special case for methods in classes that are returned by arrow function expressions; for
397 // other method definitions, we get the memberof from the node name elsewhere. yes, this is
398 // confusing...
399 else if (type === Syntax.MethodDefinition && node.parent.parent.parent &&
400 node.parent.parent.parent.type === Syntax.ArrowFunctionExpression) {
401 doclet = this._getDocletById(node.enclosingScope.nodeId);
402
403 if (doclet) {
404 result.memberof = doclet.longname +
405 (node.static === true ?
406 jsdoc.name.SCOPE.PUNC.STATIC :
407 jsdoc.name.SCOPE.PUNC.INSTANCE);
408 }
409 }
410 else {
411 // check local references for aliases
412 scope = node;
413 basename = jsdoc.name.getBasename( jsdoc.src.astnode.nodeToValue(node) );
414
415 // walk up the scope chain until we find the scope in which the node is defined

Callers 1

addSymbolMemberofFunction · 0.80

Calls 3

_getDocletByIdMethod · 0.95
_getDocletByLongnameMethod · 0.95
definedInScopeFunction · 0.85

Tested by

no test coverage detected