11'use strict' ;
22
33var types = require ( 'ast-types' ) ,
4+ pathParse = require ( 'parse-filepath' ) ,
45 isJSDocComment = require ( '../../lib/is_jsdoc_comment' ) ,
56 parse = require ( '../../lib/parse' ) ;
67
@@ -56,22 +57,15 @@ function extractIdentifiers(path) {
5657}
5758
5859/**
59- * Set `memberof` and `instance`/`static` tags on `comment` based on the
60- * array of `identifiers`. If the last element of the `identifiers` is
61- * `"prototype"`, it is assumed to be an instance member; otherwise static.
62- *
63- * @param {Object } comment comment for which to infer memberships
60+ * Test whether some identifiers refer to a module export (`exports` or `module.exports`).
6461 * @param {Array<string> } identifiers array of identifier names
65- * @returns {undefined } mutates `comment`
66- * @private
62+ * @returns {boolean } true if identifiers refer to a module export
6763 */
68- function inferMembershipFromIdentifiers ( comment , identifiers ) {
69- if ( identifiers [ identifiers . length - 1 ] === 'prototype' ) {
70- comment . memberof = identifiers . slice ( 0 , - 1 ) . join ( '.' ) ;
71- comment . scope = 'instance' ;
72- } else {
73- comment . memberof = identifiers . join ( '.' ) ;
74- comment . scope = 'static' ;
64+ function isModuleExport ( identifiers ) {
65+ switch ( identifiers . length ) {
66+ case 1 : return identifiers [ 0 ] === 'exports' ;
67+ case 2 : return identifiers [ 0 ] === 'module' && identifiers [ 1 ] === 'exports' ;
68+ default : return false ;
7569 }
7670}
7771
@@ -84,7 +78,41 @@ function inferMembershipFromIdentifiers(comment, identifiers) {
8478 * @returns {Object } comment with membership inferred
8579 */
8680module . exports = function ( ) {
81+ var currentModule ;
82+
83+ function inferModuleName ( comment ) {
84+ return ( comment . module && comment . module . name ) ||
85+ pathParse ( comment . context . file ) . name ;
86+ }
87+
88+ /**
89+ * Set `memberof` and `instance`/`static` tags on `comment` based on the
90+ * array of `identifiers`. If the last element of the `identifiers` is
91+ * `"prototype"`, it is assumed to be an instance member; otherwise static.
92+ *
93+ * @param {Object } comment comment for which to infer memberships
94+ * @param {Array<string> } identifiers array of identifier names
95+ * @returns {undefined } mutates `comment`
96+ * @private
97+ */
98+ function inferMembershipFromIdentifiers ( comment , identifiers ) {
99+ if ( isModuleExport ( identifiers ) ) {
100+ comment . memberof = inferModuleName ( currentModule || comment ) ;
101+ comment . scope = 'static' ;
102+ } else if ( identifiers [ identifiers . length - 1 ] === 'prototype' ) {
103+ comment . memberof = identifiers . slice ( 0 , - 1 ) . join ( '.' ) ;
104+ comment . scope = 'instance' ;
105+ } else {
106+ comment . memberof = identifiers . join ( '.' ) ;
107+ comment . scope = 'static' ;
108+ }
109+ }
110+
87111 return function inferMembership ( comment ) {
112+ if ( comment . module ) {
113+ currentModule = comment ;
114+ }
115+
88116 if ( comment . memberof ) {
89117 return comment ;
90118 }
0 commit comments