From 60143a457f61b7bcf3f72f18b9be027410148ef0 Mon Sep 17 00:00:00 2001 From: Jeff Williams Date: Sun, 16 Jul 2017 18:48:40 -0700 Subject: [PATCH] support `preserve` tag (Closure Compiler only) (#605) --- lib/jsdoc/tag/dictionary/definitions.js | 2 ++ test/fixtures/preservetag.js | 2 ++ test/specs/tags/preservetag.js | 43 +++++++++++++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 test/fixtures/preservetag.js create mode 100644 test/specs/tags/preservetag.js diff --git a/lib/jsdoc/tag/dictionary/definitions.js b/lib/jsdoc/tag/dictionary/definitions.js index 5e357ab7..983a664e 100644 --- a/lib/jsdoc/tag/dictionary/definitions.js +++ b/lib/jsdoc/tag/dictionary/definitions.js @@ -931,6 +931,8 @@ exports.closureTags = { polymerBehavior: { onTagged: ignore }, + // Closure Compiler only + preserve: cloneTagDef(baseTags.license), private: { canHaveType: true, onTagged: function(doclet, tag) { diff --git a/test/fixtures/preservetag.js b/test/fixtures/preservetag.js new file mode 100644 index 00000000..8d07d7f8 --- /dev/null +++ b/test/fixtures/preservetag.js @@ -0,0 +1,2 @@ +/** @preserve My cool license goes here. */ +var x; diff --git a/test/specs/tags/preservetag.js b/test/specs/tags/preservetag.js new file mode 100644 index 00000000..f1f42c48 --- /dev/null +++ b/test/specs/tags/preservetag.js @@ -0,0 +1,43 @@ +'use strict'; + +describe('@preserve tag', function() { + var env = require('jsdoc/env'); + var logger = require('jsdoc/util/logger'); + + var allowUnknownTags = Boolean(env.conf.tags.allowUnknownTags); + + beforeEach(function() { + env.conf.tags.allowUnknownTags = false; + spyOn(logger, 'error'); + }); + + afterEach(function() { + jasmine.restoreTagDictionary(); + env.conf.tags.allowUnknownTags = allowUnknownTags; + }); + + describe('JSDoc tags', function() { + beforeEach(function() { + jasmine.replaceTagDictionary('jsdoc'); + }); + + it('should not recognize the @preserve tag', function() { + jasmine.getDocSetFromFile('test/fixtures/preservetag.js'); + + expect(logger.error).toHaveBeenCalled(); + }); + }); + + describe('Closure Compiler tags', function() { + beforeEach(function() { + jasmine.replaceTagDictionary('closure'); + }); + + it('should set the doclet\'s `license` property to the tag value', function() { + var docSet = jasmine.getDocSetFromFile('test/fixtures/preservetag.js'); + var x = docSet.getByLongname('x')[0]; + + expect(x.license).toBe('My cool license goes here.'); + }); + }); +});