diff --git a/lib/infer/kind.js b/lib/infer/kind.js index 4f7fb6d31..34ce699ef 100644 --- a/lib/infer/kind.js +++ b/lib/infer/kind.js @@ -48,6 +48,8 @@ module.exports = function () { } else if (t.isExpressionStatement(path)) { // module.exports = function() {} findKind(path.node.expression.right); + } else if (t.isClassProperty(path)) { + comment.kind = 'member'; } else if (t.isProperty(path)) { // { foo: function() {} } findKind(path.node.value); diff --git a/lib/infer/membership.js b/lib/infer/membership.js index f00293786..66c648321 100644 --- a/lib/infer/membership.js +++ b/lib/infer/membership.js @@ -170,7 +170,7 @@ module.exports = function () { /* * Same as above but for `b: c` vs `b: function () {}`. */ - if (n.isProperty(path.node) && + if (n.isObjectProperty(path.node) && n.isIdentifier(path.node.key)) { path = path.get('key'); } @@ -221,23 +221,18 @@ module.exports = function () { } // class Foo { bar() { } } - if (n.isClassMethod(path) && - n.isClassBody(path.parentPath) && - n.isClassDeclaration(path.parentPath.parentPath)) { - identifiers = [path.parentPath.parentPath.node.id.name]; - var scope = 'instance'; - if (path.node.static == true) { - scope = 'static'; - } - inferMembershipFromIdentifiers(comment, identifiers, scope); - } - // var Foo = class { bar() { } } - if (n.isClassMethod(path) && + // class Foo { prop: T } + // var Foo = class { prop: T } + if ((n.isClassMethod(path) || n.isClassProperty(path)) && n.isClassBody(path.parentPath) && - n.isClassExpression(path.parentPath.parentPath)) { - identifiers = extractIdentifiers(path.parentPath.parentPath.parentPath.get('left')); - scope = 'instance'; + n.isClass(path.parentPath.parentPath)) { + if (n.isExpression(path.parentPath.parentPath)) { + identifiers = extractIdentifiers(path.parentPath.parentPath.parentPath.get('left')); + } else { + identifiers = [path.parentPath.parentPath.node.id.name]; + } + var scope = 'instance'; if (path.node.static == true) { scope = 'static'; } diff --git a/test/fixture/es6-import.output.json b/test/fixture/es6-import.output.json index b4e18d84e..42ee67944 100644 --- a/test/fixture/es6-import.output.json +++ b/test/fixture/es6-import.output.json @@ -839,6 +839,105 @@ "kind": "class", "members": { "instance": [ + { + "description": { + "type": "root", + "children": [ + { + "type": "paragraph", + "children": [ + { + "type": "text", + "value": "This is a property of the sink.", + "position": { + "start": { + "line": 1, + "column": 1, + "offset": 0 + }, + "end": { + "line": 1, + "column": 32, + "offset": 31 + }, + "indent": [] + } + } + ], + "position": { + "start": { + "line": 1, + "column": 1, + "offset": 0 + }, + "end": { + "line": 1, + "column": 32, + "offset": 31 + }, + "indent": [] + } + } + ], + "position": { + "start": { + "line": 1, + "column": 1, + "offset": 0 + }, + "end": { + "line": 1, + "column": 32, + "offset": 31 + } + } + }, + "tags": [], + "loc": { + "start": { + "line": 24, + "column": 2 + }, + "end": { + "line": 26, + "column": 5 + } + }, + "context": { + "loc": { + "start": { + "line": 27, + "column": 2 + }, + "end": { + "line": 27, + "column": 18 + } + }, + "code": "/**\n * This function destructures with defaults.\n */\nfunction destructure({phoneNumbers = [], emailAddresses = [], ...params} = {}) {\n}\n\n/**\n * Similar, but with an array\n */\nfunction destructure([a, b, c]) {\n}\n\n/**\n * This function returns the number one.\n * @param {Array} a an array of numbers\n * @returns {Number} numberone\n */\nvar multiply = (a, b) => a * b;\n\n/**\n * This is a sink\n */\nclass Sink {\n /**\n * This is a property of the sink.\n */\n staticProp = 42;\n\n /**\n * Is it empty\n */\n empty() {\n return 1;\n }\n\n /**\n * This method says hello\n */\n static hello() {\n return 'hello';\n }\n\n /**\n * This is a getter method: it should be documented\n * as a property.\n */\n get aGetter() {\n return 42;\n }\n\n /**\n * @param {number} height the height of the thing\n * @param {number} width the width of the thing\n */\n constructor(height, width) {\n this.height = height;\n this.width = width;\n }\n}\n\n/**\n * This function takes rest params\n */\nfunction functionWithRest(...someParams) {\n}\n\n/**\n * So does this one, with types\n */\nfunction functionWithRestAndType(...someParams: number) {\n}\n\n// FUNCTION TYPES\n\n/**\n * This is an async method\n */\nasync function foo() { }\n\nexport default multiply;\n\n/**\n * @public\n */\nexport default (thisIsTheArgument) => {};\n\n/**\n * This function returns the number one.\n * @returns {Number} numberone\n */\nmodule.exports = () => (

hello

);\n\n/**\n * This tests our support of optional parameters in ES6\n */\nfunction veryImportantTransform(foo = 'bar') {\n return \"42\";\n}\n\n// ACCESS LEVELS\n\n/**\n * A private function\n * @private\n */\nfunction iAmPrivate() { }\n\n/**\n * A protected function\n * @protected\n */\nfunction iAmProtected() { }\n\n/**\n * A public function\n * @public\n */\nfunction iAmPublic() { }\n\n/**\n * A private function using the access tag\n * @access private\n */\nfunction iAmAccessPrivate() { }\n\n/**\n * This is re-exported\n */\nexport { execute } from 'external-module';\n" + }, + "errors": [], + "name": "staticProp", + "kind": "member", + "memberof": "Sink", + "scope": "instance", + "members": { + "instance": [], + "static": [] + }, + "path": [ + { + "name": "Sink", + "kind": "class" + }, + { + "name": "staticProp", + "kind": "member", + "scope": "instance" + } + ], + "namespace": "Sink#staticProp" + }, { "description": { "type": "root", @@ -1344,96 +1443,6 @@ ], "namespace": "Sink" }, - { - "description": { - "type": "root", - "children": [ - { - "type": "paragraph", - "children": [ - { - "type": "text", - "value": "This is a property of the sink.", - "position": { - "start": { - "line": 1, - "column": 1, - "offset": 0 - }, - "end": { - "line": 1, - "column": 32, - "offset": 31 - }, - "indent": [] - } - } - ], - "position": { - "start": { - "line": 1, - "column": 1, - "offset": 0 - }, - "end": { - "line": 1, - "column": 32, - "offset": 31 - }, - "indent": [] - } - } - ], - "position": { - "start": { - "line": 1, - "column": 1, - "offset": 0 - }, - "end": { - "line": 1, - "column": 32, - "offset": 31 - } - } - }, - "tags": [], - "loc": { - "start": { - "line": 24, - "column": 2 - }, - "end": { - "line": 26, - "column": 5 - } - }, - "context": { - "loc": { - "start": { - "line": 27, - "column": 2 - }, - "end": { - "line": 27, - "column": 18 - } - }, - "code": "/**\n * This function destructures with defaults.\n */\nfunction destructure({phoneNumbers = [], emailAddresses = [], ...params} = {}) {\n}\n\n/**\n * Similar, but with an array\n */\nfunction destructure([a, b, c]) {\n}\n\n/**\n * This function returns the number one.\n * @param {Array} a an array of numbers\n * @returns {Number} numberone\n */\nvar multiply = (a, b) => a * b;\n\n/**\n * This is a sink\n */\nclass Sink {\n /**\n * This is a property of the sink.\n */\n staticProp = 42;\n\n /**\n * Is it empty\n */\n empty() {\n return 1;\n }\n\n /**\n * This method says hello\n */\n static hello() {\n return 'hello';\n }\n\n /**\n * This is a getter method: it should be documented\n * as a property.\n */\n get aGetter() {\n return 42;\n }\n\n /**\n * @param {number} height the height of the thing\n * @param {number} width the width of the thing\n */\n constructor(height, width) {\n this.height = height;\n this.width = width;\n }\n}\n\n/**\n * This function takes rest params\n */\nfunction functionWithRest(...someParams) {\n}\n\n/**\n * So does this one, with types\n */\nfunction functionWithRestAndType(...someParams: number) {\n}\n\n// FUNCTION TYPES\n\n/**\n * This is an async method\n */\nasync function foo() { }\n\nexport default multiply;\n\n/**\n * @public\n */\nexport default (thisIsTheArgument) => {};\n\n/**\n * This function returns the number one.\n * @returns {Number} numberone\n */\nmodule.exports = () => (

hello

);\n\n/**\n * This tests our support of optional parameters in ES6\n */\nfunction veryImportantTransform(foo = 'bar') {\n return \"42\";\n}\n\n// ACCESS LEVELS\n\n/**\n * A private function\n * @private\n */\nfunction iAmPrivate() { }\n\n/**\n * A protected function\n * @protected\n */\nfunction iAmProtected() { }\n\n/**\n * A public function\n * @public\n */\nfunction iAmPublic() { }\n\n/**\n * A private function using the access tag\n * @access private\n */\nfunction iAmAccessPrivate() { }\n\n/**\n * This is re-exported\n */\nexport { execute } from 'external-module';\n" - }, - "errors": [], - "name": "staticProp", - "members": { - "instance": [], - "static": [] - }, - "path": [ - { - "name": "staticProp" - } - ], - "namespace": "staticProp" - }, { "description": { "type": "root", diff --git a/test/fixture/es6-import.output.md b/test/fixture/es6-import.output.md index 6d0be24ba..60e9d1456 100644 --- a/test/fixture/es6-import.output.md +++ b/test/fixture/es6-import.output.md @@ -49,6 +49,10 @@ Returns **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refer This is a sink +## staticProp + +This is a property of the sink. + ## empty Is it empty @@ -69,10 +73,6 @@ as a property. This method says hello -# staticProp - -This is a property of the sink. - # functionWithRest This function takes rest params diff --git a/test/fixture/es6-import.output.md.json b/test/fixture/es6-import.output.md.json index dfac7e528..cb03bcb73 100644 --- a/test/fixture/es6-import.output.md.json +++ b/test/fixture/es6-import.output.md.json @@ -875,6 +875,51 @@ "indent": [] } }, + { + "depth": 2, + "type": "heading", + "children": [ + { + "type": "text", + "value": "staticProp" + } + ] + }, + { + "type": "paragraph", + "children": [ + { + "type": "text", + "value": "This is a property of the sink.", + "position": { + "start": { + "line": 1, + "column": 1, + "offset": 0 + }, + "end": { + "line": 1, + "column": 32, + "offset": 31 + }, + "indent": [] + } + } + ], + "position": { + "start": { + "line": 1, + "column": 1, + "offset": 0 + }, + "end": { + "line": 1, + "column": 32, + "offset": 31 + }, + "indent": [] + } + }, { "depth": 2, "type": "heading", @@ -1185,51 +1230,6 @@ "indent": [] } }, - { - "depth": 1, - "type": "heading", - "children": [ - { - "type": "text", - "value": "staticProp" - } - ] - }, - { - "type": "paragraph", - "children": [ - { - "type": "text", - "value": "This is a property of the sink.", - "position": { - "start": { - "line": 1, - "column": 1, - "offset": 0 - }, - "end": { - "line": 1, - "column": 32, - "offset": 31 - }, - "indent": [] - } - } - ], - "position": { - "start": { - "line": 1, - "column": 1, - "offset": 0 - }, - "end": { - "line": 1, - "column": 32, - "offset": 31 - }, - "indent": [] - } - }, { "depth": 1, "type": "heading", diff --git a/test/fixture/es6.output.json b/test/fixture/es6.output.json index 2f8441e42..244d609bb 100644 --- a/test/fixture/es6.output.json +++ b/test/fixture/es6.output.json @@ -580,6 +580,105 @@ "kind": "class", "members": { "instance": [ + { + "description": { + "type": "root", + "children": [ + { + "type": "paragraph", + "children": [ + { + "type": "text", + "value": "This is a property of the sink.", + "position": { + "start": { + "line": 1, + "column": 1, + "offset": 0 + }, + "end": { + "line": 1, + "column": 32, + "offset": 31 + }, + "indent": [] + } + } + ], + "position": { + "start": { + "line": 1, + "column": 1, + "offset": 0 + }, + "end": { + "line": 1, + "column": 32, + "offset": 31 + }, + "indent": [] + } + } + ], + "position": { + "start": { + "line": 1, + "column": 1, + "offset": 0 + }, + "end": { + "line": 1, + "column": 32, + "offset": 31 + } + } + }, + "tags": [], + "loc": { + "start": { + "line": 24, + "column": 2 + }, + "end": { + "line": 26, + "column": 5 + } + }, + "context": { + "loc": { + "start": { + "line": 27, + "column": 2 + }, + "end": { + "line": 27, + "column": 18 + } + }, + "code": "/**\n * This function destructures with defaults.\n */\nfunction destructure({phoneNumbers = [], emailAddresses = [], ...params} = {}) {\n}\n\n/**\n * Similar, but with an array\n */\nfunction destructure([a, b, c]) {\n}\n\n/**\n * This function returns the number one.\n * @param {Array} a an array of numbers\n * @returns {Number} numberone\n */\nvar multiply = (a, b) => a * b;\n\n/**\n * This is a sink\n */\nclass Sink {\n /**\n * This is a property of the sink.\n */\n staticProp = 42;\n\n /**\n * Is it empty\n */\n empty() {\n return 1;\n }\n\n /**\n * This method says hello\n */\n static hello() {\n return 'hello';\n }\n\n /**\n * This is a getter method: it should be documented\n * as a property.\n */\n get aGetter() {\n return 42;\n }\n\n /**\n * @param {number} height the height of the thing\n * @param {number} width the width of the thing\n */\n constructor(height, width) {\n this.height = height;\n this.width = width;\n }\n}\n\n/**\n * This function takes rest params\n */\nfunction functionWithRest(...someParams) {\n}\n\n/**\n * So does this one, with types\n */\nfunction functionWithRestAndType(...someParams: number) {\n}\n\n// FUNCTION TYPES\n\n/**\n * This is an async method\n */\nasync function foo() { }\n\nexport default multiply;\n\n/**\n * @public\n */\nexport default (thisIsTheArgument) => {};\n\n/**\n * This function returns the number one.\n * @returns {Number} numberone\n */\nmodule.exports = () => (

hello

);\n\n/**\n * This tests our support of optional parameters in ES6\n */\nfunction veryImportantTransform(foo = 'bar') {\n return \"42\";\n}\n\n// ACCESS LEVELS\n\n/**\n * A private function\n * @private\n */\nfunction iAmPrivate() { }\n\n/**\n * A protected function\n * @protected\n */\nfunction iAmProtected() { }\n\n/**\n * A public function\n * @public\n */\nfunction iAmPublic() { }\n\n/**\n * A private function using the access tag\n * @access private\n */\nfunction iAmAccessPrivate() { }\n\n/**\n * This is re-exported\n */\nexport { execute } from 'external-module';\n" + }, + "errors": [], + "name": "staticProp", + "kind": "member", + "memberof": "Sink", + "scope": "instance", + "members": { + "instance": [], + "static": [] + }, + "path": [ + { + "name": "Sink", + "kind": "class" + }, + { + "name": "staticProp", + "kind": "member", + "scope": "instance" + } + ], + "namespace": "Sink#staticProp" + }, { "description": { "type": "root", @@ -1085,96 +1184,6 @@ ], "namespace": "Sink" }, - { - "description": { - "type": "root", - "children": [ - { - "type": "paragraph", - "children": [ - { - "type": "text", - "value": "This is a property of the sink.", - "position": { - "start": { - "line": 1, - "column": 1, - "offset": 0 - }, - "end": { - "line": 1, - "column": 32, - "offset": 31 - }, - "indent": [] - } - } - ], - "position": { - "start": { - "line": 1, - "column": 1, - "offset": 0 - }, - "end": { - "line": 1, - "column": 32, - "offset": 31 - }, - "indent": [] - } - } - ], - "position": { - "start": { - "line": 1, - "column": 1, - "offset": 0 - }, - "end": { - "line": 1, - "column": 32, - "offset": 31 - } - } - }, - "tags": [], - "loc": { - "start": { - "line": 24, - "column": 2 - }, - "end": { - "line": 26, - "column": 5 - } - }, - "context": { - "loc": { - "start": { - "line": 27, - "column": 2 - }, - "end": { - "line": 27, - "column": 18 - } - }, - "code": "/**\n * This function destructures with defaults.\n */\nfunction destructure({phoneNumbers = [], emailAddresses = [], ...params} = {}) {\n}\n\n/**\n * Similar, but with an array\n */\nfunction destructure([a, b, c]) {\n}\n\n/**\n * This function returns the number one.\n * @param {Array} a an array of numbers\n * @returns {Number} numberone\n */\nvar multiply = (a, b) => a * b;\n\n/**\n * This is a sink\n */\nclass Sink {\n /**\n * This is a property of the sink.\n */\n staticProp = 42;\n\n /**\n * Is it empty\n */\n empty() {\n return 1;\n }\n\n /**\n * This method says hello\n */\n static hello() {\n return 'hello';\n }\n\n /**\n * This is a getter method: it should be documented\n * as a property.\n */\n get aGetter() {\n return 42;\n }\n\n /**\n * @param {number} height the height of the thing\n * @param {number} width the width of the thing\n */\n constructor(height, width) {\n this.height = height;\n this.width = width;\n }\n}\n\n/**\n * This function takes rest params\n */\nfunction functionWithRest(...someParams) {\n}\n\n/**\n * So does this one, with types\n */\nfunction functionWithRestAndType(...someParams: number) {\n}\n\n// FUNCTION TYPES\n\n/**\n * This is an async method\n */\nasync function foo() { }\n\nexport default multiply;\n\n/**\n * @public\n */\nexport default (thisIsTheArgument) => {};\n\n/**\n * This function returns the number one.\n * @returns {Number} numberone\n */\nmodule.exports = () => (

hello

);\n\n/**\n * This tests our support of optional parameters in ES6\n */\nfunction veryImportantTransform(foo = 'bar') {\n return \"42\";\n}\n\n// ACCESS LEVELS\n\n/**\n * A private function\n * @private\n */\nfunction iAmPrivate() { }\n\n/**\n * A protected function\n * @protected\n */\nfunction iAmProtected() { }\n\n/**\n * A public function\n * @public\n */\nfunction iAmPublic() { }\n\n/**\n * A private function using the access tag\n * @access private\n */\nfunction iAmAccessPrivate() { }\n\n/**\n * This is re-exported\n */\nexport { execute } from 'external-module';\n" - }, - "errors": [], - "name": "staticProp", - "members": { - "instance": [], - "static": [] - }, - "path": [ - { - "name": "staticProp" - } - ], - "namespace": "staticProp" - }, { "description": { "type": "root", diff --git a/test/fixture/es6.output.md b/test/fixture/es6.output.md index a0eefa748..567a8fd77 100644 --- a/test/fixture/es6.output.md +++ b/test/fixture/es6.output.md @@ -35,6 +35,10 @@ Returns **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refer This is a sink +## staticProp + +This is a property of the sink. + ## empty Is it empty @@ -55,10 +59,6 @@ as a property. This method says hello -# staticProp - -This is a property of the sink. - # functionWithRest This function takes rest params diff --git a/test/fixture/es6.output.md.json b/test/fixture/es6.output.md.json index 610893cac..329f12376 100644 --- a/test/fixture/es6.output.md.json +++ b/test/fixture/es6.output.md.json @@ -684,6 +684,51 @@ "indent": [] } }, + { + "depth": 2, + "type": "heading", + "children": [ + { + "type": "text", + "value": "staticProp" + } + ] + }, + { + "type": "paragraph", + "children": [ + { + "type": "text", + "value": "This is a property of the sink.", + "position": { + "start": { + "line": 1, + "column": 1, + "offset": 0 + }, + "end": { + "line": 1, + "column": 32, + "offset": 31 + }, + "indent": [] + } + } + ], + "position": { + "start": { + "line": 1, + "column": 1, + "offset": 0 + }, + "end": { + "line": 1, + "column": 32, + "offset": 31 + }, + "indent": [] + } + }, { "depth": 2, "type": "heading", @@ -994,51 +1039,6 @@ "indent": [] } }, - { - "depth": 1, - "type": "heading", - "children": [ - { - "type": "text", - "value": "staticProp" - } - ] - }, - { - "type": "paragraph", - "children": [ - { - "type": "text", - "value": "This is a property of the sink.", - "position": { - "start": { - "line": 1, - "column": 1, - "offset": 0 - }, - "end": { - "line": 1, - "column": 32, - "offset": 31 - }, - "indent": [] - } - } - ], - "position": { - "start": { - "line": 1, - "column": 1, - "offset": 0 - }, - "end": { - "line": 1, - "column": 32, - "offset": 31 - }, - "indent": [] - } - }, { "depth": 1, "type": "heading", pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy