From 68ceb33ec3a3f99ea9c8432d9c6b311d31e6a6f3 Mon Sep 17 00:00:00 2001 From: Jeff Williams Date: Sat, 11 Oct 2014 15:09:53 -0700 Subject: [PATCH] stop adding a `scope` property to module doclets that include an `exports` tag (#782) --- lib/jsdoc/src/handlers.js | 9 ++++++--- test/specs/tags/exportstag.js | 32 +++++++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/lib/jsdoc/src/handlers.js b/lib/jsdoc/src/handlers.js index 8cb11e9f..36a7a61a 100644 --- a/lib/jsdoc/src/handlers.js +++ b/lib/jsdoc/src/handlers.js @@ -264,9 +264,12 @@ function newSymbolDoclet(parser, docletSrc, e) { return false; } - // set the scope to global unless a) the doclet is a memberof something or b) we're in a module - // that exports only this symbol - if ( !newDoclet.memberof && (!currentModule || currentModule.longname !== newDoclet.name) ) { + // set the scope to global unless any of the following are true: + // a) the doclet is a memberof something + // b) the doclet represents a module + // c) we're in a module that exports only this symbol + if ( !newDoclet.memberof && newDoclet.kind !== 'module' && + (!currentModule || currentModule.longname !== newDoclet.name) ) { newDoclet.scope = SCOPE_NAMES.GLOBAL; } diff --git a/test/specs/tags/exportstag.js b/test/specs/tags/exportstag.js index 1a8822de..a895aad4 100644 --- a/test/specs/tags/exportstag.js +++ b/test/specs/tags/exportstag.js @@ -24,6 +24,10 @@ describe('@exports tag', function() { expect(shirt.kind).toEqual('module'); }); + it('When an objlit symbol has an @exports tag, the module doclet does not have a scope.', function() { + expect(shirt.scope).not.toBeDefined(); + }); + it('When an objlit symbol has an @exports tag, the objlit members are documented as members of the module.', function() { expect(typeof color).toEqual('object'); expect(color.memberof).toEqual('module:my/shirt'); @@ -54,6 +58,10 @@ describe('@exports tag', function() { expect(coat.kind).toEqual('module'); }); + it('When a function symbol has an @exports tag, the module doclet does not have a scope.', function() { + expect(coat.scope).not.toBeDefined(); + }); + it('When a function symbol has an @exports tag, the this members are documented as instance members of the module.', function() { expect(typeof wool).toEqual('object'); expect(wool.memberof).toEqual('module:my/coat'); @@ -66,14 +74,19 @@ describe('@exports tag', function() { var getstyle = docSet.getByLongname('module:html/utils.getStyleProperty')[0]; var inhead = docSet.getByLongname('module:html/utils.isInHead')[0]; + it('When a function symbol has an @exports tag, the module doclet does not have a scope.', function() { + expect(html.scope).not.toBeDefined(); + }); + it('When a function symbol has an @exports tag and there is an objlit named "exports" the members are documented as members of the module.', function() { expect(typeof getstyle).toEqual('object'); expect(getstyle.memberof).toEqual('module:html/utils'); }); - it('When a function symbol has an @exports tag and there are members assinged to an "exports" name, the members are documented as members of the module.', function() { + it('When a function symbol has an @exports tag and there are members assigned to an "exports" name, the members are documented as members of the module.', function() { expect(typeof inhead).toEqual('object'); expect(inhead.memberof).toEqual('module:html/utils'); + }); }); @@ -83,6 +96,10 @@ describe('@exports tag', function() { var innerClass = docSet.getByLongname('module:some/module~myClass')[0]; var method = docSet.getByLongname('module:some/module~myClass#myMethod')[0]; + it('When a function symbol has an @exports tag, the module doclet does not have a scope.', function() { + expect(module.scope).not.toBeDefined(); + }); + it('An inner class declared as a function in a module should be documented.', function() { expect(typeof innerClass).toEqual('object'); }); @@ -94,8 +111,13 @@ describe('@exports tag', function() { describe('variable shadowing', function() { var docSet = jasmine.getDocSetFromFile('test/fixtures/exportstag5.js'); + var foo = docSet.getByLongname('module:Foo')[0]; var method = docSet.getByLongname('module:Foo#bar')[0]; + it('When a var has an @exports tag, the module doclet does not have a scope.', function() { + expect(foo.scope).not.toBeDefined(); + }); + it('A variable defined in an inner scope should correctly shadow a variable in an outer scope.', function() { expect(method.description).toBe('This should be in the Foo module doc.'); }); @@ -122,6 +144,10 @@ describe('@exports tag', function() { expect(shirt.kind).toEqual('module'); }); + it('When a param has an @exports tag, the module doclet does not have a scope.', function() { + expect(shirt.scope).not.toBeDefined(); + }); + it('When a param has an @exports tag, the properties added to the param are documented as members of the module.', function() { expect(typeof color).toBe('object'); expect(color.memberof).toBe('module:my/shirt'); @@ -152,6 +178,10 @@ describe('@exports tag', function() { expect(shirt.kind).toEqual('module'); }); + it('When a symbol has an @exports tag, the module doclet does not have a scope.', function() { + expect(shirt.scope).not.toBeDefined(); + }); + it('When a symbol tagged with @exports is an alias to "exports", the symbol properties are documented as members of the module.', function() { expect(typeof color).toBe('object'); expect(color.memberof).toBe('module:my/shirt');