From 97a22a0f632ca8524323ecba6290f01f3bd10dd8 Mon Sep 17 00:00:00 2001 From: lcharbon Date: Fri, 12 Oct 2018 15:12:51 -0400 Subject: [PATCH] fix: Update scope for a comment that is memberof an other to defaults to static. fix #197 --- __tests__/__snapshots__/bin-readme.js.snap | 36 ++++++++++++++++++++++ __tests__/__snapshots__/test.js.snap | 9 ++++-- __tests__/lib/hierarchy.js | 16 ++++++++++ src/hierarchy.js | 2 ++ 4 files changed, 60 insertions(+), 3 deletions(-) diff --git a/__tests__/__snapshots__/bin-readme.js.snap b/__tests__/__snapshots__/bin-readme.js.snap index f82e9545f..db4a10de3 100644 --- a/__tests__/__snapshots__/bin-readme.js.snap +++ b/__tests__/__snapshots__/bin-readme.js.snap @@ -36,6 +36,42 @@ A second function with docs " `; +exports[`readme command --diff-only: changes needed 1`] = ` +"# A title + +# API + + + +### Table of Contents + +- [foo](#foo) + - [Parameters](#parameters) +- [bar](#bar) + - [Parameters](#parameters-1) + +## foo + +A function with documentation. + +### Parameters + +- \`a\` {string} blah + +Returns **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** answer + +## bar + +A second function with docs + +### Parameters + +- \`b\` + +# Another section +" +`; + exports[`readme command --readme-file 1`] = ` "# A title diff --git a/__tests__/__snapshots__/test.js.snap b/__tests__/__snapshots__/test.js.snap index 66be7220d..fb38152ea 100644 --- a/__tests__/__snapshots__/test.js.snap +++ b/__tests__/__snapshots__/test.js.snap @@ -22680,7 +22680,7 @@ Array [ "static": Array [], }, "name": "getFoo", - "namespace": "MyClass#getFoo", + "namespace": ".MyClass#getFoo", "params": Array [ Object { "description": Object { @@ -22748,6 +22748,7 @@ Array [ Object { "kind": "class", "name": "MyClass", + "scope": "static", }, Object { "kind": "function", @@ -22933,12 +22934,13 @@ Array [ "static": Array [], }, "name": "getUndefined", - "namespace": "MyClass.getUndefined", + "namespace": ".MyClass.getUndefined", "params": Array [], "path": Array [ Object { "kind": "class", "name": "MyClass", + "scope": "static", }, Object { "kind": "function", @@ -23025,12 +23027,13 @@ Array [ ], }, "name": "MyClass", - "namespace": "MyClass", + "namespace": ".MyClass", "params": Array [], "path": Array [ Object { "kind": "class", "name": "MyClass", + "scope": "static", }, ], "properties": Array [], diff --git a/__tests__/lib/hierarchy.js b/__tests__/lib/hierarchy.js index de763e929..33b99291e 100644 --- a/__tests__/lib/hierarchy.js +++ b/__tests__/lib/hierarchy.js @@ -184,3 +184,19 @@ test('hierarchy - object prototype member names', function() { 'otherMethod' ]); }); + +test('hierarchy - member namespace defaults to static', function() { + const comments = evaluate(function() { + /** + * @namespace fooNamespace + */ + /** + * @class BarClass + * @memberof fooNamespace + */ + }); + + expect(comments[0].members.static[0].namespace).toEqual( + 'fooNamespace.BarClass' + ); +}); diff --git a/src/hierarchy.js b/src/hierarchy.js index ab94adf8e..dd0cbd8ec 100644 --- a/src/hierarchy.js +++ b/src/hierarchy.js @@ -39,6 +39,8 @@ function pick(comment) { if (comment.scope) { item.scope = comment.scope; + } else if (comment.memberof) { + item.scope = 'static'; } return item;