use the correct scope for exported symbols (and their children) in ES 2015 modules (#1293)

This commit is contained in:
Jeff Williams 2017-07-03 14:47:47 -07:00
parent 2dcdb21e96
commit 5660c94adf
3 changed files with 96 additions and 67 deletions

View File

@ -104,6 +104,12 @@ function setModuleScopeMemberOf(doclet) {
doclet.addTag('instance');
}
}
// is this something that the module exports? if so, it's a static member
else if (doclet.meta && doclet.meta.code && doclet.meta.code.node &&
doclet.meta.code.node.parent &&
doclet.meta.code.node.parent.type === Syntax.ExportNamedDeclaration) {
doclet.addTag('static');
}
// otherwise, it must be an inner member
else {
doclet.addTag('inner');

11
test/fixtures/moduletag11.js vendored Normal file
View File

@ -0,0 +1,11 @@
/**
* Test module.
* @module foo
*/
/** Test class. */
export class Foo {
/** Test method. */
testMethod() {}
}

View File

@ -87,83 +87,95 @@ describe('@module tag', function() {
});
});
if (jasmine.jsParser !== 'rhino') {
describe('ES 2015 modules', function() {
describe('that export a default', function() {
describe('value type', function() {
var docSet = jasmine.getDocSetFromFile('test/fixtures/moduletag6.js');
var exports = docSet.getByLongname('module:appname').filter(function(d) {
return d.kind === 'member';
})[0];
describe('ES 2015 modules', function() {
describe('that export a default', function() {
describe('value type', function() {
var docSet = jasmine.getDocSetFromFile('test/fixtures/moduletag6.js');
var exports = docSet.getByLongname('module:appname').filter(function(d) {
return d.kind === 'member';
})[0];
it('When a value type is exported, it has the same name as the module longname', function() {
expect(exports.name).toBe('module:appname');
});
});
describe('object', function() {
var docSet = jasmine.getDocSetFromFile('test/fixtures/moduletag7.js');
var blend = docSet.getByLongname('module:color/mixer.blend')[0];
it('When an object is exported, its members have the correct name, memberof, and kind', function() {
expect(blend.name).toBe('blend');
expect(blend.memberof).toBe('module:color/mixer');
expect(blend.kind).toBe('function');
});
it('When a value type is exported, it has the same name as the module longname', function() {
expect(exports.name).toBe('module:appname');
});
});
describe('that export named values', function() {
var docSet = jasmine.getDocSetFromFile('test/fixtures/moduletag8.js');
describe('object', function() {
var docSet = jasmine.getDocSetFromFile('test/fixtures/moduletag7.js');
var blend = docSet.getByLongname('module:color/mixer.blend')[0];
var lastColor = docSet.getByLongname('module:color/mixer.lastColor')[0];
var name = docSet.getByLongname('module:color/mixer.name')[0];
var toRgb = docSet.getByLongname('module:color/mixer.toRgb')[0];
it('When a method is exported, it has the correct name, memberof, and kind', function() {
it('When an object is exported, its members have the correct name, memberof, and kind', function() {
expect(blend.name).toBe('blend');
expect(blend.memberof).toBe('module:color/mixer');
expect(blend.kind).toBe('function');
});
it('When a variable is exported, it has the correct name, memberof, and kind', function() {
expect(lastColor.name).toBe('lastColor');
expect(lastColor.memberof).toBe('module:color/mixer');
expect(lastColor.kind).toBe('member');
});
it('When a constant is exported, it has the correct name, memberof, and kind', function() {
expect(name.name).toBe('name');
expect(name.memberof).toBe('module:color/mixer');
expect(name.kind).toBe('constant');
});
it('When a symbol is exported under a different name, it has the correct name, memberof, and kind', function() {
expect(toRgb.name).toBe('toRgb');
expect(toRgb.memberof).toBe('module:color/mixer');
expect(toRgb.kind).toBe('function');
});
});
describe('that export another module in its entirety', function() {
it('should not crash JSDoc', function() {
function getDocSet() {
jasmine.getDocSetFromFile('test/fixtures/moduletag9.js');
}
expect(getDocSet).not.toThrow();
});
});
describe('that export an unnamed default function', function() {
it('should not crash JSDoc', function() {
function getDocSet() {
jasmine.getDocSetFromFile('test/fixtures/moduletag10.js');
}
expect(getDocSet).not.toThrow();
});
});
});
}
describe('that export named values', function() {
var docSet = jasmine.getDocSetFromFile('test/fixtures/moduletag8.js');
var blend = docSet.getByLongname('module:color/mixer.blend')[0];
var lastColor = docSet.getByLongname('module:color/mixer.lastColor')[0];
var name = docSet.getByLongname('module:color/mixer.name')[0];
var toRgb = docSet.getByLongname('module:color/mixer.toRgb')[0];
it('When a method is exported, it has the correct name, memberof, and kind', function() {
expect(blend.name).toBe('blend');
expect(blend.memberof).toBe('module:color/mixer');
expect(blend.kind).toBe('function');
});
it('When a variable is exported, it has the correct name, memberof, and kind', function() {
expect(lastColor.name).toBe('lastColor');
expect(lastColor.memberof).toBe('module:color/mixer');
expect(lastColor.kind).toBe('member');
});
it('When a constant is exported, it has the correct name, memberof, and kind', function() {
expect(name.name).toBe('name');
expect(name.memberof).toBe('module:color/mixer');
expect(name.kind).toBe('constant');
});
it('When a symbol is exported under a different name, it has the correct name, memberof, and kind', function() {
expect(toRgb.name).toBe('toRgb');
expect(toRgb.memberof).toBe('module:color/mixer');
expect(toRgb.kind).toBe('function');
});
});
describe('that export another module in its entirety', function() {
it('should not crash JSDoc', function() {
function getDocSet() {
jasmine.getDocSetFromFile('test/fixtures/moduletag9.js');
}
expect(getDocSet).not.toThrow();
});
});
describe('that export an unnamed default function', function() {
it('should not crash JSDoc', function() {
function getDocSet() {
jasmine.getDocSetFromFile('test/fixtures/moduletag10.js');
}
expect(getDocSet).not.toThrow();
});
});
describe('that export a class', function() {
var docSet = jasmine.getDocSetFromFile('test/fixtures/moduletag11.js');
var foo = docSet.getByLongname('module:foo.Foo')[0];
var testMethod = docSet.getByLongname('module:foo.Foo#testMethod')[0];
it('should identify the correct scope for the exported class', function() {
expect(foo).toBeDefined();
});
it('should identify the correct scope for the exported class\'s methods', function() {
expect(testMethod).toBeDefined();
});
});
});
});