From 34745de61a8d2529d3fa1b72192c852f691a7735 Mon Sep 17 00:00:00 2001 From: Roman Dvornov Date: Sun, 8 May 2016 19:56:40 +0300 Subject: [PATCH] the same name and values for comments option (cli and compress function) - specialComments -> comments - values: exclamation, first-exclamation, none and boolean (true=exclamation, false=none) --- lib/cli.js | 16 ++++++---------- lib/compressor/index.js | 22 +++++++++------------- test/compress.js | 26 +++++++++++++++----------- 3 files changed, 30 insertions(+), 34 deletions(-) diff --git a/lib/cli.js b/lib/cli.js index 87dea0a9..83846875 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -173,19 +173,15 @@ function resolveSourceMap(source, inputMap, map, inputFile, outputFile) { }; } -function processCommentsOption(specialComments) { - switch (specialComments) { +function processCommentsOption(value) { + switch (value) { case 'exclamation': - return 'all'; - case 'first-exclamation': - return 'first-only'; - case 'none': - return false; + return value; } - console.error('Wrong value for `comments` option: %s', specialComments); + console.error('Wrong value for `comments` option: %s', value); process.exit(2); } @@ -209,7 +205,7 @@ var command = cli.create('csso', '[input] [output]') var map = options.map; var inputMap = options.inputMap; var structureOptimisationOff = options.restructureOff; - var specialComments = processCommentsOption(options.comments); + var comments = processCommentsOption(options.comments); var debug = options.debug; var statistics = options.stat; var inputStream; @@ -261,7 +257,7 @@ var command = cli.create('csso', '[input] [output]') sourceMap: sourceMap.output, usage: usageData, restructure: !structureOptimisationOff, - specialComments: specialComments, + comments: comments, debug: debug }); diff --git a/lib/compressor/index.js b/lib/compressor/index.js index ca5dd760..2c47165a 100644 --- a/lib/compressor/index.js +++ b/lib/compressor/index.js @@ -65,16 +65,16 @@ function compressBlock(ast, usageData, num, logger) { return ast; } -function getSpecialCommentsOption(options) { - var specialComments = 'specialComments' in options ? options.specialComments : 'all'; +function getCommentsOption(options) { + var comments = 'comments' in options ? options.comments : 'exclamation'; - if (typeof specialComments === 'boolean') { - specialComments = specialComments ? 'all' : false; - } else if (specialComments !== 'all' && specialComments !== 'first-only') { - specialComments = false; + if (typeof comments === 'boolean') { + comments = comments ? 'exclamation' : false; + } else if (comments !== 'exclamation' && comments !== 'first-exclamation') { + comments = false; } - return specialComments; + return comments; } function getRestructureOption(options) { @@ -88,7 +88,7 @@ module.exports = function compress(ast, options) { ast = ast || { type: 'StyleSheet', rules: new List() }; var logger = typeof options.logger === 'function' ? options.logger : Function(); - var specialComments = getSpecialCommentsOption(options); + var specialComments = getCommentsOption(options); var restructuring = getRestructureOption(options); var result = new List(); var block; @@ -99,10 +99,6 @@ module.exports = function compress(ast, options) { var usageData = false; var info = ast.info || null; - if (typeof specialComments === true) { - specialComments = 'all'; - } - if (ast.type !== 'StyleSheet') { blockMode = true; ast = { @@ -169,7 +165,7 @@ module.exports = function compress(ast, options) { } } - if (specialComments !== 'all') { + if (specialComments !== 'exclamation') { specialComments = false; } diff --git a/test/compress.js b/test/compress.js index a9921d68..76a7e70a 100644 --- a/test/compress.js +++ b/test/compress.js @@ -90,7 +90,7 @@ describe('compress', function() { }); }); - describe('specialComments option', function() { + describe('comments option', function() { var css = '/*! first *//*! second *//*! third */'; var all = '/*! first */\n/*! second */\n/*! third */'; @@ -98,24 +98,28 @@ describe('compress', function() { assert.equal(csso.minify(css).css, all); }); - it('shouldn\'t remove exclamation comments when specialComments is true', function() { - assert.equal(csso.minify(css, { specialComments: true }).css, all); + it('shouldn\'t remove exclamation comments when comments is true', function() { + assert.equal(csso.minify(css, { comments: true }).css, all); }); - it('shouldn\'t remove exclamation comments when specialComments is "all"', function() { - assert.equal(csso.minify(css, { specialComments: 'all' }).css, all); + it('shouldn\'t remove exclamation comments when comments is "exclamation"', function() { + assert.equal(csso.minify(css, { comments: 'exclamation' }).css, all); }); - it('should remove every exclamation comment when specialComments is false', function() { - assert.equal(csso.minify(css, { specialComments: false }).css, ''); + it('should remove every exclamation comment when comments is false', function() { + assert.equal(csso.minify(css, { comments: false }).css, ''); }); - it('should remove every exclamation comment when specialComments has wrong value', function() { - assert.equal(csso.minify(css, { specialComments: 'foo' }).css, ''); + it('should remove every exclamation comment when comments is "none"', function() { + assert.equal(csso.minify(css, { comments: 'none' }).css, ''); }); - it('should remove every exclamation comment except first when specialComments is "first-only"', function() { - assert.equal(csso.minify(css, { specialComments: 'first-only' }).css, '/*! first */'); + it('should remove every exclamation comment when comments has wrong value', function() { + assert.equal(csso.minify(css, { comments: 'foo' }).css, ''); + }); + + it('should remove every exclamation comment except first when comments is "first-exclamation"', function() { + assert.equal(csso.minify(css, { comments: 'first-exclamation' }).css, '/*! first */'); }); });