diff --git a/lib/infer/membership.js b/lib/infer/membership.js index 17410aee3..831436953 100644 --- a/lib/infer/membership.js +++ b/lib/infer/membership.js @@ -63,13 +63,11 @@ function extractIdentifiers(path) { * @returns {number} number of identifiers referring to a module export (0, 1 or 2) */ function countModuleIdentifiers(comment, identifiers) { - if (identifiers.length >= 1 && - (identifiers[0] === 'exports' || (identifiers[0] === 'module' && comment.name === 'exports'))) { + if (identifiers.length >= 1 && identifiers[0] === 'exports') { return 1; } - if (identifiers.length >= 2 && - (identifiers[0] === 'module' && identifiers[1] === 'exports')) { + if (identifiers.length >= 2 && identifiers[0] === 'module' && identifiers[1] === 'exports') { return 2; } @@ -105,6 +103,11 @@ module.exports = function () { * @private */ function inferMembershipFromIdentifiers(comment, identifiers) { + if (identifiers.length === 1 && identifiers[0] === 'module' && comment.name === 'exports') { + comment.name = inferModuleName(currentModule || comment); + return; + } + /* * Test whether identifiers start with a module export (`exports` or `module.exports`), * and if so replace those identifiers with the name of the current module. diff --git a/test/fixture/_external-deps-included.json b/test/fixture/_external-deps-included.json index e8258f586..c92e35b2f 100644 --- a/test/fixture/_external-deps-included.json +++ b/test/fixture/_external-deps-included.json @@ -1,4 +1,42 @@ [ + { + "description": "I am in `external.input.js`.", + "tags": [], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 7, + "column": 3 + } + }, + "context": { + "loc": { + "start": { + "line": 8, + "column": 0 + }, + "end": { + "line": 11, + "column": 1 + } + }, + "code": "require('external');\nrequire('external2');\nrequire('module-not-found');\n\n/**\n * I am in `external.input.js`.\n */\nfunction foo() {\n 'use strict';\n return 'bar';\n}\n\nmodule.exports = foo;\n" + }, + "errors": [], + "name": "foo", + "kind": "function", + "members": { + "instance": [], + "static": [] + }, + "events": [], + "path": [ + "foo" + ] + }, { "description": "This function returns the number one.", "tags": [ @@ -35,12 +73,7 @@ }, "code": "/**\n * This function returns the number one.\n * @return {Number} numberone\n */\nmodule.exports = function () {\n // this returns 1\n return 1;\n};\n" }, - "errors": [ - { - "message": "memberof reference to index not found", - "commentLineNumber": 0 - } - ], + "errors": [], "returns": [ { "title": "returns", @@ -52,17 +85,15 @@ } } ], - "name": "exports", + "name": "index", "kind": "function", - "memberof": "index", - "scope": "static", "members": { "instance": [], "static": [] }, "events": [], "path": [ - "exports" + "index" ] }, { @@ -101,12 +132,7 @@ }, "code": "'use strict';\n\nvar otherDep = require('external2');\n\n/**\n * This function returns the number one.\n * @return {Number} numberone\n */\nmodule.exports = function () {\n // this returns 1\n return otherDep() - 1;\n};\n" }, - "errors": [ - { - "message": "memberof reference to main not found", - "commentLineNumber": 0 - } - ], + "errors": [], "returns": [ { "title": "returns", @@ -118,47 +144,7 @@ } } ], - "name": "exports", - "kind": "function", - "memberof": "main", - "scope": "static", - "members": { - "instance": [], - "static": [] - }, - "events": [], - "path": [ - "exports" - ] - }, - { - "description": "I am in `external.input.js`.", - "tags": [], - "loc": { - "start": { - "line": 5, - "column": 0 - }, - "end": { - "line": 7, - "column": 3 - } - }, - "context": { - "loc": { - "start": { - "line": 8, - "column": 0 - }, - "end": { - "line": 11, - "column": 1 - } - }, - "code": "require('external');\nrequire('external2');\nrequire('module-not-found');\n\n/**\n * I am in `external.input.js`.\n */\nfunction foo() {\n 'use strict';\n return 'bar';\n}\n\nmodule.exports = foo;\n" - }, - "errors": [], - "name": "foo", + "name": "main", "kind": "function", "members": { "instance": [], @@ -166,7 +152,7 @@ }, "events": [], "path": [ - "foo" + "main" ] } ] \ No newline at end of file diff --git a/test/fixture/_multi-file-input.json b/test/fixture/_multi-file-input.json index 5addee68e..5abd6d339 100644 --- a/test/fixture/_multi-file-input.json +++ b/test/fixture/_multi-file-input.json @@ -1,15 +1,30 @@ [ { - "description": "This function returns the number one.", + "description": "This function returns the number plus two.", "tags": [ + { + "title": "param", + "description": "the number", + "lineNumber": 3, + "type": { + "type": "NameExpression", + "name": "Number" + }, + "name": "a" + }, { "title": "returns", - "description": "numberone", - "lineNumber": 2, + "description": "numbertwo", + "lineNumber": 4, "type": { "type": "NameExpression", "name": "Number" } + }, + { + "title": "example", + "description": "var result = returnTwo(4);\n// result is 6", + "lineNumber": 5 } ], "loc": { @@ -18,79 +33,77 @@ "column": 0 }, "end": { - "line": 4, + "line": 9, "column": 3 } }, "context": { "loc": { "start": { - "line": 5, + "line": 10, "column": 0 }, "end": { - "line": 8, - "column": 2 + "line": 13, + "column": 1 } }, - "code": "/**\n * This function returns the number one.\n * @returns {Number} numberone\n */\nmodule.exports = function () {\n // this returns 1\n return 1;\n};\n" + "code": "/**\n * This function returns the number plus two.\n *\n * @param {Number} a the number\n * @returns {Number} numbertwo\n * @example\n * var result = returnTwo(4);\n * // result is 6\n */\nfunction returnTwo(a) {\n // this returns a + 2\n return a + 2;\n}\n" }, "errors": [ { - "message": "memberof reference to simple.input not found", - "commentLineNumber": 0 + "message": "type Number found, number is standard", + "commentLineNumber": 3 + } + ], + "params": [ + { + "title": "param", + "description": "the number", + "lineNumber": 3, + "type": { + "type": "NameExpression", + "name": "Number" + }, + "name": "a" } ], "returns": [ { "title": "returns", - "description": "numberone", - "lineNumber": 2, + "description": "numbertwo", + "lineNumber": 4, "type": { "type": "NameExpression", "name": "Number" } } ], - "name": "exports", + "examples": [ + "var result = returnTwo(4);\n// result is 6" + ], + "name": "returnTwo", "kind": "function", - "memberof": "simple.input", - "scope": "static", "members": { "instance": [], "static": [] }, "events": [], "path": [ - "exports" + "returnTwo" ] }, { - "description": "This function returns the number plus two.", + "description": "This function returns the number one.", "tags": [ - { - "title": "param", - "description": "the number", - "lineNumber": 3, - "type": { - "type": "NameExpression", - "name": "Number" - }, - "name": "a" - }, { "title": "returns", - "description": "numbertwo", - "lineNumber": 4, + "description": "numberone", + "lineNumber": 2, "type": { "type": "NameExpression", "name": "Number" } - }, - { - "title": "example", - "description": "var result = returnTwo(4);\n// result is 6", - "lineNumber": 5 } ], "loc": { @@ -99,56 +112,36 @@ "column": 0 }, "end": { - "line": 9, + "line": 4, "column": 3 } }, "context": { "loc": { "start": { - "line": 10, + "line": 5, "column": 0 }, "end": { - "line": 13, - "column": 1 + "line": 8, + "column": 2 } }, - "code": "/**\n * This function returns the number plus two.\n *\n * @param {Number} a the number\n * @returns {Number} numbertwo\n * @example\n * var result = returnTwo(4);\n * // result is 6\n */\nfunction returnTwo(a) {\n // this returns a + 2\n return a + 2;\n}\n" + "code": "/**\n * This function returns the number one.\n * @returns {Number} numberone\n */\nmodule.exports = function () {\n // this returns 1\n return 1;\n};\n" }, - "errors": [ - { - "message": "type Number found, number is standard", - "commentLineNumber": 3 - } - ], - "params": [ - { - "title": "param", - "description": "the number", - "lineNumber": 3, - "type": { - "type": "NameExpression", - "name": "Number" - }, - "name": "a" - } - ], + "errors": [], "returns": [ { "title": "returns", - "description": "numbertwo", - "lineNumber": 4, + "description": "numberone", + "lineNumber": 2, "type": { "type": "NameExpression", "name": "Number" } } ], - "examples": [ - "var result = returnTwo(4);\n// result is 6" - ], - "name": "returnTwo", + "name": "simple.input", "kind": "function", "members": { "instance": [], @@ -156,7 +149,7 @@ }, "events": [], "path": [ - "returnTwo" + "simple.input" ] } ] \ No newline at end of file diff --git a/test/fixture/inline-link.output.custom.md b/test/fixture/inline-link.output.custom.md index e3424bd54..0e638ead9 100644 --- a/test/fixture/inline-link.output.custom.md +++ b/test/fixture/inline-link.output.custom.md @@ -14,7 +14,7 @@ Returns **number** the output -# exports +# inline-link.input This function returns the number one. Internally, this uses `addOne` to do the math. diff --git a/test/fixture/inline-link.output.json b/test/fixture/inline-link.output.json index 393670576..0959132d9 100644 --- a/test/fixture/inline-link.output.json +++ b/test/fixture/inline-link.output.json @@ -126,12 +126,7 @@ }, "code": "/**\n * Adds one to a number\n * @param {number} a the input\n * @returns {number} the output\n */\nfunction addOne(a) {\n return a + 1;\n}\n\n/**\n * This function returns the number one. Internally, this uses\n * {@link addOne} to do the math.\n * @param {number} a the input\n * @returns {number} numberone\n */\nmodule.exports = function (a) {\n return addOne(a);\n};\n" }, - "errors": [ - { - "message": "memberof reference to inline-link.input not found", - "commentLineNumber": 0 - } - ], + "errors": [], "params": [ { "title": "param", @@ -155,17 +150,15 @@ } } ], - "name": "exports", + "name": "inline-link.input", "kind": "function", - "memberof": "inline-link.input", - "scope": "static", "members": { "instance": [], "static": [] }, "events": [], "path": [ - "exports" + "inline-link.input" ] } ] \ No newline at end of file diff --git a/test/fixture/inline-link.output.md b/test/fixture/inline-link.output.md index e3424bd54..0e638ead9 100644 --- a/test/fixture/inline-link.output.md +++ b/test/fixture/inline-link.output.md @@ -14,7 +14,7 @@ Returns **number** the output -# exports +# inline-link.input This function returns the number one. Internally, this uses `addOne` to do the math. diff --git a/test/fixture/inline-link.output.md.json b/test/fixture/inline-link.output.md.json index a2b509e9e..d7ebbb9e8 100644 --- a/test/fixture/inline-link.output.md.json +++ b/test/fixture/inline-link.output.md.json @@ -241,7 +241,7 @@ "children": [ { "type": "text", - "value": "exports" + "value": "inline-link.input" } ] }, diff --git a/test/fixture/jsx.output.custom.md b/test/fixture/jsx.output.custom.md index 5eb617f6e..fc2f7c1d5 100644 --- a/test/fixture/jsx.output.custom.md +++ b/test/fixture/jsx.output.custom.md @@ -1,4 +1,4 @@ -# exports +# jsx.input This function returns the number one. diff --git a/test/fixture/jsx.output.json b/test/fixture/jsx.output.json index 975ea9a72..6769cdef3 100644 --- a/test/fixture/jsx.output.json +++ b/test/fixture/jsx.output.json @@ -35,12 +35,7 @@ }, "code": "var util = require('util');\n\n/**\n * This function returns the number one.\n * @returns {Number} numberone\n */\nmodule.exports = (

hello

);\n" }, - "errors": [ - { - "message": "memberof reference to jsx.input not found", - "commentLineNumber": 0 - } - ], + "errors": [], "returns": [ { "title": "returns", @@ -52,16 +47,14 @@ } } ], - "name": "exports", - "memberof": "jsx.input", - "scope": "static", + "name": "jsx.input", "members": { "instance": [], "static": [] }, "events": [], "path": [ - "exports" + "jsx.input" ] } ] \ No newline at end of file diff --git a/test/fixture/jsx.output.md b/test/fixture/jsx.output.md index 5eb617f6e..fc2f7c1d5 100644 --- a/test/fixture/jsx.output.md +++ b/test/fixture/jsx.output.md @@ -1,4 +1,4 @@ -# exports +# jsx.input This function returns the number one. diff --git a/test/fixture/jsx.output.md.json b/test/fixture/jsx.output.md.json index a563ea3d5..ce3cdfc1b 100644 --- a/test/fixture/jsx.output.md.json +++ b/test/fixture/jsx.output.md.json @@ -10,7 +10,7 @@ "children": [ { "type": "text", - "value": "exports" + "value": "jsx.input" } ] }, diff --git a/test/fixture/multiexample.output.custom.md b/test/fixture/multiexample.output.custom.md index 2327db903..1936816af 100644 --- a/test/fixture/multiexample.output.custom.md +++ b/test/fixture/multiexample.output.custom.md @@ -1,4 +1,4 @@ -# exports +# multiexample.input This function returns the number one. diff --git a/test/fixture/multiexample.output.json b/test/fixture/multiexample.output.json index b948d7cd5..4fc52cee3 100644 --- a/test/fixture/multiexample.output.json +++ b/test/fixture/multiexample.output.json @@ -77,12 +77,7 @@ }, "code": "/**\n * This function returns the number one.\n * @returns {Number} numberone\n * @example\n * foo(1);\n * @example\n * foo(2);\n * @throws {Error} if you give it something\n * @throws {TypeError} if you give it something else\n * @augments Foo\n * @augments Bar\n */\nmodule.exports = function () {\n // this returns 1\n return 1;\n};\n" }, - "errors": [ - { - "message": "memberof reference to multiexample.input not found", - "commentLineNumber": 0 - } - ], + "errors": [], "returns": [ { "title": "returns", @@ -134,17 +129,15 @@ "name": "Bar" } ], - "name": "exports", + "name": "multiexample.input", "kind": "function", - "memberof": "multiexample.input", - "scope": "static", "members": { "instance": [], "static": [] }, "events": [], "path": [ - "exports" + "multiexample.input" ] } ] \ No newline at end of file diff --git a/test/fixture/multiexample.output.md b/test/fixture/multiexample.output.md index 2327db903..1936816af 100644 --- a/test/fixture/multiexample.output.md +++ b/test/fixture/multiexample.output.md @@ -1,4 +1,4 @@ -# exports +# multiexample.input This function returns the number one. diff --git a/test/fixture/multiexample.output.md.json b/test/fixture/multiexample.output.md.json index bbe3bafd2..d61fa332a 100644 --- a/test/fixture/multiexample.output.md.json +++ b/test/fixture/multiexample.output.md.json @@ -10,7 +10,7 @@ "children": [ { "type": "text", - "value": "exports" + "value": "multiexample.input" } ] }, diff --git a/test/fixture/simple-hashbang.output.custom.md b/test/fixture/simple-hashbang.output.custom.md index 5eb617f6e..35df8b9c6 100644 --- a/test/fixture/simple-hashbang.output.custom.md +++ b/test/fixture/simple-hashbang.output.custom.md @@ -1,4 +1,4 @@ -# exports +# simple-hashbang.input This function returns the number one. diff --git a/test/fixture/simple-hashbang.output.json b/test/fixture/simple-hashbang.output.json index d347890fc..5182beef8 100644 --- a/test/fixture/simple-hashbang.output.json +++ b/test/fixture/simple-hashbang.output.json @@ -35,12 +35,7 @@ }, "code": "//#!/usr/bin/env node\n\n/**\n * This function returns the number one.\n * @returns {Number} numberone\n */\nmodule.exports = function () {\n // this returns 1\n return 1;\n};\n" }, - "errors": [ - { - "message": "memberof reference to simple-hashbang.input not found", - "commentLineNumber": 0 - } - ], + "errors": [], "returns": [ { "title": "returns", @@ -52,17 +47,15 @@ } } ], - "name": "exports", + "name": "simple-hashbang.input", "kind": "function", - "memberof": "simple-hashbang.input", - "scope": "static", "members": { "instance": [], "static": [] }, "events": [], "path": [ - "exports" + "simple-hashbang.input" ] } ] \ No newline at end of file diff --git a/test/fixture/simple-hashbang.output.md b/test/fixture/simple-hashbang.output.md index 5eb617f6e..35df8b9c6 100644 --- a/test/fixture/simple-hashbang.output.md +++ b/test/fixture/simple-hashbang.output.md @@ -1,4 +1,4 @@ -# exports +# simple-hashbang.input This function returns the number one. diff --git a/test/fixture/simple-hashbang.output.md.json b/test/fixture/simple-hashbang.output.md.json index a563ea3d5..59f4170c3 100644 --- a/test/fixture/simple-hashbang.output.md.json +++ b/test/fixture/simple-hashbang.output.md.json @@ -10,7 +10,7 @@ "children": [ { "type": "text", - "value": "exports" + "value": "simple-hashbang.input" } ] }, diff --git a/test/fixture/simple.output.custom.md b/test/fixture/simple.output.custom.md index 5eb617f6e..93cf80e8e 100644 --- a/test/fixture/simple.output.custom.md +++ b/test/fixture/simple.output.custom.md @@ -1,4 +1,4 @@ -# exports +# simple.input This function returns the number one. diff --git a/test/fixture/simple.output.github.json b/test/fixture/simple.output.github.json index d564df720..26fc9cbc3 100644 --- a/test/fixture/simple.output.github.json +++ b/test/fixture/simple.output.github.json @@ -37,12 +37,7 @@ "path": "test/fixture/simple.input.js", "github": "[github]" }, - "errors": [ - { - "message": "memberof reference to simple.input not found", - "commentLineNumber": 0 - } - ], + "errors": [], "returns": [ { "title": "returns", @@ -54,17 +49,15 @@ } } ], - "name": "exports", + "name": "simple.input", "kind": "function", - "memberof": "simple.input", - "scope": "static", "members": { "instance": [], "static": [] }, "events": [], "path": [ - "exports" + "simple.input" ] } ] \ No newline at end of file diff --git a/test/fixture/simple.output.json b/test/fixture/simple.output.json index 95944df24..250e8ab4b 100644 --- a/test/fixture/simple.output.json +++ b/test/fixture/simple.output.json @@ -35,12 +35,7 @@ }, "code": "/**\n * This function returns the number one.\n * @returns {Number} numberone\n */\nmodule.exports = function () {\n // this returns 1\n return 1;\n};\n" }, - "errors": [ - { - "message": "memberof reference to simple.input not found", - "commentLineNumber": 0 - } - ], + "errors": [], "returns": [ { "title": "returns", @@ -52,17 +47,15 @@ } } ], - "name": "exports", + "name": "simple.input", "kind": "function", - "memberof": "simple.input", - "scope": "static", "members": { "instance": [], "static": [] }, "events": [], "path": [ - "exports" + "simple.input" ] } ] \ No newline at end of file diff --git a/test/fixture/simple.output.md b/test/fixture/simple.output.md index 5eb617f6e..93cf80e8e 100644 --- a/test/fixture/simple.output.md +++ b/test/fixture/simple.output.md @@ -1,4 +1,4 @@ -# exports +# simple.input This function returns the number one. diff --git a/test/fixture/simple.output.md.json b/test/fixture/simple.output.md.json index a563ea3d5..bc9e6503a 100644 --- a/test/fixture/simple.output.md.json +++ b/test/fixture/simple.output.md.json @@ -10,7 +10,7 @@ "children": [ { "type": "text", - "value": "exports" + "value": "simple.input" } ] }, diff --git a/test/lib/infer/membership.js b/test/lib/infer/membership.js index d27bf6fc6..c97364dbd 100644 --- a/test/lib/infer/membership.js +++ b/test/lib/infer/membership.js @@ -286,19 +286,22 @@ test('inferMembership - module.exports', function (t) { }; })[1].memberof, 'mod'); - // https://github.com/documentationjs/documentation/issues/178 - // - // t.equal(evaluate(function () { - // /** @module mod */ - // /** foo */ - // module.exports = 1; - // })[1].memberof, 'mod'); - // - // t.equal(evaluate(function () { - // /** @module mod */ - // /** @returns {undefined} foo */ - // module.exports = function () {}; - // })[1].memberof, 'mod'); + t.equal(evaluate(function () { + /** + * @module mod + * @name exports + */ + module.exports = 1; + })[0].memberof, undefined); + + t.equal(evaluate(function () { + /** + * @module mod + * @name exports + * @returns {undefined} bar + */ + module.exports = function () {}; + })[0].memberof, undefined); t.equal(evaluate(function () { /** @module mod */