stop adding a scope property to module doclets that include an exports tag (#782)

This commit is contained in:
Jeff Williams 2014-10-11 15:09:53 -07:00
parent bb8a66291a
commit 68ceb33ec3
2 changed files with 37 additions and 4 deletions

View File

@ -264,9 +264,12 @@ function newSymbolDoclet(parser, docletSrc, e) {
return false; return false;
} }
// set the scope to global unless a) the doclet is a memberof something or b) we're in a module // set the scope to global unless any of the following are true:
// that exports only this symbol // a) the doclet is a memberof something
if ( !newDoclet.memberof && (!currentModule || currentModule.longname !== newDoclet.name) ) { // 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; newDoclet.scope = SCOPE_NAMES.GLOBAL;
} }

View File

@ -24,6 +24,10 @@ describe('@exports tag', function() {
expect(shirt.kind).toEqual('module'); 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() { 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(typeof color).toEqual('object');
expect(color.memberof).toEqual('module:my/shirt'); expect(color.memberof).toEqual('module:my/shirt');
@ -54,6 +58,10 @@ describe('@exports tag', function() {
expect(coat.kind).toEqual('module'); 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() { 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(typeof wool).toEqual('object');
expect(wool.memberof).toEqual('module:my/coat'); 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 getstyle = docSet.getByLongname('module:html/utils.getStyleProperty')[0];
var inhead = docSet.getByLongname('module:html/utils.isInHead')[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() { 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(typeof getstyle).toEqual('object');
expect(getstyle.memberof).toEqual('module:html/utils'); 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(typeof inhead).toEqual('object');
expect(inhead.memberof).toEqual('module:html/utils'); 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 innerClass = docSet.getByLongname('module:some/module~myClass')[0];
var method = docSet.getByLongname('module:some/module~myClass#myMethod')[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() { it('An inner class declared as a function in a module should be documented.', function() {
expect(typeof innerClass).toEqual('object'); expect(typeof innerClass).toEqual('object');
}); });
@ -94,8 +111,13 @@ describe('@exports tag', function() {
describe('variable shadowing', function() { describe('variable shadowing', function() {
var docSet = jasmine.getDocSetFromFile('test/fixtures/exportstag5.js'); var docSet = jasmine.getDocSetFromFile('test/fixtures/exportstag5.js');
var foo = docSet.getByLongname('module:Foo')[0];
var method = docSet.getByLongname('module:Foo#bar')[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() { 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.'); 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'); 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() { 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(typeof color).toBe('object');
expect(color.memberof).toBe('module:my/shirt'); expect(color.memberof).toBe('module:my/shirt');
@ -152,6 +178,10 @@ describe('@exports tag', function() {
expect(shirt.kind).toEqual('module'); 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() { 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(typeof color).toBe('object');
expect(color.memberof).toBe('module:my/shirt'); expect(color.memberof).toBe('module:my/shirt');