diff --git a/lib/jsdoc/tag/dictionary/definitions.js b/lib/jsdoc/tag/dictionary/definitions.js index 6ff62de6..469ddbde 100644 --- a/lib/jsdoc/tag/dictionary/definitions.js +++ b/lib/jsdoc/tag/dictionary/definitions.js @@ -1003,7 +1003,13 @@ exports.closureTags = { type: cloneTagDef(baseTags.type, { mustNotHaveDescription: false }), - typedef: cloneTagDef(baseTags.typedef), + typedef: { + canHaveType: true, + onTagged: function(doclet, tag) { + setDocletKindToTitle(doclet, tag); + setDocletTypeToValueType(doclet, tag); + } + }, // Closure Compiler only unrestricted: { onTagged: ignore diff --git a/test/fixtures/typedeftag2.js b/test/fixtures/typedeftag2.js new file mode 100644 index 00000000..070e85ad --- /dev/null +++ b/test/fixtures/typedeftag2.js @@ -0,0 +1,2 @@ +/** @typedef {(string|number)} */ +calc.NumberLike; diff --git a/test/specs/tags/typedeftag.js b/test/specs/tags/typedeftag.js index 0714b4f6..55c86b68 100644 --- a/test/specs/tags/typedeftag.js +++ b/test/specs/tags/typedeftag.js @@ -1,41 +1,94 @@ 'use strict'; describe('@typedef tag', function() { - var docSet = jasmine.getDocSetFromFile('test/fixtures/typedeftag.js'); - var numberlike = docSet.getByLongname('calc.NumberLike')[0]; - var operator = docSet.getByLongname('calc.Operator')[0]; - var result = docSet.getByLongname('calc.Result')[0]; - var calculatorBattery = docSet.getByLongname('CalculatorBattery')[0]; - - it('When a comment has a @typedef tag, the doclet has a kind property set to "typedef".', function() { - expect(numberlike.kind).toBe('typedef'); + afterEach(function() { + jasmine.restoreTagDictionary(); }); - it('When a comment has a @typedef tag with a type, the doclet has a type property set to that type.', function() { - expect(typeof numberlike.type).toBe('object'); - expect(typeof numberlike.type.names).toBe('object'); - expect(numberlike.type.names.length).toBe(2); - expect(numberlike.type.names[0]).toBe('string'); - expect(numberlike.type.names[1]).toBe('number'); + describe('JSDoc tags', function() { + beforeEach(function() { + jasmine.replaceTagDictionary('jsdoc'); + }); + + it('When a comment has a @typedef tag, the doclet has a kind property set to "typedef".', function() { + var docSet = jasmine.getDocSetFromFile('test/fixtures/typedeftag.js'); + var numberlike = docSet.getByLongname('calc.NumberLike')[0]; + + expect(numberlike.kind).toBe('typedef'); + }); + + it('When a comment has a @typedef tag with a type, the doclet has a type property set to that type.', function() { + var docSet = jasmine.getDocSetFromFile('test/fixtures/typedeftag.js'); + var numberlike = docSet.getByLongname('calc.NumberLike')[0]; + + expect(typeof numberlike.type).toBe('object'); + expect(Array.isArray(numberlike.type.names)).toBe(true); + expect(numberlike.type.names.length).toBe(2); + expect(numberlike.type.names[0]).toBe('string'); + expect(numberlike.type.names[1]).toBe('number'); + }); + + it('When a comment has a @typedef tag with a name, the doclet has a name property set to that name.', function() { + var docSet = jasmine.getDocSetFromFile('test/fixtures/typedeftag.js'); + var numberlike = docSet.getByLongname('calc.NumberLike')[0]; + + expect(numberlike.name).toBe('NumberLike'); + expect(numberlike.longname).toBe('calc.NumberLike'); + }); + + it('When a symbol has a @typedef tag without a name, the doclet has a name property set to the symbol name.', function() { + var docSet = jasmine.getDocSetFromFile('test/fixtures/typedeftag.js'); + var operator = docSet.getByLongname('calc.Operator')[0]; + + expect(operator.name).toBe('Operator'); + expect(operator.longname).toBe('calc.Operator'); + }); + + it('When a symbol has a @typedef tag with a name, the name in the tag takes precedence over the symbol name.', function() { + var docSet = jasmine.getDocSetFromFile('test/fixtures/typedeftag.js'); + var result = docSet.getByLongname('calc.Result')[0]; + + expect(result.name).toBe('Result'); + expect(result.longname).toBe('calc.Result'); + }); + + it('When a symbol has a @typedef tag with a name and no scope, the scope defaults to `global`.', function() { + var docSet = jasmine.getDocSetFromFile('test/fixtures/typedeftag.js'); + var calculatorBattery = docSet.getByLongname('CalculatorBattery')[0]; + + expect(calculatorBattery).toBeDefined(); + expect(calculatorBattery.scope).toBe('global'); + }); }); - it('When a comment has a @typedef tag with a name, the doclet has a name property set to that name.', function() { - expect(numberlike.name).toBe('NumberLike'); - expect(numberlike.longname).toBe('calc.NumberLike'); - }); + describe('Closure Compiler tags', function() { + beforeEach(function() { + jasmine.replaceTagDictionary('closure'); + }); - it('When a symbol has a @typedef tag without a name, the doclet has a name property set to the symbol name.', function() { - expect(operator.name).toBe('Operator'); - expect(operator.longname).toBe('calc.Operator'); - }); + it('When a comment has a @typedef tag, the doclet has a kind property set to "typedef".', function() { + var docSet = jasmine.getDocSetFromFile('test/fixtures/typedeftag2.js'); + var numberlike = docSet.getByLongname('calc.NumberLike')[0]; - it('When a symbol has a @typedef tag with a name, the name in the tag takes precedence over the symbol name.', function() { - expect(result.name).toBe('Result'); - expect(result.longname).toBe('calc.Result'); - }); + expect(numberlike.kind).toBe('typedef'); + }); - it('When a symbol has a @typedef tag with a name and no scope, the scope defaults to `global`.', function() { - expect(calculatorBattery).toBeDefined(); - expect(calculatorBattery.scope).toBe('global'); + it('When a comment has a @typedef tag with a type, the doclet has a type property set to that type.', function() { + var docSet = jasmine.getDocSetFromFile('test/fixtures/typedeftag2.js'); + var numberlike = docSet.getByLongname('calc.NumberLike')[0]; + + expect(typeof numberlike.type).toBe('object'); + expect(Array.isArray(numberlike.type.names)).toBe(true); + expect(numberlike.type.names.length).toBe(2); + expect(numberlike.type.names[0]).toBe('string'); + expect(numberlike.type.names[1]).toBe('number'); + }); + + it('When a symbol has a @typedef tag, the doclet has a name property set to the symbol name.', function() { + var docSet = jasmine.getDocSetFromFile('test/fixtures/typedeftag2.js'); + var numberlike = docSet.getByLongname('calc.NumberLike')[0]; + + expect(numberlike.name).toBe('NumberLike'); + }); }); });