From 1da64f85f4739dad4fc1e06bcbb315281adbcbf9 Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Thu, 12 Apr 2018 12:27:29 +1200 Subject: [PATCH 01/66] Added tests. --- tests/minifier.js | 243 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 243 insertions(+) diff --git a/tests/minifier.js b/tests/minifier.js index 4f71d662..16cf76cf 100644 --- a/tests/minifier.js +++ b/tests/minifier.js @@ -3397,3 +3397,246 @@ QUnit.test('canCollapseWhitespace and canTrimWhitespace hooks', function(assert) canCollapseWhitespace: canCollapseAndTrimWhitespace }), output); }); + +QUnit.test('style minification with callback', function(assert) { + var input = ''; + var output = ''; + var done = assert.async(); + assert.notOk(minify( + input, + { + minifyCSS: function(css, cb) { + setTimeout(function() { + cb(css + ' callback!'); + }, 0); + } + }, + function(error, result) { + assert.notOk(error); + assert.equal(result, output); + done(); + } + )); +}); + +QUnit.test('script minification with callback', function(assert) { + var input = ''; + var output = ''; + var done = assert.async(); + assert.notOk(minify( + input, + { + minifyJS: function(js, inline, cb) { + setTimeout(function() { + cb(js + '(function(){ console.log("World"); })()'); + }, 0); + } + }, + function(error, result) { + assert.notOk(error); + assert.equal(result, output); + done(); + } + )); +}); + +QUnit.test('style async minification with script sync minification', function(assert) { + var input = ''; + var output = ''; + var done = assert.async(); + assert.notOk(minify( + input, + { + minifyCSS: function(css, cb) { + setTimeout(function() { + cb(css + ' callback!'); + }, 0); + }, + minifyJS: true + }, + function(error, result) { + assert.notOk(error); + assert.equal(result, output); + done(); + } + )); +}); + +QUnit.test('style sync minification with script async minification', function(assert) { + var input = ''; + var output = ''; + var done = assert.async(); + assert.notOk(minify( + input, + { + minifyCSS: true, + minifyJS: function(js, inline, cb) { + setTimeout(function() { + cb(js + ' callback!'); + }, 0); + } + }, + function(error, result) { + assert.notOk(error); + assert.equal(result, output); + done(); + } + )); +}); + +QUnit.test('style async minification with script async minification', function(assert) { + var input = ''; + var output = ''; + var done = assert.async(); + assert.notOk(minify( + input, + { + minifyCSS: function(css, cb) { + setTimeout(function() { + cb(css + ' callback!'); + }, 0); + }, + minifyJS: function(js, inline, cb) { + setTimeout(function() { + cb(js + ' callback!'); + }, 0); + } + }, + function(error, result) { + assert.notOk(error); + assert.equal(result, output); + done(); + } + )); +}); + + +QUnit.test('async minification along side sync minification', function(assert) { + var input = ''; + var syncOutput = ''; + var asyncOutput = ''; + var done = assert.async(); + + assert.notOk(minify( + input, + { + minifyCSS: function(css, cb) { + setTimeout(function() { + cb(css + ' callback!'); + }, 0); + }, + minifyJS: function(js, inline, cb) { + setTimeout(function() { + cb(js + ' callback!'); + }, 0); + } + }, + function(error, result) { + assert.notOk(error); + assert.equal(result, asyncOutput); + done(); + } + )); + + assert.equal(minify(input, { + minifyCSS: true, + minifyJS: true + }), syncOutput); +}); + +QUnit.test('multiple async minifications', function(assert) { + var input = ''; + var output = ''; + var done = assert.async(2); + + assert.notOk(minify( + input, + { + minifyCSS: function(css, cb) { + setTimeout(function() { + cb(css + ' callback!'); + }, 0); + }, + minifyJS: function(js, inline, cb) { + setTimeout(function() { + cb(js + ' callback!'); + }, 0); + } + }, + function(error, result) { + assert.notOk(error); + assert.equal(result, output); + done(); + } + )); + + assert.notOk(minify( + input, + { + minifyCSS: function(css, cb) { + setTimeout(function() { + cb(css + ' callback!'); + }, 0); + }, + minifyJS: function(js, inline, cb) { + setTimeout(function() { + cb(js + ' callback!'); + }, 0); + } + }, + function(error, result) { + assert.notOk(error); + assert.equal(result, output); + done(); + } + )); +}); + +QUnit.test('sync minify with callback', function(assert) { + var input = 'TestHello World'; + var output = input; + var done = assert.async(); + assert.equal(minify( + input, + {}, + function(error, result) { + assert.notOk(error); + assert.equal(result, output); + done(); + } + ), output); +}); + + +QUnit.test('minify error with callback', function(assert) { + var input = ' Date: Thu, 12 Apr 2018 12:29:02 +1200 Subject: [PATCH 02/66] Added callback parameter to minify. --- src/htmlminifier.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/htmlminifier.js b/src/htmlminifier.js index 7748f1c6..1ab95f8b 100644 --- a/src/htmlminifier.js +++ b/src/htmlminifier.js @@ -803,7 +803,7 @@ function createSortFns(value, options, uidIgnore, uidAttr) { } } -function minify(value, options, partialMarkup) { +function minify(value, options, partialMarkup, cb) { options = options || {}; var optionsStack = []; processOptions(options); @@ -1300,6 +1300,6 @@ function joinResultSegments(results, options) { return options.collapseWhitespace ? collapseWhitespace(str, options, true, true) : str; } -exports.minify = function(value, options) { - return minify(value, options); +exports.minify = function(value, options, cb) { + return minify(value, options, null, cb); }; From b773ab494909342a05c656e4ee789ae1511cb91d Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Thu, 12 Apr 2018 12:30:08 +1200 Subject: [PATCH 03/66] Added callback parameter to minifyCSS and minifyJS. --- src/htmlminifier.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/htmlminifier.js b/src/htmlminifier.js index 1ab95f8b..ea298d5f 100644 --- a/src/htmlminifier.js +++ b/src/htmlminifier.js @@ -867,14 +867,14 @@ function minify(value, options, partialMarkup, cb) { uidPattern = new RegExp('(\\s*)' + uidAttr + '([0-9]+)(\\s*)', 'g'); var minifyCSS = options.minifyCSS; if (minifyCSS) { - options.minifyCSS = function(text) { - return minifyCSS(escapeFragments(text)); + options.minifyCSS = function(text, cb) { + return minifyCSS(escapeFragments(text), cb); }; } var minifyJS = options.minifyJS; if (minifyJS) { - options.minifyJS = function(text, inline) { - return minifyJS(escapeFragments(text), inline); + options.minifyJS = function(text, inline, cb) { + return minifyJS(escapeFragments(text), inline, cb); }; } } From fdf4ca38bb32409dd27f7ff3958fe85c3bc61a6f Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Thu, 12 Apr 2018 14:22:20 +1200 Subject: [PATCH 04/66] Create a placeholder class for async text. --- src/htmlminifier.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/htmlminifier.js b/src/htmlminifier.js index ea298d5f..68d8c39b 100644 --- a/src/htmlminifier.js +++ b/src/htmlminifier.js @@ -803,6 +803,29 @@ function createSortFns(value, options, uidIgnore, uidAttr) { } } +/** + * A placeholder for text that will be set later. + * + * @constructor + */ +function AsyncTextPlaceholder() {} + +/** + * Set the value this placeholder has. + * + * @param {string} value + */ +AsyncTextPlaceholder.prototype.setValue = function(value) { + this.value = value; +}; + +AsyncTextPlaceholder.prototype.toString = function() { + if (this.value) { + return this.value; + } + return '[[Placeholder]]'; +}; + function minify(value, options, partialMarkup, cb) { options = options || {}; var optionsStack = []; From b71cc2fbd278942555199bc1af0479d2a30954a4 Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Thu, 12 Apr 2018 14:24:31 +1200 Subject: [PATCH 05/66] When processing entries in the buffer, make sure they are a string. This allows instances of AsyncTextPlaceholder to be put into the buffer. --- src/htmlminifier.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/htmlminifier.js b/src/htmlminifier.js index 68d8c39b..25890c37 100644 --- a/src/htmlminifier.js +++ b/src/htmlminifier.js @@ -1304,7 +1304,7 @@ function joinResultSegments(results, options) { var lines = []; var line = ''; for (var i = 0, len = results.length; i < len; i++) { - token = results[i]; + token = String(results[i]); if (line.length + token.length < maxLineLength) { line += token; } From d9104aca702107cb47902df4ec1928641c521f45 Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Thu, 12 Apr 2018 14:31:22 +1200 Subject: [PATCH 06/66] The result is only finalize and returned if there are no async tasks running. --- src/htmlminifier.js | 84 ++++++++++++++++++++++++++------------------- 1 file changed, 48 insertions(+), 36 deletions(-) diff --git a/src/htmlminifier.js b/src/htmlminifier.js index 25890c37..fd1e52ad 100644 --- a/src/htmlminifier.js +++ b/src/htmlminifier.js @@ -964,6 +964,7 @@ function minify(value, options, partialMarkup, cb) { trimTrailingWhitespace(charsIndex, nextTag); } + var asyncTasksWaitingFor = 0; new HTMLParser(value, { partialMarkup: partialMarkup, html5: options.html5, @@ -1251,49 +1252,60 @@ function minify(value, options, partialMarkup, cb) { customAttrSurround: options.customAttrSurround }); - if (options.removeOptionalTags) { - // may be omitted if first thing inside is not comment - // or may be omitted if empty - if (topLevelTags(optionalStartTag)) { - removeStartTag(); + function finalize() { + if (options.removeOptionalTags) { + // may be omitted if first thing inside is not comment + // or may be omitted if empty + if (topLevelTags(optionalStartTag)) { + removeStartTag(); + } + // except for or , end tags may be omitted if no more content in parent element + if (optionalEndTag && !trailingTags(optionalEndTag)) { + removeEndTag(); + } } - // except for or , end tags may be omitted if no more content in parent element - if (optionalEndTag && !trailingTags(optionalEndTag)) { - removeEndTag(); + if (options.collapseWhitespace) { + squashTrailingWhitespace('br'); } - } - if (options.collapseWhitespace) { - squashTrailingWhitespace('br'); - } - var str = joinResultSegments(buffer, options); + var str = joinResultSegments(buffer, options); - if (uidPattern) { - str = str.replace(uidPattern, function(match, prefix, index, suffix) { - var chunk = ignoredCustomMarkupChunks[+index][0]; - if (options.collapseWhitespace) { - if (prefix !== '\t') { - chunk = prefix + chunk; - } - if (suffix !== '\t') { - chunk += suffix; + if (uidPattern) { + str = str.replace(uidPattern, function(match, prefix, index, suffix) { + var chunk = ignoredCustomMarkupChunks[+index][0]; + if (options.collapseWhitespace) { + if (prefix !== '\t') { + chunk = prefix + chunk; + } + if (suffix !== '\t') { + chunk += suffix; + } + return collapseWhitespace(chunk, { + preserveLineBreaks: options.preserveLineBreaks, + conservativeCollapse: !options.trimCustomFragments + }, /^[ \n\r\t\f]/.test(chunk), /[ \n\r\t\f]$/.test(chunk)); } - return collapseWhitespace(chunk, { - preserveLineBreaks: options.preserveLineBreaks, - conservativeCollapse: !options.trimCustomFragments - }, /^[ \n\r\t\f]/.test(chunk), /[ \n\r\t\f]$/.test(chunk)); - } - return chunk; - }); - } - if (uidIgnore) { - str = str.replace(new RegExp('', 'g'), function(match, index) { - return ignoredMarkupChunks[+index]; - }); + return chunk; + }); + } + if (uidIgnore) { + str = str.replace(new RegExp('', 'g'), function(match, index) { + return ignoredMarkupChunks[+index]; + }); + } + + options.log('minified in: ' + (Date.now() - t) + 'ms'); + return str; } - options.log('minified in: ' + (Date.now() - t) + 'ms'); - return str; + // No async tasks running? + if (asyncTasksWaitingFor === 0) { + var result = finalize(); + if (typeof cb === 'function') { + cb(null, result); + } + return result; + } } function joinResultSegments(results, options) { From 79e5f8dc2196483e72dbadd0bfc58c64c25ca82f Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Thu, 12 Apr 2018 14:36:33 +1200 Subject: [PATCH 07/66] Set up minifyJS and minifyCSS to be able to complete asynchronously. --- src/htmlminifier.js | 64 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 61 insertions(+), 3 deletions(-) diff --git a/src/htmlminifier.js b/src/htmlminifier.js index fd1e52ad..ba640e09 100644 --- a/src/htmlminifier.js +++ b/src/htmlminifier.js @@ -1184,11 +1184,66 @@ function minify(value, options, partialMarkup, cb) { if (options.processScripts && specialContentTags(currentTag)) { text = processScript(text, options, currentAttrs); } + + var runningAsyncTask = false; + + /** + * To be called when running an async task. + * + * @param {AsyncTextPlaceholder} placeholder + */ + function onAsyncTask(placeholder) { + buffer.push(placeholder); + runningAsyncTask = true; + asyncTasksWaitingFor++; + } + + /** + * Returns the callback function for an async task. + * + * @param {AsyncTextPlaceholder} placeholder + * @returns {Function} + */ + function getAsyncTaskCallback(placeholder) { + return function(result) { + if (!runningAsyncTask) { + throw new Error('Async completion has already occurred.'); + } + runningAsyncTask = false; + placeholder.setValue(result); + if (--asyncTasksWaitingFor === 0) { + if (typeof cb === 'function') { + cb(null, finalize()); + } + } + }; + } + if (isExecutableScript(currentTag, currentAttrs)) { - text = options.minifyJS(text); + var minifyJSPlaceholder = new AsyncTextPlaceholder(); + var minifyJSResult = options.minifyJS(text, null, getAsyncTaskCallback(minifyJSPlaceholder)); + + // Running asynchronously? + if (typeof minifyJSResult === 'undefined') { + onAsyncTask(minifyJSPlaceholder); + } + // Finished synchronously? + else { + text = minifyJSResult; + } } if (isStyleSheet(currentTag, currentAttrs)) { - text = options.minifyCSS(text); + var minifyCSSPlaceholder = new AsyncTextPlaceholder(); + var minifyCSSResult = options.minifyCSS(text, getAsyncTaskCallback(minifyCSSPlaceholder)); + + // Running asynchronously? + if (typeof minifyCSSResult === 'undefined') { + onAsyncTask(minifyCSSPlaceholder); + } + // Finished synchronously? + else { + text = minifyCSSResult; + } } if (options.removeOptionalTags && text) { // may be omitted if first thing inside is not comment @@ -1219,7 +1274,10 @@ function minify(value, options, partialMarkup, cb) { if (text) { hasChars = true; } - buffer.push(text); + // Not running an async task? + if (!runningAsyncTask) { + buffer.push(text); + } }, comment: function(text, nonStandard) { var prefix = nonStandard ? ' Date: Thu, 12 Apr 2018 14:56:34 +1200 Subject: [PATCH 08/66] Added error handling. --- src/htmlminifier.js | 598 +++++++++++++++++++++++--------------------- 1 file changed, 306 insertions(+), 292 deletions(-) diff --git a/src/htmlminifier.js b/src/htmlminifier.js index ba640e09..90abbe78 100644 --- a/src/htmlminifier.js +++ b/src/htmlminifier.js @@ -965,350 +965,357 @@ function minify(value, options, partialMarkup, cb) { } var asyncTasksWaitingFor = 0; - new HTMLParser(value, { - partialMarkup: partialMarkup, - html5: options.html5, - - start: function(tag, attrs, unary, unarySlash, autoGenerated) { - var lowerTag = tag.toLowerCase(); - - if (lowerTag === 'svg') { - optionsStack.push(options); - var nextOptions = {}; - for (var key in options) { - nextOptions[key] = options[key]; - } - nextOptions.keepClosingSlash = true; - nextOptions.caseSensitive = true; - options = nextOptions; - } + var error; - tag = options.caseSensitive ? tag : lowerTag; + try { + new HTMLParser(value, { + partialMarkup: partialMarkup, + html5: options.html5, - currentTag = tag; - charsPrevTag = tag; - if (!inlineTextTags(tag)) { - currentChars = ''; - } - hasChars = false; - currentAttrs = attrs; - - var optional = options.removeOptionalTags; - if (optional) { - var htmlTag = htmlTags(tag); - // may be omitted if first thing inside is not comment - // may be omitted if first thing inside is an element - // may be omitted if first thing inside is not space, comment, , , '; var syncOutput = ''; @@ -3607,7 +3606,6 @@ QUnit.test('sync minify with callback', function(assert) { ), output); }); - QUnit.test('minify error with callback', function(assert) { var input = ' Date: Thu, 12 Apr 2018 15:07:32 +1200 Subject: [PATCH 10/66] "along side" --> "alongside" --- tests/minifier.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/minifier.js b/tests/minifier.js index 085c3ed0..0b5e56c6 100644 --- a/tests/minifier.js +++ b/tests/minifier.js @@ -3510,7 +3510,7 @@ QUnit.test('style async minification with script async minification', function(a )); }); -QUnit.test('async minification along side sync minification', function(assert) { +QUnit.test('async minification alongside sync minification', function(assert) { var input = ''; var syncOutput = ''; var asyncOutput = ''; From ee14967a2bce791d6b4390e6694143eb825705dd Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Thu, 12 Apr 2018 15:08:21 +1200 Subject: [PATCH 11/66] Added extra check to 'minify error with callback' test. --- tests/minifier.js | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/minifier.js b/tests/minifier.js index 0b5e56c6..59567a62 100644 --- a/tests/minifier.js +++ b/tests/minifier.js @@ -3615,6 +3615,7 @@ QUnit.test('minify error with callback', function(assert) { {}, function(error) { assert.ok(error); + assert.equal(error.message, 'Parse Error: Date: Thu, 12 Apr 2018 15:09:53 +1200 Subject: [PATCH 12/66] Added a test to ensure the minifyCSS and miniftJS callbacks can only be called once. --- tests/minifier.js | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/tests/minifier.js b/tests/minifier.js index 59567a62..381ab646 100644 --- a/tests/minifier.js +++ b/tests/minifier.js @@ -3639,3 +3639,50 @@ QUnit.test('error in callback', function(assert) { } ); }); + +QUnit.test('call callback multiple times', function(assert) { + var input = ''; + var output = ''; + var done = assert.async(3); + + minify( + input, + { + minifyCSS: function(css, cb) { + setTimeout(function() { + try { + cb(css + ' callback!'); + cb(css + ' callback!'); + + assert.ok(false, 'An error should be thrown.'); + done(); + } + catch (error) { + assert.equal(error.message, 'Async completion has already occurred.'); + done(); + } + }, 0); + }, + minifyJS: function(js, inline, cb) { + setTimeout(function() { + try { + cb(js + ' callback!'); + cb(js + ' callback!'); + + assert.ok(false, 'An error should be thrown.'); + done(); + } + catch (error) { + assert.equal(error.message, 'Async completion has already occurred.'); + done(); + } + }, 0); + } + }, + function(error, result) { + assert.notOk(error); + assert.equal(result, output); + done(); + } + ); +}); From 390eacb4044416cdfccb854017be53a8e25954dc Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Thu, 12 Apr 2018 17:26:57 +1200 Subject: [PATCH 13/66] Fixed bug with AsyncTextPlaceholder not being able to have the emptyString as its value. --- src/htmlminifier.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/htmlminifier.js b/src/htmlminifier.js index 90abbe78..4c82d624 100644 --- a/src/htmlminifier.js +++ b/src/htmlminifier.js @@ -820,7 +820,7 @@ AsyncTextPlaceholder.prototype.setValue = function(value) { }; AsyncTextPlaceholder.prototype.toString = function() { - if (this.value) { + if (typeof this.value !== 'undefined') { return this.value; } return '[[Placeholder]]'; From e74fcf195fd8b2c59b2fc64841676f377aa46639 Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Thu, 12 Apr 2018 17:31:46 +1200 Subject: [PATCH 14/66] Fixed bug with error not being given to callback after all async tasks have completed. --- src/htmlminifier.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/htmlminifier.js b/src/htmlminifier.js index 4c82d624..e929fa7a 100644 --- a/src/htmlminifier.js +++ b/src/htmlminifier.js @@ -1216,7 +1216,12 @@ function minify(value, options, partialMarkup, cb) { placeholder.setValue(result); if (--asyncTasksWaitingFor === 0) { if (typeof cb === 'function') { - cb(null, finalize()); + if (error) { + cb(error, null); + } + else { + cb(null, finalize()); + } } } }; From d77176a7540b9e4fe4bdec02e94f5e25981e9f04 Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Thu, 12 Apr 2018 17:36:52 +1200 Subject: [PATCH 15/66] Added callback information to the readme. --- README.md | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 60 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b925130e..9fc93921 100644 --- a/README.md +++ b/README.md @@ -58,8 +58,8 @@ Most of the options are disabled by default. | `includeAutoGeneratedTags` | Insert tags generated by HTML parser | `true` | | `keepClosingSlash` | Keep the trailing slash on singleton elements | `false` | | `maxLineLength` | Specify a maximum line length. Compressed output will be split by newlines at valid HTML split-points | -| `minifyCSS` | Minify CSS in style elements and style attributes (uses [clean-css](https://github.com/jakubpawlowicz/clean-css)) | `false` (could be `true`, `Object`, `Function(text)`) | -| `minifyJS` | Minify JavaScript in script elements and event attributes (uses [UglifyJS](https://github.com/mishoo/UglifyJS2)) | `false` (could be `true`, `Object`, `Function(text, inline)`) | +| `minifyCSS` | Minify CSS in style elements and style attributes (uses [clean-css](https://github.com/jakubpawlowicz/clean-css)) | `false` (could be `true`, `Object`, `Function(text[, cb])`) | +| `minifyJS` | Minify JavaScript in script elements and event attributes (uses [UglifyJS](https://github.com/mishoo/UglifyJS2)) | `false` (could be `true`, `Object`, `Function(text, inline[, cb])`) | | `minifyURLs` | Minify URLs in various attributes (uses [relateurl](https://github.com/stevenvachon/relateurl)) | `false` (could be `String`, `Object`, `Function(text)`) | | `preserveLineBreaks` | Always collapse to 1 line break (never remove it entirely) when whitespace between tags include a line break. Must be used in conjunction with `collapseWhitespace=true` | `false` | | `preventAttributesEscaping` | Prevents the escaping of the values of attributes | `false` | @@ -142,6 +142,8 @@ For command line usage please see `html-minifier --help` ### Node.js +#### Synchronous Usage + ```js var minify = require('html-minifier').minify; var result = minify('

foo

', { @@ -150,6 +152,62 @@ var result = minify('

foo

', { result; // '

foo

' ``` +#### Asynchronous Usage + +`minify` can take an optional callback function that will be invoked once the +minification is complete (or an error occurs). + +This allows for the following functions to complete asynchronously: + +* minifyCSS +* minifyJS + +```js +var minify = require('html-minifier').minify; + +minify( + '', + { + minifyCSS: function(css, cb) { + doSomethingAsync(css, function(updatedCss) { + cb(updatedCss); + }); + }, + }, + function(error, result) { + if (error) { + // Handle error. + } else { + // Do something with the result. + } + } +); +``` + +##### Promisify + +`minify` is compatable with NodeJS's [`util.promisify`](https://nodejs.org/dist/latest-v8.x/docs/api/util.html#util_util_promisify_original) +function added in v8.0.0 + +```js +const util = require('util'); +const minify = util.promisify(require('html-minifier').minify); + +minify('', { + minifyCSS: (css, cb) => { + doSomethingAsync(css, updatedCss => { + cb(updatedCss); + }); + } +}) + .then(result => { + // Do something with the result. + }) + .catch(error => { + // Handle error. + }); +``` + ## Running benchmarks Benchmarks for minified HTML: From cdc653bd2ceca57385be6e37bc940c02e02710e5 Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Fri, 13 Apr 2018 00:28:20 +1200 Subject: [PATCH 16/66] Refactored. --- src/htmlminifier.js | 192 ++++++++++++++++++++------------------------ tests/minifier.js | 16 ++-- 2 files changed, 97 insertions(+), 111 deletions(-) diff --git a/src/htmlminifier.js b/src/htmlminifier.js index e929fa7a..65039774 100644 --- a/src/htmlminifier.js +++ b/src/htmlminifier.js @@ -803,29 +803,6 @@ function createSortFns(value, options, uidIgnore, uidAttr) { } } -/** - * A placeholder for text that will be set later. - * - * @constructor - */ -function AsyncTextPlaceholder() {} - -/** - * Set the value this placeholder has. - * - * @param {string} value - */ -AsyncTextPlaceholder.prototype.setValue = function(value) { - this.value = value; -}; - -AsyncTextPlaceholder.prototype.toString = function() { - if (typeof this.value !== 'undefined') { - return this.value; - } - return '[[Placeholder]]'; -}; - function minify(value, options, partialMarkup, cb) { options = options || {}; var optionsStack = []; @@ -851,6 +828,8 @@ function minify(value, options, partialMarkup, cb) { uidAttr, uidPattern; + var asyncExecution = typeof cb === 'function'; + // temporarily replace ignored chunks with comments, // so that we don't have to worry what's there. // for all we care there might be @@ -964,8 +943,9 @@ function minify(value, options, partialMarkup, cb) { trimTrailingWhitespace(charsIndex, nextTag); } - var asyncTasksWaitingFor = 0; - var error; + // Number of tasks waiting to complete (includes current function). + var asyncTasksWaitingFor = 1; + var asyncError; try { new HTMLParser(value, { @@ -1136,6 +1116,7 @@ function minify(value, options, partialMarkup, cb) { chars: function(text, prevTag, nextTag) { prevTag = prevTag === '' ? 'comment' : prevTag; nextTag = nextTag === '' ? 'comment' : nextTag; + var usingAsyncText = false; if (options.decodeEntities && text && !specialContentTags(currentTag)) { text = decode(text); } @@ -1188,36 +1169,24 @@ function minify(value, options, partialMarkup, cb) { text = processScript(text, options, currentAttrs); } - var runningAsyncTask = false; - - /** - * To be called when running an async task. - * - * @param {AsyncTextPlaceholder} placeholder - */ - function onAsyncTask(placeholder) { - buffer.push(placeholder); - runningAsyncTask = true; - asyncTasksWaitingFor++; - } - /** * Returns the callback function for an async task. * - * @param {AsyncTextPlaceholder} placeholder + * @param {number} index - The index in the buffer to insert the updated text into * @returns {Function} */ - function getAsyncTaskCallback(placeholder) { + function getAsyncTaskCallback(index) { + var runningAsyncTask = true; return function(result) { if (!runningAsyncTask) { throw new Error('Async completion has already occurred.'); } runningAsyncTask = false; - placeholder.setValue(result); + buffer[index] = result; if (--asyncTasksWaitingFor === 0) { if (typeof cb === 'function') { - if (error) { - cb(error, null); + if (asyncError) { + cb(asyncError, null); } else { cb(null, finalize()); @@ -1228,62 +1197,72 @@ function minify(value, options, partialMarkup, cb) { } if (isExecutableScript(currentTag, currentAttrs)) { - var minifyJSPlaceholder = new AsyncTextPlaceholder(); - var minifyJSResult = options.minifyJS(text, null, getAsyncTaskCallback(minifyJSPlaceholder)); - - // Running asynchronously? - if (typeof minifyJSResult === 'undefined') { - onAsyncTask(minifyJSPlaceholder); + if (asyncExecution) { + asyncTasksWaitingFor++; + usingAsyncText = true; + var minifyJS_cb = getAsyncTaskCallback(buffer.length); + var minifyJS_result = options.minifyJS(text, null, minifyJS_cb); + + // Finished synchronously? + if (typeof minifyJS_result !== 'undefined') { + // Call the callback manually. + minifyJS_cb(minifyJS_result); + } } - // Finished synchronously? else { - text = minifyJSResult; + text = options.minifyJS(text); } } if (isStyleSheet(currentTag, currentAttrs)) { - var minifyCSSPlaceholder = new AsyncTextPlaceholder(); - var minifyCSSResult = options.minifyCSS(text, getAsyncTaskCallback(minifyCSSPlaceholder)); - - // Running asynchronously? - if (typeof minifyCSSResult === 'undefined') { - onAsyncTask(minifyCSSPlaceholder); + if (asyncExecution) { + asyncTasksWaitingFor++; + usingAsyncText = true; + var minifyCSS_cb = getAsyncTaskCallback(buffer.length); + var minifyCSS_result = options.minifyCSS(text, minifyCSS_cb); + + // Finished synchronously? + if (typeof minifyCSS_result !== 'undefined') { + // Call the callback manually. + minifyCSS_cb(minifyCSS_result); + } } - // Finished synchronously? else { - text = minifyCSSResult; + text = options.minifyCSS(text); } } - if (options.removeOptionalTags && text) { - // may be omitted if first thing inside is not comment - // may be omitted if first thing inside is not space, comment, , , '; var done = assert.async(3); - minify( + assert.notOk(minify( input, { minifyCSS: function(css, cb) { @@ -3684,5 +3684,5 @@ QUnit.test('call callback multiple times', function(assert) { assert.equal(result, output); done(); } - ); + )); }); From 28c1ac3a3aeff7ef3375679ddb9dd6b9bebfcad9 Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Fri, 13 Apr 2018 17:35:07 +1200 Subject: [PATCH 17/66] Refactored - Async tasks now do not start until after all sync code has finished. --- src/htmlminifier.js | 271 ++++++++++++++++++++++++++++---------------- 1 file changed, 173 insertions(+), 98 deletions(-) diff --git a/src/htmlminifier.js b/src/htmlminifier.js index 65039774..9b15bac7 100644 --- a/src/htmlminifier.js +++ b/src/htmlminifier.js @@ -828,8 +828,111 @@ function minify(value, options, partialMarkup, cb) { uidAttr, uidPattern; + /** + * Running using async exectution? + * + * @type {boolean} + */ var asyncExecution = typeof cb === 'function'; + /** + * Set of tasks to perform asynchronously. + * + * @type {AsyncTask[]} + */ + var asyncTasks = []; + + /** + * The number of async tasks that have completed. + * + * @type {number} + */ + var asyncTasksComplete = 0; + + /** + * A task that will be executed asynchronously after all the synchronous + * code has executed. + * + * @constructor + * + * @param {AsyncSubtask[]} tasks + * @param {string} content + * @param {Function} cb + */ + function AsyncTask(tasks, content, cb) { + this.tasks = tasks; + this.content = content; + this.cb = cb; + } + + /** + * Run the subtasks at the given index, giving it a callback to run the next + * subtask the same way. This therefore asynchronously runs all subtasks from + * the given index in series. + * + * @private + * @param {string} content + * @param {number} index + */ + AsyncTask.prototype.runSubtask = function(content, index) { + if (index < this.tasks.length) { + try { + this.tasks[index].exec( + content, + function(result) { + if (this.tasks[index].cbExecuted) { + throw new Error('Async completion has already occurred.'); + } + this.tasks[index].cbExecuted = true; + + this.runSubtask(result, index + 1); + }.bind(this) + ); + } + catch (error) { + cb(error); + } + } + else { + this.cb(content); + if (++asyncTasksComplete === asyncTasks.length) { + cb(null, finalize()); + } + } + }; + + /** + * Execute this task. + */ + AsyncTask.prototype.exec = function() { + // Recursively run all subtasks. + this.runSubtask(this.content, 0); + }; + + /** + * A subtask in an AsyncTask. + * + * @constructor + * + * @param {Function>} task + */ + function AsyncSubtask(task) { + this.task = task; + } + + /** + * Execute this subtask. + */ + AsyncSubtask.prototype.exec = function(content, cb) { + var result = this.task(content, cb); + + // Finished synchronously? + if (typeof result !== 'undefined') { + // Call the callback manually. + cb(result); + } + }; + // temporarily replace ignored chunks with comments, // so that we don't have to worry what's there. // for all we care there might be @@ -943,10 +1046,6 @@ function minify(value, options, partialMarkup, cb) { trimTrailingWhitespace(charsIndex, nextTag); } - // Number of tasks waiting to complete (includes current function). - var asyncTasksWaitingFor = 1; - var asyncError; - try { new HTMLParser(value, { partialMarkup: partialMarkup, @@ -1116,7 +1215,7 @@ function minify(value, options, partialMarkup, cb) { chars: function(text, prevTag, nextTag) { prevTag = prevTag === '' ? 'comment' : prevTag; nextTag = nextTag === '' ? 'comment' : nextTag; - var usingAsyncText = false; + var asyncSubtasks = []; if (options.decodeEntities && text && !specialContentTags(currentTag)) { text = decode(text); } @@ -1169,45 +1268,12 @@ function minify(value, options, partialMarkup, cb) { text = processScript(text, options, currentAttrs); } - /** - * Returns the callback function for an async task. - * - * @param {number} index - The index in the buffer to insert the updated text into - * @returns {Function} - */ - function getAsyncTaskCallback(index) { - var runningAsyncTask = true; - return function(result) { - if (!runningAsyncTask) { - throw new Error('Async completion has already occurred.'); - } - runningAsyncTask = false; - buffer[index] = result; - if (--asyncTasksWaitingFor === 0) { - if (typeof cb === 'function') { - if (asyncError) { - cb(asyncError, null); - } - else { - cb(null, finalize()); - } - } - } - }; - } - if (isExecutableScript(currentTag, currentAttrs)) { if (asyncExecution) { - asyncTasksWaitingFor++; - usingAsyncText = true; - var minifyJS_cb = getAsyncTaskCallback(buffer.length); - var minifyJS_result = options.minifyJS(text, null, minifyJS_cb); - - // Finished synchronously? - if (typeof minifyJS_result !== 'undefined') { - // Call the callback manually. - minifyJS_cb(minifyJS_result); - } + // Run minifyJS asynchronously after all synchronous code has finished. + asyncSubtasks.push(new AsyncSubtask(function(content, cb) { + return options.minifyJS(content, null, cb); + })); } else { text = options.minifyJS(text); @@ -1215,56 +1281,64 @@ function minify(value, options, partialMarkup, cb) { } if (isStyleSheet(currentTag, currentAttrs)) { if (asyncExecution) { - asyncTasksWaitingFor++; - usingAsyncText = true; - var minifyCSS_cb = getAsyncTaskCallback(buffer.length); - var minifyCSS_result = options.minifyCSS(text, minifyCSS_cb); - - // Finished synchronously? - if (typeof minifyCSS_result !== 'undefined') { - // Call the callback manually. - minifyCSS_cb(minifyCSS_result); - } + // Run minifyCSS asynchronously after all synchronous code has finished. + asyncSubtasks.push(new AsyncSubtask(function(content, cb) { + return options.minifyCSS(content, cb); + })); } else { text = options.minifyCSS(text); } } - if (usingAsyncText) { - buffer.push(null); - } - else { - if (options.removeOptionalTags && text) { - // may be omitted if first thing inside is not comment - // may be omitted if first thing inside is not space, comment, , , '), ''); - assert.equal(minify(''), ''); - assert.equal(minify(''), ''); + test_minify(assert, '', ''); + test_minify(assert, '', ''); + test_minify(assert, '', ''); - assert.equal(minify('foo'), 'foo'); - assert.equal(minify('

x'), '

x

'); - assert.equal(minify('

x

'), '

x

', 'trailing quote should be ignored'); - assert.equal(minify('

Click me

'), '

Click me

'); - assert.equal(minify(''), ''); - assert.equal(minify('
[fallback image]
'), + test_minify(assert, 'foo', 'foo'); + test_minify(assert, '

x', '

x

'); + test_minify(assert, '

x

', '

x

', 'trailing quote should be ignored'); + test_minify(assert, '

Click me

', '

Click me

'); + test_minify(assert, '', ''); + test_minify(assert, '
[fallback image]
', '
[fallback image]
' ); - assert.equal(minify(''), ''); - assert.equal(minify(''), ''); - assert.equal(minify('
'), + test_minify(assert, '', ''); + test_minify(assert, '', ''); + test_minify(assert, '
', '
' ); // will cause test to time-out if fail input = '

For more information, read this Stack Overflow answer.

'; output = '

For more information, read this Stack Overflow answer.

'; - assert.equal(minify(input), output); + test_minify(assert, input, output); input = ''; - assert.equal(minify(input), input); + test_minify(assert, input, input); input = ''; - assert.equal(minify(input), input); + test_minify(assert, input, input); input = '<$unicorn>'; assert.throws(function() { @@ -66,33 +118,33 @@ QUnit.test('parsing non-trivial markup', function(assert) { }, 'Invalid tag name'); input = ''; - assert.equal(minify(input), input); + test_minify(assert, input, input); // https://github.com/kangax/html-minifier/issues/41 - assert.equal(minify(''), + test_minify(assert, '', '' ); // https://github.com/kangax/html-minifier/issues/40 - assert.equal(minify('[\']["]'), '[\']["]'); + test_minify(assert, '[\']["]', '[\']["]'); // https://github.com/kangax/html-minifier/issues/21 - assert.equal(minify('
hey
'), '
hey
'); + test_minify(assert, '
hey
', '
hey
'); // https://github.com/kangax/html-minifier/issues/17 - assert.equal(minify(':) link'), ':) link'); + test_minify(assert, ':) link', ':) link'); // https://github.com/kangax/html-minifier/issues/169 - assert.equal(minify('ok'), 'ok'); + test_minify(assert, 'ok', 'ok'); - assert.equal(minify(''), ''); + test_minify(assert, '', ''); // https://github.com/kangax/html-minifier/issues/229 - assert.equal(minify('
Hello :)
'), '
Hello :)
'); + test_minify(assert, '
Hello :)
', '
Hello :)
'); // https://github.com/kangax/html-minifier/issues/507 input = ''; - assert.equal(minify(input), input); + test_minify(assert, input, input); assert.throws(function() { minify(''); }, 'invalid attribute name'); @@ -105,7 +157,7 @@ QUnit.test('parsing non-trivial markup', function(assert) { ' data-ng-model-options="{ debounce: 1000 }"' + ' data-ng-pattern="vm.options.format"' + ' data-options="vm.datepickerOptions">'; - assert.equal(minify(input), input); + test_minify(assert, input, input); assert.throws(function() { minify( 'foo

'), '

foo

'); - assert.equal(minify('
boo
'), '
boo
'); - assert.equal(minify('
boo
'), '
boo
'); - assert.equal(minify('
boo
'), '
boo
'); - assert.equal(minify('
boo
'), '
boo
'); - assert.equal(minify('
boo
'), '
boo
'); + test_minify(assert, '

foo

', '

foo

'); + test_minify(assert, '
boo
', '
boo
'); + test_minify(assert, '
boo
', '
boo
'); + test_minify(assert, '
boo
', '
boo
'); + test_minify(assert, '
boo
', '
boo
'); + test_minify(assert, '
boo
', '
boo
'); }); QUnit.test('space normalization between attributes', function(assert) { - assert.equal(minify('

foo

'), '

foo

'); - assert.equal(minify(''), ''); - assert.equal(minify('

foo

'), '

foo

'); - assert.equal(minify('

foo

'), '

foo

'); - assert.equal(minify(''), ''); - assert.equal(minify(''), ''); + test_minify(assert, '

foo

', '

foo

'); + test_minify(assert, '', ''); + test_minify(assert, '

foo

', '

foo

'); + test_minify(assert, '

foo

', '

foo

'); + test_minify(assert, '', ''); + test_minify(assert, '', ''); }); QUnit.test('space normalization around text', function(assert) { var input, output; input = '

blah

\n\n\n '; - assert.equal(minify(input), input); + test_minify(assert, input, input); output = '

blah

'; - assert.equal(minify(input, { collapseWhitespace: true }), output); + test_minify(assert, input, { collapseWhitespace: true }, output); output = '

blah

'; - assert.equal(minify(input, { + test_minify(assert, input, { collapseWhitespace: true, conservativeCollapse: true - }), output); + }, output); output = '

blah

\n'; - assert.equal(minify(input, { + test_minify(assert, input, { collapseWhitespace: true, preserveLineBreaks: true - }), output); + }, output); output = '

blah

\n'; - assert.equal(minify(input, { + test_minify(assert, input, { collapseWhitespace: true, conservativeCollapse: true, preserveLineBreaks: true - }), output); + }, output); [ 'a', 'abbr', 'acronym', 'b', 'big', 'del', 'em', 'font', 'i', 'ins', 'kbd', 'mark', 's', 'samp', 'small', 'span', 'strike', 'strong', 'sub', 'sup', 'time', 'tt', 'u', 'var' ].forEach(function(el) { - assert.equal(minify('foo <' + el + '>baz bar', { collapseWhitespace: true }), 'foo <' + el + '>baz bar'); - assert.equal(minify('foo<' + el + '>bazbar', { collapseWhitespace: true }), 'foo<' + el + '>bazbar'); - assert.equal(minify('foo <' + el + '>bazbar', { collapseWhitespace: true }), 'foo <' + el + '>bazbar'); - assert.equal(minify('foo<' + el + '>baz bar', { collapseWhitespace: true }), 'foo<' + el + '>baz bar'); - assert.equal(minify('foo <' + el + '> baz bar', { collapseWhitespace: true }), 'foo <' + el + '>baz bar'); - assert.equal(minify('foo<' + el + '> baz bar', { collapseWhitespace: true }), 'foo<' + el + '> baz bar'); - assert.equal(minify('foo <' + el + '> baz bar', { collapseWhitespace: true }), 'foo <' + el + '>baz bar'); - assert.equal(minify('foo<' + el + '> baz bar', { collapseWhitespace: true }), 'foo<' + el + '> baz bar'); - assert.equal(minify('
foo <' + el + '>baz bar
', { collapseWhitespace: true }), '
foo <' + el + '>baz bar
'); - assert.equal(minify('
foo<' + el + '>bazbar
', { collapseWhitespace: true }), '
foo<' + el + '>bazbar
'); - assert.equal(minify('
foo <' + el + '>bazbar
', { collapseWhitespace: true }), '
foo <' + el + '>bazbar
'); - assert.equal(minify('
foo<' + el + '>baz bar
', { collapseWhitespace: true }), '
foo<' + el + '>baz bar
'); - assert.equal(minify('
foo <' + el + '> baz bar
', { collapseWhitespace: true }), '
foo <' + el + '>baz bar
'); - assert.equal(minify('
foo<' + el + '> baz bar
', { collapseWhitespace: true }), '
foo<' + el + '> baz bar
'); - assert.equal(minify('
foo <' + el + '> baz bar
', { collapseWhitespace: true }), '
foo <' + el + '>baz bar
'); - assert.equal(minify('
foo<' + el + '> baz bar
', { collapseWhitespace: true }), '
foo<' + el + '> baz bar
'); + test_minify(assert, 'foo <' + el + '>baz bar', { collapseWhitespace: true }, 'foo <' + el + '>baz bar'); + test_minify(assert, 'foo<' + el + '>bazbar', { collapseWhitespace: true }, 'foo<' + el + '>bazbar'); + test_minify(assert, 'foo <' + el + '>bazbar', { collapseWhitespace: true }, 'foo <' + el + '>bazbar'); + test_minify(assert, 'foo<' + el + '>baz bar', { collapseWhitespace: true }, 'foo<' + el + '>baz bar'); + test_minify(assert, 'foo <' + el + '> baz bar', { collapseWhitespace: true }, 'foo <' + el + '>baz bar'); + test_minify(assert, 'foo<' + el + '> baz bar', { collapseWhitespace: true }, 'foo<' + el + '> baz bar'); + test_minify(assert, 'foo <' + el + '> baz bar', { collapseWhitespace: true }, 'foo <' + el + '>baz bar'); + test_minify(assert, 'foo<' + el + '> baz bar', { collapseWhitespace: true }, 'foo<' + el + '> baz bar'); + test_minify(assert, '
foo <' + el + '>baz bar
', { collapseWhitespace: true }, '
foo <' + el + '>baz bar
'); + test_minify(assert, '
foo<' + el + '>bazbar
', { collapseWhitespace: true }, '
foo<' + el + '>bazbar
'); + test_minify(assert, '
foo <' + el + '>bazbar
', { collapseWhitespace: true }, '
foo <' + el + '>bazbar
'); + test_minify(assert, '
foo<' + el + '>baz bar
', { collapseWhitespace: true }, '
foo<' + el + '>baz bar
'); + test_minify(assert, '
foo <' + el + '> baz bar
', { collapseWhitespace: true }, '
foo <' + el + '>baz bar
'); + test_minify(assert, '
foo<' + el + '> baz bar
', { collapseWhitespace: true }, '
foo<' + el + '> baz bar
'); + test_minify(assert, '
foo <' + el + '> baz bar
', { collapseWhitespace: true }, '
foo <' + el + '>baz bar
'); + test_minify(assert, '
foo<' + el + '> baz bar
', { collapseWhitespace: true }, '
foo<' + el + '> baz bar
'); }); // Don't trim whitespace around element, but do trim within [ 'bdi', 'bdo', 'button', 'cite', 'code', 'dfn', 'math', 'q', 'rt', 'rtc', 'ruby', 'svg' ].forEach(function(el) { - assert.equal(minify('foo <' + el + '>baz bar', { collapseWhitespace: true }), 'foo <' + el + '>baz bar'); - assert.equal(minify('foo<' + el + '>bazbar', { collapseWhitespace: true }), 'foo<' + el + '>bazbar'); - assert.equal(minify('foo <' + el + '>bazbar', { collapseWhitespace: true }), 'foo <' + el + '>bazbar'); - assert.equal(minify('foo<' + el + '>baz bar', { collapseWhitespace: true }), 'foo<' + el + '>baz bar'); - assert.equal(minify('foo <' + el + '> baz bar', { collapseWhitespace: true }), 'foo <' + el + '>baz bar'); - assert.equal(minify('foo<' + el + '> baz bar', { collapseWhitespace: true }), 'foo<' + el + '>bazbar'); - assert.equal(minify('foo <' + el + '> baz bar', { collapseWhitespace: true }), 'foo <' + el + '>bazbar'); - assert.equal(minify('foo<' + el + '> baz bar', { collapseWhitespace: true }), 'foo<' + el + '>baz bar'); - assert.equal(minify('
foo <' + el + '>baz bar
', { collapseWhitespace: true }), '
foo <' + el + '>baz bar
'); - assert.equal(minify('
foo<' + el + '>bazbar
', { collapseWhitespace: true }), '
foo<' + el + '>bazbar
'); - assert.equal(minify('
foo <' + el + '>bazbar
', { collapseWhitespace: true }), '
foo <' + el + '>bazbar
'); - assert.equal(minify('
foo<' + el + '>baz bar
', { collapseWhitespace: true }), '
foo<' + el + '>baz bar
'); - assert.equal(minify('
foo <' + el + '> baz bar
', { collapseWhitespace: true }), '
foo <' + el + '>baz bar
'); - assert.equal(minify('
foo<' + el + '> baz bar
', { collapseWhitespace: true }), '
foo<' + el + '>bazbar
'); - assert.equal(minify('
foo <' + el + '> baz bar
', { collapseWhitespace: true }), '
foo <' + el + '>bazbar
'); - assert.equal(minify('
foo<' + el + '> baz bar
', { collapseWhitespace: true }), '
foo<' + el + '>baz bar
'); + test_minify(assert, 'foo <' + el + '>baz bar', { collapseWhitespace: true }, 'foo <' + el + '>baz bar'); + test_minify(assert, 'foo<' + el + '>bazbar', { collapseWhitespace: true }, 'foo<' + el + '>bazbar'); + test_minify(assert, 'foo <' + el + '>bazbar', { collapseWhitespace: true }, 'foo <' + el + '>bazbar'); + test_minify(assert, 'foo<' + el + '>baz bar', { collapseWhitespace: true }, 'foo<' + el + '>baz bar'); + test_minify(assert, 'foo <' + el + '> baz bar', { collapseWhitespace: true }, 'foo <' + el + '>baz bar'); + test_minify(assert, 'foo<' + el + '> baz bar', { collapseWhitespace: true }, 'foo<' + el + '>bazbar'); + test_minify(assert, 'foo <' + el + '> baz bar', { collapseWhitespace: true }, 'foo <' + el + '>bazbar'); + test_minify(assert, 'foo<' + el + '> baz bar', { collapseWhitespace: true }, 'foo<' + el + '>baz bar'); + test_minify(assert, '
foo <' + el + '>baz bar
', { collapseWhitespace: true }, '
foo <' + el + '>baz bar
'); + test_minify(assert, '
foo<' + el + '>bazbar
', { collapseWhitespace: true }, '
foo<' + el + '>bazbar
'); + test_minify(assert, '
foo <' + el + '>bazbar
', { collapseWhitespace: true }, '
foo <' + el + '>bazbar
'); + test_minify(assert, '
foo<' + el + '>baz bar
', { collapseWhitespace: true }, '
foo<' + el + '>baz bar
'); + test_minify(assert, '
foo <' + el + '> baz bar
', { collapseWhitespace: true }, '
foo <' + el + '>baz bar
'); + test_minify(assert, '
foo<' + el + '> baz bar
', { collapseWhitespace: true }, '
foo<' + el + '>bazbar
'); + test_minify(assert, '
foo <' + el + '> baz bar
', { collapseWhitespace: true }, '
foo <' + el + '>bazbar
'); + test_minify(assert, '
foo<' + el + '> baz bar
', { collapseWhitespace: true }, '
foo<' + el + '>baz bar
'); }); [ [' foo ', 'foo'], @@ -252,39 +304,39 @@ QUnit.test('space normalization around text', function(assert) { ['a b c', 'a b c'], ['a b c', 'a b c'] ].forEach(function(inputs) { - assert.equal(minify(inputs[0], { + test_minify(assert, inputs[0], { collapseWhitespace: true, conservativeCollapse: true - }), inputs[0], inputs[0]); - assert.equal(minify(inputs[0], { collapseWhitespace: true }), inputs[1], inputs[0]); + }, inputs[0], inputs[0]); + test_minify(assert, inputs[0], { collapseWhitespace: true }, inputs[1], inputs[0]); var input = '
' + inputs[0] + '
'; - assert.equal(minify(input, { + test_minify(assert, input, { collapseWhitespace: true, conservativeCollapse: true - }), input, input); + }, input, input); var output = '
' + inputs[1] + '
'; - assert.equal(minify(input, { collapseWhitespace: true }), output, input); + test_minify(assert, input, { collapseWhitespace: true }, output, input); }); - assert.equal(minify('

foo bar

', { collapseWhitespace: true }), '

foo bar

'); - assert.equal(minify('

foobar

', { collapseWhitespace: true }), '

foobar

'); - assert.equal(minify('

foo bar

', { collapseWhitespace: true }), '

foo bar

'); - assert.equal(minify('

foo bar

', { collapseWhitespace: true }), '

foo bar

'); - assert.equal(minify('

foo bar

', { collapseWhitespace: true }), '

foo bar

'); - assert.equal(minify('

foobar

', { collapseWhitespace: true }), '

foobar

'); - assert.equal(minify('

foo bar

', { collapseWhitespace: true }), '

foo bar

'); - assert.equal(minify('

foo bar

', { collapseWhitespace: true }), '

foo bar

'); - assert.equal(minify('

foo bar

', { collapseWhitespace: true }), '

foo bar

'); - assert.equal(minify('

foobar

', { collapseWhitespace: true }), '

foobar

'); - assert.equal(minify('

foo bar

', { collapseWhitespace: true }), '

foo bar

'); - assert.equal(minify('

foo bar

', { collapseWhitespace: true }), '

foo bar

'); - assert.equal(minify('

foo bar

', { collapseWhitespace: true }), '

foo bar

'); - assert.equal(minify('

foo bar

', { collapseWhitespace: true }), '

foo bar

'); - assert.equal(minify('

foo bar

', { collapseWhitespace: true }), '

foo bar

'); - assert.equal(minify('
Empty not
', { collapseWhitespace: true }), '
Empty not
'); - assert.equal(minify('
a c
', { + test_minify(assert, '

foo bar

', { collapseWhitespace: true }, '

foo bar

'); + test_minify(assert, '

foobar

', { collapseWhitespace: true }, '

foobar

'); + test_minify(assert, '

foo bar

', { collapseWhitespace: true }, '

foo bar

'); + test_minify(assert, '

foo bar

', { collapseWhitespace: true }, '

foo bar

'); + test_minify(assert, '

foo bar

', { collapseWhitespace: true }, '

foo bar

'); + test_minify(assert, '

foobar

', { collapseWhitespace: true }, '

foobar

'); + test_minify(assert, '

foo bar

', { collapseWhitespace: true }, '

foo bar

'); + test_minify(assert, '

foo bar

', { collapseWhitespace: true }, '

foo bar

'); + test_minify(assert, '

foo bar

', { collapseWhitespace: true }, '

foo bar

'); + test_minify(assert, '

foobar

', { collapseWhitespace: true }, '

foobar

'); + test_minify(assert, '

foo bar

', { collapseWhitespace: true }, '

foo bar

'); + test_minify(assert, '

foo bar

', { collapseWhitespace: true }, '

foo bar

'); + test_minify(assert, '

foo bar

', { collapseWhitespace: true }, '

foo bar

'); + test_minify(assert, '

foo bar

', { collapseWhitespace: true }, '

foo bar

'); + test_minify(assert, '

foo bar

', { collapseWhitespace: true }, '

foo bar

'); + test_minify(assert, '
Empty not
', { collapseWhitespace: true }, '
Empty not
'); + test_minify(assert, '
a c
', { collapseWhitespace: true, removeComments: true - }), '
a c
'); + }, '
a c
'); [ ' a c ', ' a c ', @@ -296,64 +348,64 @@ QUnit.test('space normalization around text', function(assert) { ' a c ', ' a c ' ].forEach(function(input) { - assert.equal(minify(input, { + test_minify(assert, input, { collapseWhitespace: true, conservativeCollapse: true - }), input, input); - assert.equal(minify(input, { + }, input, input); + test_minify(assert, input, { collapseWhitespace: true, removeComments: true - }), 'a c', input); - assert.equal(minify(input, { + }, 'a c', input); + test_minify(assert, input, { collapseWhitespace: true, conservativeCollapse: true, removeComments: true - }), ' a c ', input); + }, ' a c ', input); input = '

' + input + '

'; - assert.equal(minify(input, { + test_minify(assert, input, { collapseWhitespace: true, conservativeCollapse: true - }), input, input); - assert.equal(minify(input, { + }, input, input); + test_minify(assert, input, { collapseWhitespace: true, removeComments: true - }), '

a c

', input); - assert.equal(minify(input, { + }, '

a c

', input); + test_minify(assert, input, { collapseWhitespace: true, conservativeCollapse: true, removeComments: true - }), '

a c

', input); + }, '

a c

', input); }); input = '
  • foo
  • '; output = '
  • foo
  • '; - assert.equal(minify(input, { collapseWhitespace: true }), output); + test_minify(assert, input, { collapseWhitespace: true }, output); input = '
  • foo
  • '; - assert.equal(minify(input, { collapseWhitespace: true }), output); + test_minify(assert, input, { collapseWhitespace: true }, output); input = '
  • foo
  • '; - assert.equal(minify(input, { collapseWhitespace: true }), output); + test_minify(assert, input, { collapseWhitespace: true }, output); input = '
  • foo
  • '; - assert.equal(minify(input, { collapseWhitespace: true }), output); + test_minify(assert, input, { collapseWhitespace: true }, output); input = '
  • foo
  • '; - assert.equal(minify(input, { collapseWhitespace: true }), output); + test_minify(assert, input, { collapseWhitespace: true }, output); input = ''; output = ''; - assert.equal(minify(input, { collapseWhitespace: true }), output); + test_minify(assert, input, { collapseWhitespace: true }, output); input = ' '; output = ''; - assert.equal(minify(input, { collapseWhitespace: true }), output); + test_minify(assert, input, { collapseWhitespace: true }, output); input = ' '; output = ''; - assert.equal(minify(input, { collapseWhitespace: true }), output); + test_minify(assert, input, { collapseWhitespace: true }, output); input = '

    foo\u00A0bar\nbaz \u00A0\nmoo\t

    '; output = '

    foo\u00A0bar baz \u00A0 moo

    '; - assert.equal(minify(input, { collapseWhitespace: true }), output); + test_minify(assert, input, { collapseWhitespace: true }, output); input = '\n' + '\n' + ' bar \n' + '\n' + '\n'; output = ' bar '; - assert.equal(minify(input, { collapseWhitespace: true }), output); + test_minify(assert, input, { collapseWhitespace: true }, output); input = '
    \n' +
               'foo\n' +
               '
    \n' + @@ -361,130 +413,130 @@ QUnit.test('space normalization around text', function(assert) { '
    \n' + 'baz\n'; output = '
    \nfoo\n
    \nbar\n
    baz'; - assert.equal(minify(input, { collapseWhitespace: true }), output); + test_minify(assert, input, { collapseWhitespace: true }, output); }); QUnit.test('types of whitespace that should always be preserved', function(assert) { // Hair space: var input = '
    \u200afo\u200ao\u200a
    '; - assert.equal(minify(input, { collapseWhitespace: true }), input); + test_minify(assert, input, { collapseWhitespace: true }, input); // Hair space passed as HTML entity: var inputWithEntities = '
     fo o 
    '; - assert.equal(minify(inputWithEntities, { collapseWhitespace: true }), inputWithEntities); + test_minify(assert, inputWithEntities, { collapseWhitespace: true }, inputWithEntities); // Hair space passed as HTML entity, in decodeEntities:true mode: - assert.equal(minify(inputWithEntities, { collapseWhitespace: true, decodeEntities: true }), input); + test_minify(assert, inputWithEntities, { collapseWhitespace: true, decodeEntities: true }, input); // Non-breaking space: input = '
    \xa0fo\xa0o\xa0
    '; - assert.equal(minify(input, { collapseWhitespace: true }), input); + test_minify(assert, input, { collapseWhitespace: true }, input); // Non-breaking space passed as HTML entity: inputWithEntities = '
     fo o 
    '; - assert.equal(minify(inputWithEntities, { collapseWhitespace: true }), inputWithEntities); + test_minify(assert, inputWithEntities, { collapseWhitespace: true }, inputWithEntities); // Non-breaking space passed as HTML entity, in decodeEntities:true mode: - assert.equal(minify(inputWithEntities, { collapseWhitespace: true, decodeEntities: true }), input); + test_minify(assert, inputWithEntities, { collapseWhitespace: true, decodeEntities: true }, input); // Do not remove hair space when preserving line breaks between tags: input = '

    \u200a\n

    \n'; - assert.equal(minify(input, { collapseWhitespace: true, preserveLineBreaks: true }), input); + test_minify(assert, input, { collapseWhitespace: true, preserveLineBreaks: true }, input); // Preserve hair space in attributes: input = '

    '; - assert.equal(minify(input, { collapseWhitespace: true }), input); + test_minify(assert, input, { collapseWhitespace: true }, input); // Preserve hair space in class names when deduplicating and reordering: input = ''; - assert.equal(minify(input, { sortClassName: false }), input); - assert.equal(minify(input, { sortClassName: true }), input); + test_minify(assert, input, { sortClassName: false }, input); + test_minify(assert, input, { sortClassName: true }, input); }); QUnit.test('doctype normalization', function(assert) { var input; input = ''; - assert.equal(minify(input, { useShortDoctype: true }), ''); + test_minify(assert, input, { useShortDoctype: true }, ''); input = ''; - assert.equal(minify(input, { useShortDoctype: true }), input); + test_minify(assert, input, { useShortDoctype: true }, input); input = ''; - assert.equal(minify(input, { useShortDoctype: false }), input); + test_minify(assert, input, { useShortDoctype: false }, input); }); QUnit.test('removing comments', function(assert) { var input; input = ''; - assert.equal(minify(input, { removeComments: true }), ''); + test_minify(assert, input, { removeComments: true }, ''); input = '
    baz
    '; - assert.equal(minify(input, { removeComments: true }), '
    baz
    '); - assert.equal(minify(input, { removeComments: false }), input); + test_minify(assert, input, { removeComments: true }, '
    baz
    '); + test_minify(assert, input, { removeComments: false }, input); input = '

    foo

    '; - assert.equal(minify(input, { removeComments: true }), input); + test_minify(assert, input, { removeComments: true }, input); input = ''; - assert.equal(minify(input, { removeComments: true }), input); + test_minify(assert, input, { removeComments: true }, input); input = ''; - assert.equal(minify(input, { removeComments: true }), ''); + test_minify(assert, input, { removeComments: true }, ''); }); QUnit.test('ignoring comments', function(assert) { var input, output; input = ''; - assert.equal(minify(input, { removeComments: true }), input); - assert.equal(minify(input, { removeComments: false }), input); + test_minify(assert, input, { removeComments: true }, input); + test_minify(assert, input, { removeComments: false }, input); input = '
    baz
    '; - assert.equal(minify(input, { removeComments: true }), input); - assert.equal(minify(input, { removeComments: false }), input); + test_minify(assert, input, { removeComments: true }, input); + test_minify(assert, input, { removeComments: false }, input); input = '
    baz
    '; - assert.equal(minify(input, { removeComments: true }), '
    baz
    '); - assert.equal(minify(input, { removeComments: false }), input); + test_minify(assert, input, { removeComments: true }, '
    baz
    '); + test_minify(assert, input, { removeComments: false }, input); input = ''; - assert.equal(minify(input, { removeComments: true }), ''); - assert.equal(minify(input, { removeComments: false }), input); + test_minify(assert, input, { removeComments: true }, ''); + test_minify(assert, input, { removeComments: false }, input); input = '
    \n\n \t
    \n\n

    \n\n \n\n

    \n\n
    '; output = '

    '; - assert.equal(minify(input, { removeComments: true }), input); - assert.equal(minify(input, { removeComments: true, collapseWhitespace: true }), output); - assert.equal(minify(input, { removeComments: false }), input); - assert.equal(minify(input, { removeComments: false, collapseWhitespace: true }), output); + test_minify(assert, input, { removeComments: true }, input); + test_minify(assert, input, { removeComments: true, collapseWhitespace: true }, output); + test_minify(assert, input, { removeComments: false }, input); + test_minify(assert, input, { removeComments: false, collapseWhitespace: true }, output); input = '

    foo

    '; - assert.equal(minify(input, { removeComments: true }), input); + test_minify(assert, input, { removeComments: true }, input); }); QUnit.test('conditional comments', function(assert) { var input, output; input = 'test'; - assert.equal(minify(input, { removeComments: true }), input); + test_minify(assert, input, { removeComments: true }, input); input = ''; - assert.equal(minify(input, { removeComments: true }), input); + test_minify(assert, input, { removeComments: true }, input); input = 'test'; - assert.equal(minify(input, { removeComments: true }), input); + test_minify(assert, input, { removeComments: true }, input); input = 'test'; - assert.equal(minify(input, { removeComments: true }), input); + test_minify(assert, input, { removeComments: true }, input); input = ''; - assert.equal(minify(input, { removeComments: true }), input); + test_minify(assert, input, { removeComments: true }, input); input = ''; - assert.equal(minify(input, { removeComments: true }), input); + test_minify(assert, input, { removeComments: true }, input); input = '\n' + ' \n' + @@ -502,22 +554,22 @@ QUnit.test('conditional comments', function(assert) { ' alert("ie8!");\n' + ' \n' + ' '; - assert.equal(minify(input, { + test_minify(assert, input, { minifyJS: true, removeComments: true, collapseWhitespace: true, removeOptionalTags: true, removeScriptTypeAttributes: true - }), output); + }, output); output = ''; - assert.equal(minify(input, { + test_minify(assert, input, { minifyJS: true, removeComments: true, collapseWhitespace: true, removeOptionalTags: true, removeScriptTypeAttributes: true, processConditionalComments: true - }), output); + }, output); input = '\n' + '\n' + @@ -545,15 +597,15 @@ QUnit.test('conditional comments', function(assert) { '' + '' + 'Document'; - assert.equal(minify(input, { + test_minify(assert, input, { removeComments: true, collapseWhitespace: true - }), output); - assert.equal(minify(input, { + }, output); + test_minify(assert, input, { removeComments: true, collapseWhitespace: true, processConditionalComments: true - }), output); + }, output); }); QUnit.test('collapsing space in conditional comments', function(assert) { @@ -562,215 +614,215 @@ QUnit.test('collapsing space in conditional comments', function(assert) { input = ''; - assert.equal(minify(input, { removeComments: true }), input); - assert.equal(minify(input, { removeComments: true, collapseWhitespace: true }), input); + test_minify(assert, input, { removeComments: true }, input); + test_minify(assert, input, { removeComments: true, collapseWhitespace: true }, input); output = ''; - assert.equal(minify(input, { removeComments: true, processConditionalComments: true }), output); + test_minify(assert, input, { removeComments: true, processConditionalComments: true }, output); output = ''; - assert.equal(minify(input, { + test_minify(assert, input, { removeComments: true, collapseWhitespace: true, processConditionalComments: true - }), output); + }, output); input = ''; - assert.equal(minify(input, { removeComments: true }), input); - assert.equal(minify(input, { removeComments: true, collapseWhitespace: true }), input); + test_minify(assert, input, { removeComments: true }, input); + test_minify(assert, input, { removeComments: true, collapseWhitespace: true }, input); output = ''; - assert.equal(minify(input, { + test_minify(assert, input, { removeComments: true, collapseWhitespace: true, processConditionalComments: true - }), output); + }, output); }); QUnit.test('remove comments from scripts', function(assert) { var input, output; input = ''; - assert.equal(minify(input), input); + test_minify(assert, input, input); output = ''; - assert.equal(minify(input, { minifyJS: true }), output); + test_minify(assert, input, { minifyJS: true }, output); input = ''; - assert.equal(minify(input), input); + test_minify(assert, input, input); output = ''; - assert.equal(minify(input, { minifyJS: true }), output); + test_minify(assert, input, { minifyJS: true }, output); input = ''; - assert.equal(minify(input), input); + test_minify(assert, input, input); output = ''; - assert.equal(minify(input, { minifyJS: true }), output); + test_minify(assert, input, { minifyJS: true }, output); input = ''; - assert.equal(minify(input), input); - assert.equal(minify(input, { minifyJS: true }), input); + test_minify(assert, input, input); + test_minify(assert, input, { minifyJS: true }, input); input = ''; - assert.equal(minify(input), input); - assert.equal(minify(input, { minifyJS: true }), input); + test_minify(assert, input, input); + test_minify(assert, input, { minifyJS: true }, input); input = ''; - assert.equal(minify(input), input); + test_minify(assert, input, input); output = ''; - assert.equal(minify(input, { minifyJS: true }), output); + test_minify(assert, input, { minifyJS: true }, output); input = ''; - assert.equal(minify(input), input); - assert.equal(minify(input, { minifyJS: true }), input); + test_minify(assert, input, input); + test_minify(assert, input, { minifyJS: true }, input); input = ''; - assert.equal(minify(input), input); + test_minify(assert, input, input); output = ''; - assert.equal(minify(input, { minifyJS: true }), output); + test_minify(assert, input, { minifyJS: true }, output); input = ''; - assert.equal(minify(input), input); + test_minify(assert, input, input); output = ''; - assert.equal(minify(input, { minifyJS: true }), output); + test_minify(assert, input, { minifyJS: true }, output); input = ''; - assert.equal(minify(input), input); - assert.equal(minify(input, { minifyJS: true }), input); + test_minify(assert, input, input); + test_minify(assert, input, { minifyJS: true }, input); }); QUnit.test('remove comments from styles', function(assert) { var input, output; input = ''; - assert.equal(minify(input), input); + test_minify(assert, input, input); output = ''; - assert.equal(minify(input, { minifyCSS: true }), output); + test_minify(assert, input, { minifyCSS: true }, output); input = ''; - assert.equal(minify(input), input); + test_minify(assert, input, input); output = ''; - assert.equal(minify(input, { minifyCSS: true }), output); + test_minify(assert, input, { minifyCSS: true }, output); input = ''; - assert.equal(minify(input), input); + test_minify(assert, input, input); output = ''; - assert.equal(minify(input, { minifyCSS: true }), output); + test_minify(assert, input, { minifyCSS: true }, output); input = ''; - assert.equal(minify(input), input); + test_minify(assert, input, input); output = ''; - assert.equal(minify(input, { minifyCSS: true }), output); + test_minify(assert, input, { minifyCSS: true }, output); input = ''; - assert.equal(minify(input), input); + test_minify(assert, input, input); output = ''; - assert.equal(minify(input, { minifyCSS: true }), output); + test_minify(assert, input, { minifyCSS: true }, output); input = ''; - assert.equal(minify(input), input); + test_minify(assert, input, input); output = ''; - assert.equal(minify(input, { minifyCSS: true }), output); + test_minify(assert, input, { minifyCSS: true }, output); input = ''; - assert.equal(minify(input), input); + test_minify(assert, input, input); output = ''; - assert.equal(minify(input, { minifyCSS: true }), output); + test_minify(assert, input, { minifyCSS: true }, output); input = ''; - assert.equal(minify(input), input); + test_minify(assert, input, input); output = ''; - assert.equal(minify(input, { minifyCSS: true }), output); + test_minify(assert, input, { minifyCSS: true }, output); input = ''; - assert.equal(minify(input), input); - assert.equal(minify(input, { minifyCSS: true }), input); + test_minify(assert, input, input); + test_minify(assert, input, { minifyCSS: true }, input); }); QUnit.test('remove CDATA sections from scripts/styles', function(assert) { var input, output; input = ''; - assert.equal(minify(input), input); - assert.equal(minify(input, { minifyJS: true }), input); + test_minify(assert, input, input); + test_minify(assert, input, { minifyJS: true }, input); input = ''; - assert.equal(minify(input), input); - assert.equal(minify(input, { minifyJS: true }), input); + test_minify(assert, input, input); + test_minify(assert, input, { minifyJS: true }, input); input = ''; - assert.equal(minify(input), input); - assert.equal(minify(input, { minifyJS: true }), input); + test_minify(assert, input, input); + test_minify(assert, input, { minifyJS: true }, input); input = ''; - assert.equal(minify(input), input); - assert.equal(minify(input, { minifyJS: true }), input); + test_minify(assert, input, input); + test_minify(assert, input, { minifyJS: true }, input); input = ''; - assert.equal(minify(input), input); - assert.equal(minify(input, { minifyJS: true }), input); + test_minify(assert, input, input); + test_minify(assert, input, { minifyJS: true }, input); input = ''; - assert.equal(minify(input), input); + test_minify(assert, input, input); output = ''; - assert.equal(minify(input, { minifyJS: true }), output); + test_minify(assert, input, { minifyJS: true }, output); input = ''; - assert.equal(minify(input), input); + test_minify(assert, input, input); output = ''; - assert.equal(minify(input, { minifyJS: true }), output); + test_minify(assert, input, { minifyJS: true }, output); input = ''; - assert.equal(minify(input), input); + test_minify(assert, input, input); output = ''; - assert.equal(minify(input, { minifyJS: true }), output); + test_minify(assert, input, { minifyJS: true }, output); input = ''; - assert.equal(minify(input), input); + test_minify(assert, input, input); output = ''; - assert.equal(minify(input, { minifyJS: true }), output); + test_minify(assert, input, { minifyJS: true }, output); input = ''; - assert.equal(minify(input), input); + test_minify(assert, input, input); output = ''; - assert.equal(minify(input, { minifyCSS: true }), output); + test_minify(assert, input, { minifyCSS: true }, output); input = ''; - assert.equal(minify(input), input); + test_minify(assert, input, input); output = ''; - assert.equal(minify(input, { minifyCSS: true }), output); + test_minify(assert, input, { minifyCSS: true }, output); input = ''; - assert.equal(minify(input), input); + test_minify(assert, input, input); output = ''; - assert.equal(minify(input, { minifyCSS: true }), output); + test_minify(assert, input, { minifyCSS: true }, output); input = ''; - assert.equal(minify(input), input); + test_minify(assert, input, input); output = ''; - assert.equal(minify(input, { minifyCSS: true }), output); + test_minify(assert, input, { minifyCSS: true }, output); input = ''; - assert.equal(minify(input), input); + test_minify(assert, input, input); output = ''; - assert.equal(minify(input, { minifyCSS: true }), output); + test_minify(assert, input, { minifyCSS: true }, output); input = ''; - assert.equal(minify(input), input); + test_minify(assert, input, input); output = ''; - assert.equal(minify(input, { minifyCSS: true }), output); + test_minify(assert, input, { minifyCSS: true }, output); input = ''; - assert.equal(minify(input), input); + test_minify(assert, input, input); output = ''; - assert.equal(minify(input, { minifyCSS: true }), output); + test_minify(assert, input, { minifyCSS: true }, output); input = ''; - assert.equal(minify(input), input); - assert.equal(minify(input, { minifyCSS: true }), input); + test_minify(assert, input, input); + test_minify(assert, input, { minifyCSS: true }, input); }); QUnit.test('custom processors', function(assert) { @@ -781,125 +833,125 @@ QUnit.test('custom processors', function(assert) { } input = ''; - assert.equal(minify(input), input); - assert.equal(minify(input, { minifyCSS: null }), input); - assert.equal(minify(input, { minifyCSS: false }), input); + test_minify(assert, input, input); + test_minify(assert, input, { minifyCSS: null }, input); + test_minify(assert, input, { minifyCSS: false }, input); output = ''; - assert.equal(minify(input, { minifyCSS: css }), output); + test_minify(assert, input, { minifyCSS: css }, output); input = '

    '; - assert.equal(minify(input), input); - assert.equal(minify(input, { minifyCSS: null }), input); - assert.equal(minify(input, { minifyCSS: false }), input); + test_minify(assert, input, input); + test_minify(assert, input, { minifyCSS: null }, input); + test_minify(assert, input, { minifyCSS: false }, input); output = '

    '; - assert.equal(minify(input, { minifyCSS: css }), output); + test_minify(assert, input, { minifyCSS: css }, output); input = ''; - assert.equal(minify(input), input); - assert.equal(minify(input, { minifyCSS: null }), input); - assert.equal(minify(input, { minifyCSS: false }), input); + test_minify(assert, input, input); + test_minify(assert, input, { minifyCSS: null }, input); + test_minify(assert, input, { minifyCSS: false }, input); output = ''; - assert.equal(minify(input, { minifyCSS: css }), output); + test_minify(assert, input, { minifyCSS: css }, output); input = ''; - assert.equal(minify(input), input); - assert.equal(minify(input, { minifyCSS: null }), input); - assert.equal(minify(input, { minifyCSS: false }), input); + test_minify(assert, input, input); + test_minify(assert, input, { minifyCSS: null }, input); + test_minify(assert, input, { minifyCSS: false }, input); output = ''; - assert.equal(minify(input, { minifyCSS: css }), output); + test_minify(assert, input, { minifyCSS: css }, output); function js(text, inline) { return inline ? 'Inline JS' : 'Normal JS'; } input = ''; - assert.equal(minify(input), input); - assert.equal(minify(input, { minifyJS: null }), input); - assert.equal(minify(input, { minifyJS: false }), input); + test_minify(assert, input, input); + test_minify(assert, input, { minifyJS: null }, input); + test_minify(assert, input, { minifyJS: false }, input); output = ''; - assert.equal(minify(input, { minifyJS: js }), output); + test_minify(assert, input, { minifyJS: js }, output); input = '

    '; - assert.equal(minify(input), input); - assert.equal(minify(input, { minifyJS: null }), input); - assert.equal(minify(input, { minifyJS: false }), input); + test_minify(assert, input, input); + test_minify(assert, input, { minifyJS: null }, input); + test_minify(assert, input, { minifyJS: false }, input); output = '

    '; - assert.equal(minify(input, { minifyJS: js }), output); + test_minify(assert, input, { minifyJS: js }, output); function url() { return 'URL'; } input = 'bar'; - assert.equal(minify(input), input); - assert.equal(minify(input, { minifyURLs: null }), input); - assert.equal(minify(input, { minifyURLs: false }), input); + test_minify(assert, input, input); + test_minify(assert, input, { minifyURLs: null }, input); + test_minify(assert, input, { minifyURLs: false }, input); output = 'bar'; - assert.equal(minify(input, { minifyURLs: url }), output); + test_minify(assert, input, { minifyURLs: url }, output); input = ''; - assert.equal(minify(input), input); - assert.equal(minify(input, { minifyURLs: null }), input); - assert.equal(minify(input, { minifyURLs: false }), input); - assert.equal(minify(input, { minifyURLs: url }), input); + test_minify(assert, input, input); + test_minify(assert, input, { minifyURLs: null }, input); + test_minify(assert, input, { minifyURLs: false }, input); + test_minify(assert, input, { minifyURLs: url }, input); output = ''; - assert.equal(minify(input, { minifyCSS: true, minifyURLs: url }), output); + test_minify(assert, input, { minifyCSS: true, minifyURLs: url }, output); }); QUnit.test('empty attributes', function(assert) { var input; input = '

    x

    '; - assert.equal(minify(input, { removeEmptyAttributes: true }), '

    x

    '); + test_minify(assert, input, { removeEmptyAttributes: true }, '

    x

    '); input = '

    x

    '; - assert.equal(minify(input, { removeEmptyAttributes: true }), '

    x

    '); + test_minify(assert, input, { removeEmptyAttributes: true }, '

    x

    '); input = ''; - assert.equal(minify(input, { removeEmptyAttributes: true }), ''); + test_minify(assert, input, { removeEmptyAttributes: true }, ''); input = ''; - assert.equal(minify(input, { removeEmptyAttributes: true }), ''); + test_minify(assert, input, { removeEmptyAttributes: true }, ''); input = ''; - assert.equal(minify(input, { removeEmptyAttributes: true }), ''); + test_minify(assert, input, { removeEmptyAttributes: true }, ''); // preserve unrecognized attribute // remove recognized attrs with unspecified values input = '
    '; - assert.equal(minify(input, { removeEmptyAttributes: true }), '
    '); + test_minify(assert, input, { removeEmptyAttributes: true }, '
    '); // additional remove attributes input = ''; - assert.equal(minify(input, { removeEmptyAttributes: function(attrName, tag) { return tag === 'img' && attrName === 'src'; } }), ''); + test_minify(assert, input, { removeEmptyAttributes: function(attrName, tag) { return tag === 'img' && attrName === 'src'; } }, ''); }); QUnit.test('cleaning class/style attributes', function(assert) { var input, output; input = '

    foo bar baz

    '; - assert.equal(minify(input), '

    foo bar baz

    '); + test_minify(assert, input, '

    foo bar baz

    '); input = '

    foo bar baz

    '; - assert.equal(minify(input), '

    foo bar baz

    '); - assert.equal(minify(input, { removeAttributeQuotes: true }), '

    foo bar baz

    '); + test_minify(assert, input, '

    foo bar baz

    '); + test_minify(assert, input, { removeAttributeQuotes: true }, '

    foo bar baz

    '); input = '

    foo bar baz

    '; output = '

    foo bar baz

    '; - assert.equal(minify(input), output); + test_minify(assert, input, output); input = '

    foo bar baz

    '; output = '

    foo bar baz

    '; - assert.equal(minify(input), output); + test_minify(assert, input, output); input = '

    '; output = '

    '; - assert.equal(minify(input), output); + test_minify(assert, input, output); input = '

    '; output = '

    '; - assert.equal(minify(input), output); + test_minify(assert, input, output); }); QUnit.test('cleaning URI-based attributes', function(assert) { @@ -907,41 +959,41 @@ QUnit.test('cleaning URI-based attributes', function(assert) { input = 'x'; output = 'x'; - assert.equal(minify(input), output); + test_minify(assert, input, output); input = 'x'; output = 'x'; - assert.equal(minify(input), output); + test_minify(assert, input, output); input = ''; output = ''; - assert.equal(minify(input), output); + test_minify(assert, input, output); input = ''; output = ''; - assert.equal(minify(input), output); + test_minify(assert, input, output); input = '
    '; output = '
    '; - assert.equal(minify(input), output); + test_minify(assert, input, output); input = '

    foobar

    '; output = '

    foobar

    '; - assert.equal(minify(input), output); + test_minify(assert, input, output); input = ''; output = ''; - assert.equal(minify(input), output); + test_minify(assert, input, output); input = ''; output = ''; - assert.equal(minify(input), output); + test_minify(assert, input, output); input = 'foo'; - assert.equal(minify(input), input); + test_minify(assert, input, input); input = '
    blah
    '; - assert.equal(minify(input), input); + test_minify(assert, input, input); }); QUnit.test('cleaning Number-based attributes', function(assert) { @@ -949,27 +1001,27 @@ QUnit.test('cleaning Number-based attributes', function(assert) { input = 'x'; output = 'x'; - assert.equal(minify(input), output); + test_minify(assert, input, output); input = ''; output = ''; - assert.equal(minify(input), output); + test_minify(assert, input, output); input = ''; output = ''; - assert.equal(minify(input), output); + test_minify(assert, input, output); input = ''; output = ''; - assert.equal(minify(input), output); + test_minify(assert, input, output); input = ''; output = ''; - assert.equal(minify(input), output); + test_minify(assert, input, output); input = 'x'; output = 'x'; - assert.equal(minify(input), output); + test_minify(assert, input, output); }); QUnit.test('cleaning other attributes', function(assert) { @@ -977,50 +1029,50 @@ QUnit.test('cleaning other attributes', function(assert) { input = 'blah'; output = 'blah'; - assert.equal(minify(input), output); + test_minify(assert, input, output); input = '

    x'; output = '

    x

    '; - assert.equal(minify(input), output); + test_minify(assert, input, output); }); QUnit.test('removing redundant attributes (<form method="get" ...>)', function(assert) { var input; input = '
    hello world
    '; - assert.equal(minify(input, { removeRedundantAttributes: true }), '
    hello world
    '); + test_minify(assert, input, { removeRedundantAttributes: true }, '
    hello world
    '); input = '
    hello world
    '; - assert.equal(minify(input, { removeRedundantAttributes: true }), '
    hello world
    '); + test_minify(assert, input, { removeRedundantAttributes: true }, '
    hello world
    '); }); QUnit.test('removing redundant attributes (<input type="text" ...>)', function(assert) { var input; input = ''; - assert.equal(minify(input, { removeRedundantAttributes: true }), ''); + test_minify(assert, input, { removeRedundantAttributes: true }, ''); input = ''; - assert.equal(minify(input, { removeRedundantAttributes: true }), ''); + test_minify(assert, input, { removeRedundantAttributes: true }, ''); input = ''; - assert.equal(minify(input, { removeRedundantAttributes: true }), ''); + test_minify(assert, input, { removeRedundantAttributes: true }, ''); }); QUnit.test('removing redundant attributes (<a name="..." id="..." ...>)', function(assert) { var input; input = 'blah'; - assert.equal(minify(input, { removeRedundantAttributes: true }), 'blah'); + test_minify(assert, input, { removeRedundantAttributes: true }, 'blah'); input = ''; - assert.equal(minify(input, { removeRedundantAttributes: true }), input); + test_minify(assert, input, { removeRedundantAttributes: true }, input); input = 'blah'; - assert.equal(minify(input, { removeRedundantAttributes: true }), input); + test_minify(assert, input, { removeRedundantAttributes: true }, input); input = 'blah'; - assert.equal(minify(input, { removeRedundantAttributes: true }), 'blah'); + test_minify(assert, input, { removeRedundantAttributes: true }, 'blah'); }); QUnit.test('removing redundant attributes (<script src="..." charset="...">)', function(assert) { @@ -1028,125 +1080,125 @@ QUnit.test('removing redundant attributes (<script src="..." charset="...">)' input = ''; output = ''; - assert.equal(minify(input, { removeRedundantAttributes: true }), output); + test_minify(assert, input, { removeRedundantAttributes: true }, output); input = ''; - assert.equal(minify(input, { removeRedundantAttributes: true }), input); + test_minify(assert, input, { removeRedundantAttributes: true }, input); input = ''; output = ''; - assert.equal(minify(input, { removeRedundantAttributes: true }), output); + test_minify(assert, input, { removeRedundantAttributes: true }, output); }); QUnit.test('removing redundant attributes (<... language="javascript" ...>)', function(assert) { var input; input = ''; - assert.equal(minify(input, { removeRedundantAttributes: true }), ''); + test_minify(assert, input, { removeRedundantAttributes: true }, ''); input = ''; - assert.equal(minify(input, { removeRedundantAttributes: true }), ''); + test_minify(assert, input, { removeRedundantAttributes: true }, ''); }); QUnit.test('removing redundant attributes (<area shape="rect" ...>)', function(assert) { var input = ''; var output = ''; - assert.equal(minify(input, { removeRedundantAttributes: true }), output); + test_minify(assert, input, { removeRedundantAttributes: true }, output); }); QUnit.test('removing redundant attributes (<... = "javascript: ..." ...>)', function(assert) { var input; input = '

    x

    '; - assert.equal(minify(input), '

    x

    '); + test_minify(assert, input, '

    x

    '); input = '

    x

    '; - assert.equal(minify(input, { removeAttributeQuotes: true }), '

    x

    '); + test_minify(assert, input, { removeAttributeQuotes: true }, '

    x

    '); input = '

    x

    '; - assert.equal(minify(input), '

    x

    '); + test_minify(assert, input, '

    x

    '); input = '

    x

    '; - assert.equal(minify(input), input); + test_minify(assert, input, input); }); QUnit.test('removing javascript type attributes', function(assert) { var input, output; input = ''; - assert.equal(minify(input, { removeScriptTypeAttributes: false }), input); + test_minify(assert, input, { removeScriptTypeAttributes: false }, input); output = ''; - assert.equal(minify(input, { removeScriptTypeAttributes: true }), output); + test_minify(assert, input, { removeScriptTypeAttributes: true }, output); input = ''; - assert.equal(minify(input, { removeScriptTypeAttributes: false }), input); + test_minify(assert, input, { removeScriptTypeAttributes: false }, input); output = ''; - assert.equal(minify(input, { removeScriptTypeAttributes: true }), output); + test_minify(assert, input, { removeScriptTypeAttributes: true }, output); input = ''; output = ''; - assert.equal(minify(input, { removeScriptTypeAttributes: true }), output); + test_minify(assert, input, { removeScriptTypeAttributes: true }, output); input = ''; output = ''; - assert.equal(minify(input, { removeScriptTypeAttributes: true }), output); + test_minify(assert, input, { removeScriptTypeAttributes: true }, output); input = ''; output = ''; - assert.equal(minify(input, { removeScriptTypeAttributes: true }), output); + test_minify(assert, input, { removeScriptTypeAttributes: true }, output); }); QUnit.test('removing type="text/css" attributes', function(assert) { var input, output; input = ''; - assert.equal(minify(input, { removeStyleLinkTypeAttributes: false }), input); + test_minify(assert, input, { removeStyleLinkTypeAttributes: false }, input); output = ''; - assert.equal(minify(input, { removeStyleLinkTypeAttributes: true }), output); + test_minify(assert, input, { removeStyleLinkTypeAttributes: true }, output); input = ''; - assert.equal(minify(input, { removeStyleLinkTypeAttributes: false }), input); + test_minify(assert, input, { removeStyleLinkTypeAttributes: false }, input); output = ''; - assert.equal(minify(input, { removeStyleLinkTypeAttributes: true }), output); + test_minify(assert, input, { removeStyleLinkTypeAttributes: true }, output); input = ''; output = ''; - assert.equal(minify(input, { removeStyleLinkTypeAttributes: true }), output); + test_minify(assert, input, { removeStyleLinkTypeAttributes: true }, output); input = ''; - assert.equal(minify(input, { removeStyleLinkTypeAttributes: true }), input); + test_minify(assert, input, { removeStyleLinkTypeAttributes: true }, input); input = ''; output = ''; - assert.equal(minify(input, { removeStyleLinkTypeAttributes: true }), output); + test_minify(assert, input, { removeStyleLinkTypeAttributes: true }, output); input = ''; - assert.equal(minify(input, { removeStyleLinkTypeAttributes: true }), input); + test_minify(assert, input, { removeStyleLinkTypeAttributes: true }, input); }); QUnit.test('removing attribute quotes', function(assert) { var input; input = '

    foo

    '; - assert.equal(minify(input, { removeAttributeQuotes: true }), '

    foo

    '); + test_minify(assert, input, { removeAttributeQuotes: true }, '

    foo

    '); input = ''; - assert.equal(minify(input, { removeAttributeQuotes: true }), ''); + test_minify(assert, input, { removeAttributeQuotes: true }, ''); input = 'x'; - assert.equal(minify(input, { removeAttributeQuotes: true }), 'x'); + test_minify(assert, input, { removeAttributeQuotes: true }, 'x'); input = '\nfoo\n\n'; - assert.equal(minify(input, { removeAttributeQuotes: true }), '\nfoo\n\n'); + test_minify(assert, input, { removeAttributeQuotes: true }, '\nfoo\n\n'); input = '\nfoo\n\n'; - assert.equal(minify(input, { removeAttributeQuotes: true }), '\nfoo\n\n'); + test_minify(assert, input, { removeAttributeQuotes: true }, '\nfoo\n\n'); input = '\nfoo\n\n'; - assert.equal(minify(input, { removeAttributeQuotes: true, removeEmptyAttributes: true }), '\nfoo\n\n'); + test_minify(assert, input, { removeAttributeQuotes: true, removeEmptyAttributes: true }, '\nfoo\n\n'); input = '

    '; - assert.equal(minify(input, { removeAttributeQuotes: true }), '

    '); + test_minify(assert, input, { removeAttributeQuotes: true }, '

    '); }); QUnit.test('preserving custom attribute-wrapping markup', function(assert) { @@ -1158,10 +1210,10 @@ QUnit.test('preserving custom attribute-wrapping markup', function(assert) { }; input = ''; - assert.equal(minify(input, customAttrOptions), input); + test_minify(assert, input, customAttrOptions, input); input = ''; - assert.equal(minify(input, customAttrOptions), input); + test_minify(assert, input, customAttrOptions, input); // With multiple rules customAttrOptions = { @@ -1172,16 +1224,16 @@ QUnit.test('preserving custom attribute-wrapping markup', function(assert) { }; input = ''; - assert.equal(minify(input, customAttrOptions), input); + test_minify(assert, input, customAttrOptions, input); input = ''; - assert.equal(minify(input, customAttrOptions), input); + test_minify(assert, input, customAttrOptions, input); input = ''; - assert.equal(minify(input, customAttrOptions), input); + test_minify(assert, input, customAttrOptions, input); input = ''; - assert.equal(minify(input, customAttrOptions), input); + test_minify(assert, input, customAttrOptions, input); // With multiple rules and richer options customAttrOptions = { @@ -1194,13 +1246,13 @@ QUnit.test('preserving custom attribute-wrapping markup', function(assert) { }; input = ''; - assert.equal(minify(input, customAttrOptions), ''); + test_minify(assert, input, customAttrOptions, ''); input = ''; - assert.equal(minify(input, customAttrOptions), ''); + test_minify(assert, input, customAttrOptions, ''); customAttrOptions.keepClosingSlash = true; - assert.equal(minify(input, customAttrOptions), ''); + test_minify(assert, input, customAttrOptions, ''); }); QUnit.test('preserving custom attribute-joining markup', function(assert) { @@ -1210,9 +1262,9 @@ QUnit.test('preserving custom attribute-joining markup', function(assert) { customAttrAssign: [polymerConditionalAttributeJoin] }; input = '
    '; - assert.equal(minify(input, customAttrOptions), input); + test_minify(assert, input, customAttrOptions, input); input = '
    '; - assert.equal(minify(input, customAttrOptions), input); + test_minify(assert, input, customAttrOptions, input); }); QUnit.test('collapsing whitespace', function(assert) { @@ -1220,37 +1272,37 @@ QUnit.test('collapsing whitespace', function(assert) { input = ''; output = ''; - assert.equal(minify(input, { collapseWhitespace: true }), output); + test_minify(assert, input, { collapseWhitespace: true }, output); input = '

    foo

    bar

    \n\n \n\t\t
    baz
    '; output = '

    foo

    bar

    baz
    '; - assert.equal(minify(input, { collapseWhitespace: true }), output); + test_minify(assert, input, { collapseWhitespace: true }, output); input = '

    foo bar

    '; output = '

    foo bar

    '; - assert.equal(minify(input, { collapseWhitespace: true }), output); + test_minify(assert, input, { collapseWhitespace: true }, output); input = '

    foo\nbar

    '; output = '

    foo bar

    '; - assert.equal(minify(input, { collapseWhitespace: true }), output); + test_minify(assert, input, { collapseWhitespace: true }, output); input = '

    foo blah 22 bar

    '; output = '

    foo blah 22 bar

    '; - assert.equal(minify(input, { collapseWhitespace: true }), output); + test_minify(assert, input, { collapseWhitespace: true }, output); input = ''; output = ''; - assert.equal(minify(input, { collapseWhitespace: true }), output); + test_minify(assert, input, { collapseWhitespace: true }, output); input = '
    '; output = '
    '; - assert.equal(minify(input, { collapseWhitespace: true }), output); + test_minify(assert, input, { collapseWhitespace: true }, output); input = '
     $foo = "baz"; 
    '; output = '
     $foo = "baz"; 
    '; - assert.equal(minify(input, { collapseWhitespace: true }), output); + test_minify(assert, input, { collapseWhitespace: true }, output); output = '
    $foo = "baz";
    '; - assert.equal(minify(input, { collapseWhitespace: true, caseSensitive: true }), output); + test_minify(assert, input, { collapseWhitespace: true, caseSensitive: true }, output); input = '\r\n\r\n\r\n' + '\r\n\r\n\r\n' + @@ -1268,153 +1320,153 @@ QUnit.test('collapsing whitespace', function(assert) { '' + '
           \r\nxxxx
    x Hello billy ' + '
    ';
    -  assert.equal(minify(input, { collapseWhitespace: true }), output);
    +  test_minify(assert, input, { collapseWhitespace: true }, output);
     
       input = '
       hello     world 
    '; output = '
       hello     world 
    '; - assert.equal(minify(input, { collapseWhitespace: true }), output); + test_minify(assert, input, { collapseWhitespace: true }, output); input = '
       hello     world 
    '; output = '
       hello     world 
    '; - assert.equal(minify(input, { collapseWhitespace: true }), output); + test_minify(assert, input, { collapseWhitespace: true }, output); input = ''; output = ''; - assert.equal(minify(input, { collapseWhitespace: true }), output); + test_minify(assert, input, { collapseWhitespace: true }, output); input = ''; output = ''; - assert.equal(minify(input, { collapseWhitespace: true }), output); + test_minify(assert, input, { collapseWhitespace: true }, output); }); QUnit.test('removing empty elements', function(assert) { var input, output; - assert.equal(minify('

    x

    ', { removeEmptyElements: true }), '

    x

    '); - assert.equal(minify('

    ', { removeEmptyElements: true }), ''); + test_minify(assert, '

    x

    ', { removeEmptyElements: true }, '

    x

    '); + test_minify(assert, '

    ', { removeEmptyElements: true }, ''); input = '

    foobar

    '; output = '

    foobar

    '; - assert.equal(minify(input, { removeEmptyElements: true }), output); + test_minify(assert, input, { removeEmptyElements: true }, output); input = ''; output = ''; - assert.equal(minify(input, { removeEmptyElements: true }), output); + test_minify(assert, input, { removeEmptyElements: true }, output); input = ''; output = ''; - assert.equal(minify(input, { removeEmptyElements: true }), output); + test_minify(assert, input, { removeEmptyElements: true }, output); input = ''; - assert.equal(minify(input, { removeEmptyElements: true }), input); + test_minify(assert, input, { removeEmptyElements: true }, input); input = ''; - assert.equal(minify(input, { removeEmptyElements: true }), input); + test_minify(assert, input, { removeEmptyElements: true }, input); input = ''; output = ''; - assert.equal(minify(input, { removeEmptyElements: true }), output); + test_minify(assert, input, { removeEmptyElements: true }, output); input = ''; - assert.equal(minify(input, { removeEmptyElements: true }), input); + test_minify(assert, input, { removeEmptyElements: true }, input); input = ''; output = ''; - assert.equal(minify(input, { removeEmptyElements: true }), output); + test_minify(assert, input, { removeEmptyElements: true }, output); input = ''; - assert.equal(minify(input, { removeEmptyElements: true }), input); + test_minify(assert, input, { removeEmptyElements: true }, input); input = ''; output = ''; - assert.equal(minify(input, { removeEmptyElements: true }), output); + test_minify(assert, input, { removeEmptyElements: true }, output); input = ''; - assert.equal(minify(input, { removeEmptyElements: true }), input); + test_minify(assert, input, { removeEmptyElements: true }, input); input = ''; output = ''; - assert.equal(minify(input, { removeEmptyElements: true }), output); + test_minify(assert, input, { removeEmptyElements: true }, output); input = ''; - assert.equal(minify(input, { removeEmptyElements: true }), input); + test_minify(assert, input, { removeEmptyElements: true }, input); input = ''; - assert.equal(minify(input, { removeEmptyElements: true }), input); + test_minify(assert, input, { removeEmptyElements: true }, input); input = '
    helloworld
    '; - assert.equal(minify(input, { removeEmptyElements: true }), input); + test_minify(assert, input, { removeEmptyElements: true }, input); input = '

    x

    '; output = '

    x

    '; - assert.equal(minify(input, { removeEmptyElements: true }), output); + test_minify(assert, input, { removeEmptyElements: true }, output); input = '
    x
    y
    blah
    foo
    z
    '; output = '
    x
    y
    blah
    foo
    z
    '; - assert.equal(minify(input, { removeEmptyElements: true }), output); + test_minify(assert, input, { removeEmptyElements: true }, output); input = ''; - assert.equal(minify(input, { removeEmptyElements: true }), input); + test_minify(assert, input, { removeEmptyElements: true }, input); input = '

    '; output = ''; - assert.equal(minify(input, { removeEmptyElements: true }), output); + test_minify(assert, input, { removeEmptyElements: true }, output); input = ''; - assert.equal(minify(input, { removeEmptyElements: true }), input); + test_minify(assert, input, { removeEmptyElements: true }, input); input = ''; - assert.equal(minify(input, { removeEmptyElements: true }), ''); + test_minify(assert, input, { removeEmptyElements: true }, ''); input = '
    after
    '; output = '
    after
    '; - assert.equal(minify(input, { removeEmptyElements: true }), output); + test_minify(assert, input, { removeEmptyElements: true }, output); output = '
    after
    '; - assert.equal(minify(input, { collapseWhitespace: true, removeEmptyElements: true }), output); + test_minify(assert, input, { collapseWhitespace: true, removeEmptyElements: true }, output); input = '
    before
    '; output = '
    before
    '; - assert.equal(minify(input, { removeEmptyElements: true }), output); + test_minify(assert, input, { removeEmptyElements: true }, output); output = '
    before
    '; - assert.equal(minify(input, { collapseWhitespace: true, removeEmptyElements: true }), output); + test_minify(assert, input, { collapseWhitespace: true, removeEmptyElements: true }, output); input = '
    both
    '; output = '
    both
    '; - assert.equal(minify(input, { removeEmptyElements: true }), output); + test_minify(assert, input, { removeEmptyElements: true }, output); output = '
    both
    '; - assert.equal(minify(input, { collapseWhitespace: true, removeEmptyElements: true }), output); + test_minify(assert, input, { collapseWhitespace: true, removeEmptyElements: true }, output); input = '
    unary
    '; output = '
    unary
    '; - assert.equal(minify(input, { removeEmptyElements: true }), output); + test_minify(assert, input, { removeEmptyElements: true }, output); output = '
    unary
    '; - assert.equal(minify(input, { collapseWhitespace: true, removeEmptyElements: true }), output); + test_minify(assert, input, { collapseWhitespace: true, removeEmptyElements: true }, output); input = '
    Empty
    '; - assert.equal(minify(input, { removeEmptyElements: true }), input); + test_minify(assert, input, { removeEmptyElements: true }, input); output = '
    Empty
    '; - assert.equal(minify(input, { collapseWhitespace: true, removeEmptyElements: true }), output); + test_minify(assert, input, { collapseWhitespace: true, removeEmptyElements: true }, output); }); QUnit.test('collapsing boolean attributes', function(assert) { var input, output; input = ''; - assert.equal(minify(input, { collapseBooleanAttributes: true }), ''); + test_minify(assert, input, { collapseBooleanAttributes: true }, ''); input = ''; - assert.equal(minify(input, { collapseBooleanAttributes: true }), ''); + test_minify(assert, input, { collapseBooleanAttributes: true }, ''); input = ''; - assert.equal(minify(input, { collapseBooleanAttributes: true }), ''); + test_minify(assert, input, { collapseBooleanAttributes: true }, ''); input = ''; - assert.equal(minify(input, { collapseBooleanAttributes: true }), ''); + test_minify(assert, input, { collapseBooleanAttributes: true }, ''); input = ''; - assert.equal(minify(input, { collapseBooleanAttributes: true }), ''); + test_minify(assert, input, { collapseBooleanAttributes: true }, ''); input = ''; - assert.equal(minify(input, { collapseBooleanAttributes: true }), ''); + test_minify(assert, input, { collapseBooleanAttributes: true }, ''); input = ''; - assert.equal(minify(input, { collapseBooleanAttributes: true }), output); + test_minify(assert, input, { collapseBooleanAttributes: true }, output); output = ''; - assert.equal(minify(input, { collapseBooleanAttributes: true, caseSensitive: true }), output); + test_minify(assert, input, { collapseBooleanAttributes: true, caseSensitive: true }, output); }); QUnit.test('collapsing enumerated attributes', function(assert) { - assert.equal(minify('
    ', { collapseBooleanAttributes: true }), '
    '); - assert.equal(minify('
    ', { collapseBooleanAttributes: true }), '
    '); - assert.equal(minify('
    ', { collapseBooleanAttributes: true }), '
    '); - assert.equal(minify('
    ', { collapseBooleanAttributes: true }), '
    '); - assert.equal(minify('
    ', { collapseBooleanAttributes: true }), '
    '); - assert.equal(minify('
    ', { collapseBooleanAttributes: true }), '
    '); - assert.equal(minify('
    ', { collapseBooleanAttributes: true }), '
    '); - assert.equal(minify('
    ', { collapseBooleanAttributes: true }), '
    '); - assert.equal(minify('
    ', { collapseBooleanAttributes: true }), '
    '); - assert.equal(minify('
    ', { collapseBooleanAttributes: true }), '
    '); - assert.equal(minify('
    ', { collapseBooleanAttributes: true }), '
    '); + test_minify(assert, '
    ', { collapseBooleanAttributes: true }, '
    '); + test_minify(assert, '
    ', { collapseBooleanAttributes: true }, '
    '); + test_minify(assert, '
    ', { collapseBooleanAttributes: true }, '
    '); + test_minify(assert, '
    ', { collapseBooleanAttributes: true }, '
    '); + test_minify(assert, '
    ', { collapseBooleanAttributes: true }, '
    '); + test_minify(assert, '
    ', { collapseBooleanAttributes: true }, '
    '); + test_minify(assert, '
    ', { collapseBooleanAttributes: true }, '
    '); + test_minify(assert, '
    ', { collapseBooleanAttributes: true }, '
    '); + test_minify(assert, '
    ', { collapseBooleanAttributes: true }, '
    '); + test_minify(assert, '
    ', { collapseBooleanAttributes: true }, '
    '); + test_minify(assert, '
    ', { collapseBooleanAttributes: true }, '
    '); }); QUnit.test('keeping trailing slashes in tags', function(assert) { - assert.equal(minify('', { keepClosingSlash: true }), ''); + test_minify(assert, '', { keepClosingSlash: true }, ''); // https://github.com/kangax/html-minifier/issues/233 - assert.equal(minify('', { keepClosingSlash: true, removeAttributeQuotes: true }), ''); - assert.equal(minify('', { keepClosingSlash: true, removeAttributeQuotes: true, removeEmptyAttributes: true }), ''); - assert.equal(minify('', { keepClosingSlash: true, removeAttributeQuotes: true }), ''); + test_minify(assert, '', { keepClosingSlash: true, removeAttributeQuotes: true }, ''); + test_minify(assert, '', { keepClosingSlash: true, removeAttributeQuotes: true, removeEmptyAttributes: true }, ''); + test_minify(assert, '', { keepClosingSlash: true, removeAttributeQuotes: true }, ''); }); QUnit.test('removing optional tags', function(assert) { var input, output; input = '

    foo'; - assert.equal(minify(input, { removeOptionalTags: true }), input); + test_minify(assert, input, { removeOptionalTags: true }, input); input = '

    '; output = '

    '; - assert.equal(minify(input, { removeOptionalTags: true }), output); + test_minify(assert, input, { removeOptionalTags: true }, output); input = ''; output = ''; - assert.equal(minify(input, { removeOptionalTags: true }), output); - assert.equal(minify(input, { removeOptionalTags: true, removeEmptyElements: true }), output); + test_minify(assert, input, { removeOptionalTags: true }, output); + test_minify(assert, input, { removeOptionalTags: true, removeEmptyElements: true }, output); input = ''; output = ''; - assert.equal(minify(input, { removeOptionalTags: true }), output); - assert.equal(minify(input, { removeOptionalTags: true, removeEmptyElements: true }), output); + test_minify(assert, input, { removeOptionalTags: true }, output); + test_minify(assert, input, { removeOptionalTags: true, removeEmptyElements: true }, output); input = ' '; output = ' '; - assert.equal(minify(input, { removeOptionalTags: true }), output); + test_minify(assert, input, { removeOptionalTags: true }, output); output = ''; - assert.equal(minify(input, { collapseWhitespace: true, removeOptionalTags: true }), output); + test_minify(assert, input, { collapseWhitespace: true, removeOptionalTags: true }, output); input = ' '; output = ' '; - assert.equal(minify(input, { removeOptionalTags: true }), output); + test_minify(assert, input, { removeOptionalTags: true }, output); output = ''; - assert.equal(minify(input, { collapseWhitespace: true, removeOptionalTags: true }), output); + test_minify(assert, input, { collapseWhitespace: true, removeOptionalTags: true }, output); input = ' '; output = ' '; - assert.equal(minify(input, { removeOptionalTags: true }), output); + test_minify(assert, input, { removeOptionalTags: true }, output); output = ''; - assert.equal(minify(input, { collapseWhitespace: true, removeOptionalTags: true }), output); + test_minify(assert, input, { collapseWhitespace: true, removeOptionalTags: true }, output); input = ' '; output = ' '; - assert.equal(minify(input, { removeOptionalTags: true }), output); + test_minify(assert, input, { removeOptionalTags: true }, output); output = ''; - assert.equal(minify(input, { collapseWhitespace: true, removeOptionalTags: true }), output); + test_minify(assert, input, { collapseWhitespace: true, removeOptionalTags: true }, output); input = ' '; output = ' '; - assert.equal(minify(input, { removeOptionalTags: true }), output); + test_minify(assert, input, { removeOptionalTags: true }, output); output = ''; - assert.equal(minify(input, { collapseWhitespace: true, removeOptionalTags: true }), output); + test_minify(assert, input, { collapseWhitespace: true, removeOptionalTags: true }, output); input = ' '; output = ' '; - assert.equal(minify(input, { removeOptionalTags: true }), output); + test_minify(assert, input, { removeOptionalTags: true }, output); output = ''; - assert.equal(minify(input, { collapseWhitespace: true, removeOptionalTags: true }), output); + test_minify(assert, input, { collapseWhitespace: true, removeOptionalTags: true }, output); input = ' '; output = ' '; - assert.equal(minify(input, { removeOptionalTags: true }), output); + test_minify(assert, input, { removeOptionalTags: true }, output); output = ''; - assert.equal(minify(input, { collapseWhitespace: true, removeOptionalTags: true }), output); + test_minify(assert, input, { collapseWhitespace: true, removeOptionalTags: true }, output); input = ' '; output = ' '; - assert.equal(minify(input, { removeOptionalTags: true }), output); + test_minify(assert, input, { removeOptionalTags: true }, output); output = ''; - assert.equal(minify(input, { collapseWhitespace: true, removeOptionalTags: true }), output); + test_minify(assert, input, { collapseWhitespace: true, removeOptionalTags: true }, output); input = 'hello

    foobar

    '; - assert.equal(minify(input), input); + test_minify(assert, input, input); output = 'hello

    foobar'; - assert.equal(minify(input, { removeOptionalTags: true }), output); + test_minify(assert, input, { removeOptionalTags: true }, output); input = 'hello

    foobar

    '; output = 'hello

    foobar'; - assert.equal(minify(input, { removeOptionalTags: true }), output); + test_minify(assert, input, { removeOptionalTags: true }, output); output = 'hello

    foobar'; - assert.equal(minify(input, { removeOptionalTags: true, removeEmptyAttributes: true }), output); + test_minify(assert, input, { removeOptionalTags: true, removeEmptyAttributes: true }, output); input = 'a

    '; output = 'a
    '; - assert.equal(minify(input, { removeOptionalTags: true }), output); + test_minify(assert, input, { removeOptionalTags: true }, output); input = 'Blah

    This is some text in a div

    Followed by some details

    This is some more text in a div

    '; output = 'Blah

    This is some text in a div

    Followed by some details

    This is some more text in a div

    '; - assert.equal(minify(input, { removeOptionalTags: true }), output); + test_minify(assert, input, { removeOptionalTags: true }, output); input = 'Blah'; output = 'Blah'; - assert.equal(minify(input, { removeOptionalTags: true }), output); + test_minify(assert, input, { removeOptionalTags: true }, output); input = '

    Configure

    '; - assert.equal(minify(input, { removeOptionalTags: true }), input); + test_minify(assert, input, { removeOptionalTags: true }, input); }); QUnit.test('removing optional tags in tables', function(assert) { @@ -1559,21 +1611,21 @@ QUnit.test('removing optional tags in tables', function(assert) { 'boomooloo ' + 'baz quxboo' + ''; - assert.equal(minify(input), input); + test_minify(assert, input, input); output = '' + ' ' + ' ' + '
    foobar baz
    boomooloo
    baz quxboo' + '
    '; - assert.equal(minify(input, { removeOptionalTags: true }), output); + test_minify(assert, input, { removeOptionalTags: true }, output); output = '' + '
    foobarbaz' + '
    boomooloo' + '
    bazquxboo' + '
    '; - assert.equal(minify(input, { collapseWhitespace: true, removeOptionalTags: true }), output); + test_minify(assert, input, { collapseWhitespace: true, removeOptionalTags: true }, output); input = '' + '' + @@ -1582,7 +1634,7 @@ QUnit.test('removing optional tags in tables', function(assert) { '' + '' + '
    foo
    barbazqux
    '; - assert.equal(minify(input), input); + test_minify(assert, input, input); output = '' + '' + @@ -1591,22 +1643,22 @@ QUnit.test('removing optional tags in tables', function(assert) { '' + '
    foo
    barbazqux' + '
    '; - assert.equal(minify(input, { removeOptionalTags: true }), output); + test_minify(assert, input, { removeOptionalTags: true }, output); output = '' + '' + '
    foo' + '
    barbazqux' + '
    '; - assert.equal(minify(input, { removeComments: true, removeOptionalTags: true }), output); + test_minify(assert, input, { removeComments: true, removeOptionalTags: true }, output); input = '' + '' + '
    '; - assert.equal(minify(input), input); + test_minify(assert, input, input); output = '
    '; - assert.equal(minify(input, { removeOptionalTags: true }), output); + test_minify(assert, input, { removeOptionalTags: true }, output); }); QUnit.test('removing optional tags in options', function(assert) { @@ -1614,17 +1666,17 @@ QUnit.test('removing optional tags in options', function(assert) { input = ''; output = ''; - assert.equal(minify(input, { removeOptionalTags: true }), output); + test_minify(assert, input, { removeOptionalTags: true }, output); input = ''; - assert.equal(minify(input, { removeOptionalTags: true }), input); + test_minify(assert, input, { removeOptionalTags: true }, input); output = ''; - assert.equal(minify(input, { removeOptionalTags: true, collapseWhitespace: true }), output); + test_minify(assert, input, { removeOptionalTags: true, collapseWhitespace: true }, output); output = ''; - assert.equal(minify(input, { removeOptionalTags: true, collapseWhitespace: true, conservativeCollapse: true }), output); + test_minify(assert, input, { removeOptionalTags: true, collapseWhitespace: true, conservativeCollapse: true }, output); // example from htmldog.com input = ''; - assert.equal(minify(input, { removeOptionalTags: true }), output); + test_minify(assert, input, { removeOptionalTags: true }, output); }); QUnit.test('custom components', function(assert) { var input = 'Oh, my.'; var output = 'Oh, my.'; - assert.equal(minify(input), output); + test_minify(assert, input, output); }); QUnit.test('HTML4: anchor with inline elements', function(assert) { var input = 'Well, look at me! I\'m a span!'; - assert.equal(minify(input, { html5: false }), input); + test_minify(assert, input, { html5: false }, input); }); QUnit.test('HTML5: anchor with inline elements', function(assert) { var input = 'Well, look at me! I\'m a span!'; - assert.equal(minify(input, { html5: true }), input); + test_minify(assert, input, { html5: true }, input); }); QUnit.test('HTML4: anchor with block elements', function(assert) { var input = '
    Well, look at me! I\'m a div!
    '; var output = '
    Well, look at me! I\'m a div!
    '; - assert.equal(minify(input, { html5: false }), output); + test_minify(assert, input, { html5: false }, output); }); QUnit.test('HTML5: anchor with block elements', function(assert) { var input = '
    Well, look at me! I\'m a div!
    '; var output = '
    Well, look at me! I\'m a div!
    '; - assert.equal(minify(input, { html5: true }), output); + test_minify(assert, input, { html5: true }, output); }); QUnit.test('HTML5: enabled by default', function(assert) { var input = '
    Well, look at me! I\'m a div!
    '; - assert.equal(minify(input, { html5: true }), minify(input)); + test_minify(assert, input, { html5: true }, minify(input)); }); QUnit.test('phrasing content', function(assert) { @@ -1684,12 +1736,12 @@ QUnit.test('phrasing content', function(assert) { input = '

    a

    b
    '; output = '

    a

    b
    '; - assert.equal(minify(input, { html5: true }), output); + test_minify(assert, input, { html5: true }, output); output = '

    a

    b

    '; - assert.equal(minify(input, { html5: false }), output); + test_minify(assert, input, { html5: false }, output); input = ''; - assert.equal(minify(input, { html5: true }), input); + test_minify(assert, input, { html5: true }, input); }); // https://github.com/kangax/html-minifier/issues/888 @@ -1698,29 +1750,29 @@ QUnit.test('ul/ol should be phrasing content', function(assert) { input = '

    a

    • item
    '; output = '

    a

    • item
    '; - assert.equal(minify(input, { html5: true }), output); + test_minify(assert, input, { html5: true }, output); output = '

    a

    • item
    '; - assert.equal(minify(input, { html5: true, removeOptionalTags: true }), output); + test_minify(assert, input, { html5: true, removeOptionalTags: true }, output); output = '

    a

    • item

    '; - assert.equal(minify(input, { html5: false }), output); + test_minify(assert, input, { html5: false }, output); input = '

    a

    1. item

    '; output = '

    a

    1. item

    '; - assert.equal(minify(input, { html5: true }), output); + test_minify(assert, input, { html5: true }, output); output = '

    a

    1. item

    '; - assert.equal(minify(input, { html5: true, removeOptionalTags: true }), output); + test_minify(assert, input, { html5: true, removeOptionalTags: true }, output); output = '

    a

    1. item
    '; - assert.equal(minify(input, { html5: true, removeEmptyElements: true }), output); + test_minify(assert, input, { html5: true, removeEmptyElements: true }, output); }); QUnit.test('phrasing content with Web Components', function(assert) { var input = ''; var output = ''; - assert.equal(minify(input, { html5: true }), output); + test_minify(assert, input, { html5: true }, output); }); // https://github.com/kangax/html-minifier/issues/10 @@ -1730,52 +1782,52 @@ QUnit.test('Ignore custom fragments', function(assert) { input = 'This is the start. <% ... %>\r\n<%= ... %>\r\n\r\n\r\nNo comment, but middle.\r\n{{ ... }}\r\n\r\n\r\nHello, this is the end!'; output = 'This is the start. <% ... %> <%= ... %> No comment, but middle. {{ ... }} Hello, this is the end!'; - assert.equal(minify(input, {}), input); - assert.equal(minify(input, { removeComments: true, collapseWhitespace: true }), output); - assert.equal(minify(input, { + test_minify(assert, input, {}, input); + test_minify(assert, input, { removeComments: true, collapseWhitespace: true }, output); + test_minify(assert, input, { removeComments: true, collapseWhitespace: true, ignoreCustomFragments: reFragments - }), output); + }, output); output = 'This is the start. <% ... %>\n<%= ... %>\n\nNo comment, but middle. {{ ... }}\n\n\nHello, this is the end!'; - assert.equal(minify(input, { + test_minify(assert, input, { removeComments: true, collapseWhitespace: true, preserveLineBreaks: true - }), output); + }, output); output = 'This is the start. <% ... %>\n<%= ... %>\n\nNo comment, but middle.\n{{ ... }}\n\n\nHello, this is the end!'; - assert.equal(minify(input, { + test_minify(assert, input, { removeComments: true, collapseWhitespace: true, preserveLineBreaks: true, ignoreCustomFragments: reFragments - }), output); + }, output); input = '{{ if foo? }}\r\n
    \r\n ...\r\n
    \r\n{{ end \n}}'; output = '{{ if foo? }}
    ...
    {{ end }}'; - assert.equal(minify(input, {}), input); - assert.equal(minify(input, { collapseWhitespace: true }), output); - assert.equal(minify(input, { collapseWhitespace: true, ignoreCustomFragments: [] }), output); + test_minify(assert, input, {}, input); + test_minify(assert, input, { collapseWhitespace: true }, output); + test_minify(assert, input, { collapseWhitespace: true, ignoreCustomFragments: [] }, output); output = '{{ if foo? }}
    ...
    {{ end \n}}'; - assert.equal(minify(input, { collapseWhitespace: true, ignoreCustomFragments: reFragments }), output); + test_minify(assert, input, { collapseWhitespace: true, ignoreCustomFragments: reFragments }, output); output = '{{ if foo? }}\n
    \n...\n
    \n{{ end \n}}'; - assert.equal(minify(input, { + test_minify(assert, input, { collapseWhitespace: true, preserveLineBreaks: true, ignoreCustomFragments: reFragments - }), output); + }, output); input = ''; - assert.equal(minify(input, {}), input); - assert.equal(minify(input, { ignoreCustomFragments: reFragments }), input); + test_minify(assert, input, {}, input); + test_minify(assert, input, { ignoreCustomFragments: reFragments }, input); input = ''; output = ''; - assert.equal(minify(input, { ignoreCustomFragments: [/\{%[^%]*?%\}/g] }), output); + test_minify(assert, input, { ignoreCustomFragments: [/\{%[^%]*?%\}/g] }, output); input = '' + '{{ form.name.label_tag }}' + @@ -1787,13 +1839,13 @@ QUnit.test('Ignore custom fragments', function(assert) { '{% endfor %}' + '{% endif %}' + '

    '; - assert.equal(minify(input, { + test_minify(assert, input, { ignoreCustomFragments: [ /\{%[\s\S]*?%\}/g, /\{\{[\s\S]*?\}\}/g ], quoteCharacter: '\'' - }), input); + }, input); output = '

    ' + '{{ form.name.label_tag }}' + '{{ form.name }}' + @@ -1804,151 +1856,151 @@ QUnit.test('Ignore custom fragments', function(assert) { '{% endfor %}' + '{% endif %}' + '

    '; - assert.equal(minify(input, { + test_minify(assert, input, { ignoreCustomFragments: [ /\{%[\s\S]*?%\}/g, /\{\{[\s\S]*?\}\}/g ], quoteCharacter: '\'', collapseWhitespace: true - }), output); + }, output); input = '>Legal Notices'; - assert.equal(minify(input, { + test_minify(assert, input, { ignoreCustomFragments: [ /<\?php[\s\S]*?\?>/g ] - }), input); + }, input); input = '>'; - assert.equal(minify(input, { + test_minify(assert, input, { ignoreCustomFragments: [ /<%=[\s\S]*?%>/g ] - }), input); + }, input); input = ''; - assert.equal(minify(input, { + test_minify(assert, input, { ignoreCustomFragments: [ /\{\{[\s\S]*?\}\}/g ], caseSensitive: true - }), input); + }, input); input = ''; - assert.equal(minify(input, { + test_minify(assert, input, { ignoreCustomFragments: [ /\{%[^%]*?%\}/g ] - }), input); + }, input); // trimCustomFragments withOUT collapseWhitespace, does // not break the "{% foo %} {% bar %}" test - assert.equal(minify(input, { + test_minify(assert, input, { ignoreCustomFragments: [ /\{%[^%]*?%\}/g ], trimCustomFragments: true - }), input); + }, input); // trimCustomFragments WITH collapseWhitespace, changes output output = ''; - assert.equal(minify(input, { + test_minify(assert, input, { ignoreCustomFragments: [ /\{%[^%]*?%\}/g ], collapseWhitespace: true, trimCustomFragments: true - }), output); + }, output); input = ''; - assert.equal(minify(input), input); - assert.equal(minify(input, { + test_minify(assert, input, input); + test_minify(assert, input, { collapseWhitespace: true - }), input); + }, input); input = '
    '; - assert.equal(minify(input), input); - assert.equal(minify(input, { + test_minify(assert, input, input); + test_minify(assert, input, { collapseWhitespace: true - }), input); + }, input); input = '{{if a}}
    b
    {{/if}}'; - assert.equal(minify(input), input); + test_minify(assert, input, input); output = '{{if a}}
    b
    {{/if}}'; - assert.equal(minify(input, { + test_minify(assert, input, { removeComments: true, ignoreCustomFragments: [ /\{\{.*?\}\}/g ] - }), output); + }, output); // https://github.com/kangax/html-minifier/issues/722 input = ' bar'; - assert.equal(minify(input), input); - assert.equal(minify(input, { + test_minify(assert, input, input); + test_minify(assert, input, { collapseWhitespace: true - }), input); + }, input); output = 'bar'; - assert.equal(minify(input, { + test_minify(assert, input, { collapseWhitespace: true, trimCustomFragments: true - }), output); + }, output); input = ' bar'; - assert.equal(minify(input), input); + test_minify(assert, input, input); output = ' bar'; - assert.equal(minify(input, { + test_minify(assert, input, { collapseWhitespace: true - }), output); + }, output); output = 'bar'; - assert.equal(minify(input, { + test_minify(assert, input, { collapseWhitespace: true, trimCustomFragments: true - }), output); + }, output); input = 'foo baz'; - assert.equal(minify(input), input); - assert.equal(minify(input, { + test_minify(assert, input, input); + test_minify(assert, input, { collapseWhitespace: true - }), input); + }, input); output = 'foobaz'; - assert.equal(minify(input, { + test_minify(assert, input, { collapseWhitespace: true, trimCustomFragments: true - }), output); + }, output); input = 'foo foo'; - assert.equal(minify(input), input); - assert.equal(minify(input, { + test_minify(assert, input, input); + test_minify(assert, input, { collapseWhitespace: true - }), input); + }, input); output = 'foofoo'; - assert.equal(minify(input, { + test_minify(assert, input, { collapseWhitespace: true, trimCustomFragments: true - }), output); + }, output); input = 'foo baz moo loo'; - assert.equal(minify(input, { + test_minify(assert, input, { collapseWhitespace: true, ignoreCustomFragments: [ /<(WC@[\s\S]*?)>(.*?)<\/\1>/ ] - }), input); + }, input); output = 'foobaz mooloo'; - assert.equal(minify(input, { + test_minify(assert, input, { collapseWhitespace: true - }), output); + }, output); input = ''; - assert.equal(minify(input), input); - assert.equal(minify(input, { removeAttributeQuotes: true }), input); + test_minify(assert, input, input); + test_minify(assert, input, { removeAttributeQuotes: true }, input); input = '
    \nfoo\n\nbaz\n
    '; - assert.equal(minify(input), input); - assert.equal(minify(input, { collapseWhitespace: true }), input); + test_minify(assert, input, input); + test_minify(assert, input, { collapseWhitespace: true }, input); }); QUnit.test('bootstrap\'s span > button > span', function(assert) { @@ -1958,15 +2010,15 @@ QUnit.test('bootstrap\'s span > button > span', function(assert) { '\n ' + ''; var output = ''; - assert.equal(minify(input, { collapseWhitespace: true, removeAttributeQuotes: true }), output); + test_minify(assert, input, { collapseWhitespace: true, removeAttributeQuotes: true }, output); }); QUnit.test('caseSensitive', function(assert) { var input = '
    '; var caseSensitiveOutput = '
    '; var caseInSensitiveOutput = '
    '; - assert.equal(minify(input), caseInSensitiveOutput); - assert.equal(minify(input, { caseSensitive: true }), caseSensitiveOutput); + test_minify(assert, input, caseInSensitiveOutput); + test_minify(assert, input, { caseSensitive: true }, caseSensitiveOutput); }); QUnit.test('source & track', function(assert) { @@ -1976,8 +2028,8 @@ QUnit.test('source & track', function(assert) { '' + '' + ''; - assert.equal(minify(input), input); - assert.equal(minify(input, { removeOptionalTags: true }), input); + test_minify(assert, input, input); + test_minify(assert, input, { removeOptionalTags: true }, input); }); QUnit.test('mixed html and svg', function(assert) { @@ -2002,18 +2054,18 @@ QUnit.test('mixed html and svg', function(assert) { '' + ''; // Should preserve case-sensitivity and closing slashes within svg tags - assert.equal(minify(input, { collapseWhitespace: true }), output); + test_minify(assert, input, { collapseWhitespace: true }, output); }); QUnit.test('nested quotes', function(assert) { var input, output; input = '
    '; - assert.equal(minify(input), input); - assert.equal(minify(input, { quoteCharacter: '\'' }), input); + test_minify(assert, input, input); + test_minify(assert, input, { quoteCharacter: '\'' }, input); output = '
    '; - assert.equal(minify(input, { quoteCharacter: '"' }), output); + test_minify(assert, input, { quoteCharacter: '"' }, output); }); QUnit.test('script minification', function(assert) { @@ -2021,32 +2073,32 @@ QUnit.test('script minification', function(assert) { input = '(function(){ var foo = 1; var bar = 2; alert(foo + " " + bar); })()'; - assert.equal(minify(input, { minifyJS: true }), input); + test_minify(assert, input, { minifyJS: true }, input); input = ''; output = ''; - assert.equal(minify(input, { minifyJS: true }), output); + test_minify(assert, input, { minifyJS: true }, output); input = ''; output = ''; - assert.equal(minify(input, { minifyJS: true }), output); + test_minify(assert, input, { minifyJS: true }, output); input = ''; output = ''; - assert.equal(minify(input, { minifyJS: true }), output); + test_minify(assert, input, { minifyJS: true }, output); input = ''; output = ''; - assert.equal(minify(input, { minifyJS: true }), output); + test_minify(assert, input, { minifyJS: true }, output); - input = ''; - output = ''; + input = ''; + output = ''; - assert.equal(minify(input, { minifyJS: { mangle: false } }), output); + test_minify(assert, input, { minifyJS: { mangle: false } }, output); input = ''; output = ''; - assert.equal(minify(input, { minifyJS: true }), output); + test_minify(assert, input, { minifyJS: true }, output); }); QUnit.test('minification of scripts with different mimetypes', function(assert) { @@ -2067,268 +2119,268 @@ QUnit.test('minification of scripts with different mimetypes', function(assert) input = ''; output = ''; - assert.equal(minify(input, { minifyJS: true }), output); + test_minify(assert, input, { minifyJS: true }, output); input = ''; output = ''; - assert.equal(minify(input, { minifyJS: true }), output); + test_minify(assert, input, { minifyJS: true }, output); input = ''; output = ''; - assert.equal(minify(input, { minifyJS: true }), output); + test_minify(assert, input, { minifyJS: true }, output); input = ''; output = ''; - assert.equal(minify(input, { minifyJS: true }), output); + test_minify(assert, input, { minifyJS: true }, output); input = ''; output = ''; - assert.equal(minify(input, { minifyJS: true }), output); + test_minify(assert, input, { minifyJS: true }, output); input = ''; - assert.equal(minify(input, { minifyJS: true }), input); + test_minify(assert, input, { minifyJS: true }, input); input = ''; - assert.equal(minify(input, { minifyJS: true }), input); + test_minify(assert, input, { minifyJS: true }, input); }); QUnit.test('minification of scripts with custom fragments', function(assert) { var input, output; input = ''; - assert.equal(minify(input, { minifyJS: true }), input); - assert.equal(minify(input, { collapseWhitespace: true, minifyJS: true }), input); - assert.equal(minify(input, { + test_minify(assert, input, { minifyJS: true }, input); + test_minify(assert, input, { collapseWhitespace: true, minifyJS: true }, input); + test_minify(assert, input, { collapseWhitespace: true, minifyJS: true, preserveLineBreaks: true - }), input); + }, input); input = ''; - assert.equal(minify(input, { minifyJS: true }), input); + test_minify(assert, input, { minifyJS: true }, input); output = ''; - assert.equal(minify(input, { collapseWhitespace: true, minifyJS: true }), output); - assert.equal(minify(input, { + test_minify(assert, input, { collapseWhitespace: true, minifyJS: true }, output); + test_minify(assert, input, { collapseWhitespace: true, minifyJS: true, preserveLineBreaks: true - }), input); + }, input); input = ''; - assert.equal(minify(input, { minifyJS: true }), input); + test_minify(assert, input, { minifyJS: true }, input); output = ''; - assert.equal(minify(input, { collapseWhitespace: true, minifyJS: true }), output); - assert.equal(minify(input, { + test_minify(assert, input, { collapseWhitespace: true, minifyJS: true }, output); + test_minify(assert, input, { collapseWhitespace: true, minifyJS: true, preserveLineBreaks: true - }), input); + }, input); input = ''; - assert.equal(minify(input, { minifyJS: true }), input); + test_minify(assert, input, { minifyJS: true }, input); output = ''; - assert.equal(minify(input, { collapseWhitespace: true, minifyJS: true }), output); - assert.equal(minify(input, { + test_minify(assert, input, { collapseWhitespace: true, minifyJS: true }, output); + test_minify(assert, input, { collapseWhitespace: true, minifyJS: true, preserveLineBreaks: true - }), input); + }, input); input = ''; output = ''; - assert.equal(minify(input, { minifyJS: true }), output); - assert.equal(minify(input, { collapseWhitespace: true, minifyJS: true }), output); - assert.equal(minify(input, { + test_minify(assert, input, { minifyJS: true }, output); + test_minify(assert, input, { collapseWhitespace: true, minifyJS: true }, output); + test_minify(assert, input, { collapseWhitespace: true, minifyJS: true, preserveLineBreaks: true - }), output); + }, output); input = ''; output = ''; - assert.equal(minify(input, { minifyJS: true }), output); + test_minify(assert, input, { minifyJS: true }, output); output = ''; - assert.equal(minify(input, { collapseWhitespace: true, minifyJS: true }), output); + test_minify(assert, input, { collapseWhitespace: true, minifyJS: true }, output); output = ''; - assert.equal(minify(input, { + test_minify(assert, input, { collapseWhitespace: true, minifyJS: true, preserveLineBreaks: true - }), output); + }, output); input = ''; output = ''; - assert.equal(minify(input, { minifyJS: true }), output); - assert.equal(minify(input, { collapseWhitespace: true, minifyJS: true }), output); - assert.equal(minify(input, { + test_minify(assert, input, { minifyJS: true }, output); + test_minify(assert, input, { collapseWhitespace: true, minifyJS: true }, output); + test_minify(assert, input, { collapseWhitespace: true, minifyJS: true, preserveLineBreaks: true - }), output); + }, output); input = ''; output = ''; - assert.equal(minify(input, { minifyJS: true }), output); + test_minify(assert, input, { minifyJS: true }, output); output = ''; - assert.equal(minify(input, { collapseWhitespace: true, minifyJS: true }), output); + test_minify(assert, input, { collapseWhitespace: true, minifyJS: true }, output); output = ''; - assert.equal(minify(input, { + test_minify(assert, input, { collapseWhitespace: true, minifyJS: true, preserveLineBreaks: true - }), output); + }, output); input = ''; output = ''; - assert.equal(minify(input, { minifyJS: true }), output); + test_minify(assert, input, { minifyJS: true }, output); output = ''; - assert.equal(minify(input, { collapseWhitespace: true, minifyJS: true }), output); + test_minify(assert, input, { collapseWhitespace: true, minifyJS: true }, output); input = ''; output = ''; - assert.equal(minify(input, { minifyJS: true }), output); - assert.equal(minify(input, { collapseWhitespace: true, minifyJS: true }), output); + test_minify(assert, input, { minifyJS: true }, output); + test_minify(assert, input, { collapseWhitespace: true, minifyJS: true }, output); }); QUnit.test('event minification', function(assert) { var input, output; input = '
    '; - assert.equal(minify(input, { minifyJS: true }), input); + test_minify(assert, input, { minifyJS: true }, input); input = '
    '; output = '
    '; - assert.equal(minify(input, { minifyJS: true }), output); + test_minify(assert, input, { minifyJS: true }, output); input = 'test'; - output = 'test'; - assert.equal(minify(input, { minifyJS: true }), output); + output = 'test'; + test_minify(assert, input, { minifyJS: true }, output); input = ' foobar'; output = ' foobar'; - assert.equal(minify(input, { minifyJS: { mangle: false } }), output); - assert.equal(minify(input, { minifyJS: { mangle: false }, quoteCharacter: '\'' }), output); + test_minify(assert, input, { minifyJS: { mangle: false } }, output); + test_minify(assert, input, { minifyJS: { mangle: false }, quoteCharacter: '\'' }, output); input = ' foobar'; output = ' foobar'; - assert.equal(minify(input, { minifyJS: { mangle: false }, quoteCharacter: '"' }), output); + test_minify(assert, input, { minifyJS: { mangle: false }, quoteCharacter: '"' }, output); input = ''; output = ''; - assert.equal(minify(input, { minifyJS: true }), output); - assert.equal(minify(input, { minifyJS: true, quoteCharacter: '\'' }), output); + test_minify(assert, input, { minifyJS: true }, output); + test_minify(assert, input, { minifyJS: true, quoteCharacter: '\'' }, output); input = ''; output = ''; - assert.equal(minify(input, { minifyJS: true, quoteCharacter: '"' }), output); + test_minify(assert, input, { minifyJS: true, quoteCharacter: '"' }, output); input = ''; output = ''; - assert.equal(minify(input, { minifyJS: true }), output); + test_minify(assert, input, { minifyJS: true }, output); input = ''; output = ''; - assert.equal(minify(input, { minifyJS: true }), output); - assert.equal(minify(input, { minifyJS: true, customEventAttributes: [] }), input); + test_minify(assert, input, { minifyJS: true }, output); + test_minify(assert, input, { minifyJS: true, customEventAttributes: [] }, input); output = ''; - assert.equal(minify(input, { minifyJS: true, customEventAttributes: [/^ng-/] }), output); + test_minify(assert, input, { minifyJS: true, customEventAttributes: [/^ng-/] }, output); output = ''; - assert.equal(minify(input, { minifyJS: true, customEventAttributes: [/^on/, /^ng-/] }), output); + test_minify(assert, input, { minifyJS: true, customEventAttributes: [/^on/, /^ng-/] }, output); input = '
    '; - assert.equal(minify(input, { minifyJS: true }), input); + test_minify(assert, input, { minifyJS: true }, input); input = '
    '; output = '
    '; - assert.equal(minify(input, { minifyJS: true }), output); + test_minify(assert, input, { minifyJS: true }, output); input = '
    '; output = '
    ")\'>
    '; - assert.equal(minify(input, { minifyJS: true }), output); + test_minify(assert, input, { minifyJS: true }, output); }); QUnit.test('escaping closing script tag', function(assert) { var input = ''; var output = ''; - assert.equal(minify(input, { minifyJS: true }), output); + test_minify(assert, input, { minifyJS: true }, output); }); QUnit.test('style minification', function(assert) { var input, output; input = 'div#foo { background-color: red; color: white }'; - assert.equal(minify(input, { minifyCSS: true }), input); + test_minify(assert, input, { minifyCSS: true }, input); input = ''; output = ''; - assert.equal(minify(input), input); - assert.equal(minify(input, { minifyCSS: true }), output); + test_minify(assert, input, input); + test_minify(assert, input, { minifyCSS: true }, output); input = ''; output = ''; - assert.equal(minify(input, { minifyCSS: true }), output); + test_minify(assert, input, { minifyCSS: true }, output); input = '
    '; - assert.equal(minify(input), input); + test_minify(assert, input, input); output = '
    '; - assert.equal(minify(input, { minifyCSS: true }), output); - assert.equal(minify(input, { + test_minify(assert, input, { minifyCSS: true }, output); + test_minify(assert, input, { collapseWhitespace: true, minifyCSS: true - }), output); + }, output); input = '
    '; - assert.equal(minify(input), input); + test_minify(assert, input, input); output = '
    '; - assert.equal(minify(input, { minifyCSS: true }), output); - assert.equal(minify(input, { + test_minify(assert, input, { minifyCSS: true }, output); + test_minify(assert, input, { collapseWhitespace: true, minifyCSS: true - }), output); + }, output); input = ''; - assert.equal(minify(input), input); + test_minify(assert, input, input); output = ''; - assert.equal(minify(input, { minifyCSS: true }), output); - assert.equal(minify(input, { + test_minify(assert, input, { minifyCSS: true }, output); + test_minify(assert, input, { collapseWhitespace: true, minifyCSS: true - }), output); + }, output); input = ''; - assert.equal(minify(input), input); + test_minify(assert, input, input); output = ''; - assert.equal(minify(input, { minifyCSS: true }), output); - assert.equal(minify(input, { + test_minify(assert, input, { minifyCSS: true }, output); + test_minify(assert, input, { collapseWhitespace: true, minifyCSS: true - }), output); + }, output); input = ''; - assert.equal(minify(input), input); + test_minify(assert, input, input); output = ''; - assert.equal(minify(input, { minifyCSS: true }), output); + test_minify(assert, input, { minifyCSS: true }, output); output = ''; - assert.equal(minify(input, { + test_minify(assert, input, { minifyCSS: true, removeAttributeQuotes: true - }), output); + }, output); input = ''; - assert.equal(minify(input), input); + test_minify(assert, input, input); output = ''; - assert.equal(minify(input, { minifyCSS: true }), output); + test_minify(assert, input, { minifyCSS: true }, output); output = ''; - assert.equal(minify(input, { + test_minify(assert, input, { minifyCSS: true, removeAttributeQuotes: true - }), output); + }, output); }); QUnit.test('style attribute minification', function(assert) { var input = '
    '; var output = '
    '; - assert.equal(minify(input, { minifyCSS: true }), output); + test_minify(assert, input, { minifyCSS: true }, output); }); QUnit.test('url attribute minification', function(assert) { @@ -2336,61 +2388,61 @@ QUnit.test('url attribute minification', function(assert) { input = '
    link
    '; output = '
    link
    '; - assert.equal(minify(input, { minifyURLs: 'http://website.com/folder/' }), output); - assert.equal(minify(input, { minifyURLs: { site: 'http://website.com/folder/' } }), output); + test_minify(assert, input, { minifyURLs: 'http://website.com/folder/' }, output); + test_minify(assert, input, { minifyURLs: { site: 'http://website.com/folder/' } }, output); input = ''; - assert.equal(minify(input, { minifyURLs: 'http://website.com/' }), input); - assert.equal(minify(input, { minifyURLs: { site: 'http://website.com/' } }), input); + test_minify(assert, input, { minifyURLs: 'http://website.com/' }, input); + test_minify(assert, input, { minifyURLs: { site: 'http://website.com/' } }, input); input = ''; - assert.equal(minify(input, { minifyURLs: 'http://website.com/' }), input); - assert.equal(minify(input, { minifyURLs: { site: 'http://website.com/' } }), input); + test_minify(assert, input, { minifyURLs: 'http://website.com/' }, input); + test_minify(assert, input, { minifyURLs: { site: 'http://website.com/' } }, input); output = ''; - assert.equal(minify(input, { minifyCSS: true }), output); + test_minify(assert, input, { minifyCSS: true }, output); output = ''; - assert.equal(minify(input, { + test_minify(assert, input, { minifyCSS: true, minifyURLs: 'http://website.com/' - }), output); - assert.equal(minify(input, { + }, output); + test_minify(assert, input, { minifyCSS: true, minifyURLs: { site: 'http://website.com/' } - }), output); + }, output); input = ''; - assert.equal(minify(input, { minifyURLs: { site: 'http://website.com/foo bar/' } }), input); + test_minify(assert, input, { minifyURLs: { site: 'http://website.com/foo bar/' } }, input); output = ''; - assert.equal(minify(input, { minifyCSS: true }), output); + test_minify(assert, input, { minifyCSS: true }, output); output = ''; - assert.equal(minify(input, { + test_minify(assert, input, { minifyCSS: true, minifyURLs: { site: 'http://website.com/foo bar/' } - }), output); + }, output); input = ''; - assert.equal(minify(input, { minifyURLs: { site: 'http://website.com/' } }), input); - assert.equal(minify(input, { minifyURLs: { site: 'http://website.com/foo%20bar/' } }), input); - assert.equal(minify(input, { minifyURLs: { site: 'http://website.com/foo%20bar/(baz)/' } }), input); + test_minify(assert, input, { minifyURLs: { site: 'http://website.com/' } }, input); + test_minify(assert, input, { minifyURLs: { site: 'http://website.com/foo%20bar/' } }, input); + test_minify(assert, input, { minifyURLs: { site: 'http://website.com/foo%20bar/(baz)/' } }, input); output = ''; - assert.equal(minify(input, { + test_minify(assert, input, { minifyCSS: true, minifyURLs: { site: 'http://website.com/' } - }), output); + }, output); output = ''; - assert.equal(minify(input, { + test_minify(assert, input, { minifyCSS: true, minifyURLs: { site: 'http://website.com/foo%20bar/' } - }), output); + }, output); output = ''; - assert.equal(minify(input, { + test_minify(assert, input, { minifyCSS: true, minifyURLs: { site: 'http://website.com/foo%20bar/(baz)/' } - }), output); + }, output); input = ''; output = ''; - assert.equal(minify(input, { minifyURLs: { site: 'http://site.com/' } }), output); + test_minify(assert, input, { minifyURLs: { site: 'http://site.com/' } }, output); }); QUnit.test('srcset attribute minification', function(assert) { @@ -2398,20 +2450,20 @@ QUnit.test('srcset attribute minification', function(assert) { input = ''; output = ''; - assert.equal(minify(input), output); + test_minify(assert, input, output); output = ''; - assert.equal(minify(input, { minifyURLs: { site: 'http://site.com/' } }), output); + test_minify(assert, input, { minifyURLs: { site: 'http://site.com/' } }, output); }); QUnit.test('valueless attributes', function(assert) { var input = '
    '; - assert.equal(minify(input), input); + test_minify(assert, input, input); }); QUnit.test('newlines becoming whitespaces', function(assert) { var input = 'test\n\n\n\ntest'; var output = 'test test'; - assert.equal(minify(input, { collapseWhitespace: true }), output); + test_minify(assert, input, { collapseWhitespace: true }, output); }); QUnit.test('conservative collapse', function(assert) { @@ -2419,115 +2471,115 @@ QUnit.test('conservative collapse', function(assert) { input = ' foo \n\n'; output = ' foo '; - assert.equal(minify(input, { + test_minify(assert, input, { collapseWhitespace: true, conservativeCollapse: true - }), output); + }, output); input = '\n\n\n\n'; output = ' '; - assert.equal(minify(input, { + test_minify(assert, input, { removeComments: true, collapseWhitespace: true, conservativeCollapse: true - }), output); + }, output); input = '

    \u00A0

    '; - assert.equal(minify(input, { collapseWhitespace: true }), input); - assert.equal(minify(input, { + test_minify(assert, input, { collapseWhitespace: true }, input); + test_minify(assert, input, { collapseWhitespace: true, conservativeCollapse: true - }), input); + }, input); input = '

    \u00A0

    '; output = '

    \u00A0

    '; - assert.equal(minify(input, { collapseWhitespace: true }), output); - assert.equal(minify(input, { + test_minify(assert, input, { collapseWhitespace: true }, output); + test_minify(assert, input, { collapseWhitespace: true, conservativeCollapse: true - }), output); + }, output); input = '

    \u00A0

    '; output = '

    \u00A0

    '; - assert.equal(minify(input, { collapseWhitespace: true }), output); - assert.equal(minify(input, { + test_minify(assert, input, { collapseWhitespace: true }, output); + test_minify(assert, input, { collapseWhitespace: true, conservativeCollapse: true - }), output); + }, output); input = '

    \u00A0

    '; output = '

    \u00A0

    '; - assert.equal(minify(input, { collapseWhitespace: true }), output); - assert.equal(minify(input, { + test_minify(assert, input, { collapseWhitespace: true }, output); + test_minify(assert, input, { collapseWhitespace: true, conservativeCollapse: true - }), output); + }, output); input = '

    \u00A0\u00A0 \u00A0

    '; output = '

    \u00A0\u00A0 \u00A0

    '; - assert.equal(minify(input, { collapseWhitespace: true }), output); - assert.equal(minify(input, { + test_minify(assert, input, { collapseWhitespace: true }, output); + test_minify(assert, input, { collapseWhitespace: true, conservativeCollapse: true - }), output); + }, output); input = '

    foo \u00A0\u00A0 \u00A0

    '; output = '

    foo \u00A0\u00A0 \u00A0

    '; - assert.equal(minify(input, { collapseWhitespace: true }), output); - assert.equal(minify(input, { + test_minify(assert, input, { collapseWhitespace: true }, output); + test_minify(assert, input, { collapseWhitespace: true, conservativeCollapse: true - }), output); + }, output); input = '

    \u00A0\u00A0 \u00A0 bar

    '; output = '

    \u00A0\u00A0 \u00A0 bar

    '; - assert.equal(minify(input, { collapseWhitespace: true }), output); - assert.equal(minify(input, { + test_minify(assert, input, { collapseWhitespace: true }, output); + test_minify(assert, input, { collapseWhitespace: true, conservativeCollapse: true - }), output); + }, output); input = '

    foo \u00A0\u00A0 \u00A0 bar

    '; output = '

    foo \u00A0\u00A0 \u00A0 bar

    '; - assert.equal(minify(input, { collapseWhitespace: true }), output); - assert.equal(minify(input, { + test_minify(assert, input, { collapseWhitespace: true }, output); + test_minify(assert, input, { collapseWhitespace: true, conservativeCollapse: true - }), output); + }, output); input = '

    \u00A0foo\u00A0\t

    '; output = '

    \u00A0foo\u00A0

    '; - assert.equal(minify(input, { collapseWhitespace: true }), output); - assert.equal(minify(input, { + test_minify(assert, input, { collapseWhitespace: true }, output); + test_minify(assert, input, { collapseWhitespace: true, conservativeCollapse: true - }), output); + }, output); input = '

    \u00A0\nfoo\u00A0\t

    '; output = '

    \u00A0 foo\u00A0

    '; - assert.equal(minify(input, { collapseWhitespace: true }), output); - assert.equal(minify(input, { + test_minify(assert, input, { collapseWhitespace: true }, output); + test_minify(assert, input, { collapseWhitespace: true, conservativeCollapse: true - }), output); + }, output); input = '

    \u00A0foo \u00A0\t

    '; output = '

    \u00A0foo \u00A0

    '; - assert.equal(minify(input, { collapseWhitespace: true }), output); - assert.equal(minify(input, { + test_minify(assert, input, { collapseWhitespace: true }, output); + test_minify(assert, input, { collapseWhitespace: true, conservativeCollapse: true - }), output); + }, output); input = '

    \u00A0\nfoo \u00A0\t

    '; output = '

    \u00A0 foo \u00A0

    '; - assert.equal(minify(input, { collapseWhitespace: true }), output); - assert.equal(minify(input, { + test_minify(assert, input, { collapseWhitespace: true }, output); + test_minify(assert, input, { collapseWhitespace: true, conservativeCollapse: true - }), output); + }, output); }); QUnit.test('collapse preseving a line break', function(assert) { @@ -2557,15 +2609,15 @@ QUnit.test('collapse preseving a line break', function(assert) { '\n' + '\n' + '\n\n

    \ntest test test\n

    \n'; - assert.equal(minify(input, { + test_minify(assert, input, { collapseWhitespace: true, preserveLineBreaks: true - }), output); - assert.equal(minify(input, { + }, output); + test_minify(assert, input, { collapseWhitespace: true, conservativeCollapse: true, preserveLineBreaks: true - }), output); + }, output); output = '\n\n\n' + '\n\n\n' + 'Carbon\n\n' + @@ -2577,140 +2629,140 @@ QUnit.test('collapse preseving a line break', function(assert) { '\n' + '\n' + '\n\n

    \ntest test test\n

    \n'; - assert.equal(minify(input, { + test_minify(assert, input, { collapseWhitespace: true, conservativeCollapse: true, preserveLineBreaks: true, removeComments: true - }), output); + }, output); input = '
    text \n text \n
    '; output = '
    text \ntext\n
    '; - assert.equal(minify(input, { + test_minify(assert, input, { collapseWhitespace: true, preserveLineBreaks: true - }), output); + }, output); input = '
    text \n
    '; output = '
    text\n
    '; - assert.equal(minify(input, { + test_minify(assert, input, { collapseWhitespace: true, preserveLineBreaks: true - }), output); + }, output); output = '
    text\n
    '; - assert.equal(minify(input, { + test_minify(assert, input, { collapseWhitespace: true, conservativeCollapse: true, preserveLineBreaks: true - }), output); + }, output); input = '
    \ntext
    '; output = '
    \ntext
    '; - assert.equal(minify(input, { + test_minify(assert, input, { collapseWhitespace: true, preserveLineBreaks: true - }), output); + }, output); output = '
    \ntext
    '; - assert.equal(minify(input, { + test_minify(assert, input, { collapseWhitespace: true, conservativeCollapse: true, preserveLineBreaks: true - }), output); + }, output); input = 'This is the start. <% ... %>\r\n<%= ... %>\r\n\r\n\r\nNo comment, but middle.\r\n\r\n\r\n\r\nHello, this is the end!'; output = 'This is the start. <% ... %>\n<%= ... %>\n\nNo comment, but middle.\n\n\n\nHello, this is the end!'; - assert.equal(minify(input, { + test_minify(assert, input, { removeComments: true, collapseWhitespace: true, preserveLineBreaks: true - }), output); + }, output); }); QUnit.test('collapse inline tag whitespace', function(assert) { var input, output; input = ' '; - assert.equal(minify(input, { + test_minify(assert, input, { collapseWhitespace: true - }), input); + }, input); output = ''; - assert.equal(minify(input, { + test_minify(assert, input, { collapseWhitespace: true, collapseInlineTagWhitespace: true - }), output); + }, output); input = '

    where R is the Rici tensor.

    '; output = '

    where R is the Rici tensor.

    '; - assert.equal(minify(input, { + test_minify(assert, input, { collapseWhitespace: true - }), output); + }, output); output = '

    whereRis the Rici tensor.

    '; - assert.equal(minify(input, { + test_minify(assert, input, { collapseWhitespace: true, collapseInlineTagWhitespace: true - }), output); + }, output); }); QUnit.test('ignore custom comments', function(assert) { var input, output; input = ''; - assert.equal(minify(input), input); - assert.equal(minify(input, { removeComments: true }), input); - assert.equal(minify(input, { ignoreCustomComments: false }), input); - assert.equal(minify(input, { + test_minify(assert, input, input); + test_minify(assert, input, { removeComments: true }, input); + test_minify(assert, input, { ignoreCustomComments: false }, input); + test_minify(assert, input, { removeComments: true, ignoreCustomComments: [] - }), ''); - assert.equal(minify(input, { + }, ''); + test_minify(assert, input, { removeComments: true, ignoreCustomComments: false - }), ''); + }, ''); input = 'test'; output = 'test'; - assert.equal(minify(input), output); - assert.equal(minify(input, { removeComments: true }), output); - assert.equal(minify(input, { ignoreCustomComments: false }), output); - assert.equal(minify(input, { + test_minify(assert, input, output); + test_minify(assert, input, { removeComments: true }, output); + test_minify(assert, input, { ignoreCustomComments: false }, output); + test_minify(assert, input, { removeComments: true, ignoreCustomComments: [] - }), output); - assert.equal(minify(input, { + }, output); + test_minify(assert, input, { removeComments: true, ignoreCustomComments: false - }), output); + }, output); input = '
  • test
  • '; - assert.equal(minify(input, { + test_minify(assert, input, { removeComments: true, // ignore knockout comments ignoreCustomComments: [ /^\s+ko/, /\/ko\s+$/ ] - }), input); + }, input); input = ''; - assert.equal(minify(input, { + test_minify(assert, input, { removeComments: true, // ignore Apache SSI includes ignoreCustomComments: [ /^\s*#/ ] - }), input); + }, input); }); QUnit.test('processScripts', function(assert) { var input = ''; var output = ''; - assert.equal(minify(input, { + test_minify(assert, input, { collapseWhitespace: true, removeComments: true, processScripts: ['text/ng-template'] - }), output); + }, output); }); QUnit.test('ignore', function(assert) { @@ -2720,10 +2772,10 @@ QUnit.test('ignore', function(assert) { '
    \n test foo \n\n
    '; output = '
    \n test foo \n\n
    ' + '
    test foo
    '; - assert.equal(minify(input, { collapseWhitespace: true }), output); + test_minify(assert, input, { collapseWhitespace: true }, output); input = ''; - assert.equal(minify(input), ''); + test_minify(assert, input, ''); input = '

    .....

    ' + '@for( $i = 0 ; $i < $criterions->count() ; $i++ )' + @@ -2735,23 +2787,23 @@ QUnit.test('ignore', function(assert) { '

    {{ $criterions[$i]->value }}

    ' + '@endfor' + '

    ....

    '; - assert.equal(minify(input, { removeComments: true }), output); + test_minify(assert, input, { removeComments: true }, output); input = '

    bar

    '; output = '

    bar

    '; - assert.equal(minify(input), output); + test_minify(assert, input, output); input = '>'; output = '>'; - assert.equal(minify(input, { ignoreCustomFragments: [/<\?php[\s\S]*?\?>/] }), output); + test_minify(assert, input, { ignoreCustomFragments: [/<\?php[\s\S]*?\?>/] }, output); input = 'a\nb'; output = 'a b'; - assert.equal(minify(input, { collapseWhitespace: true }), output); + test_minify(assert, input, { collapseWhitespace: true }, output); input = '

    foo \n\tbar\n.

    '; output = '

    foo \n\tbar\n.

    '; - assert.equal(minify(input, { collapseWhitespace: true }), output); + test_minify(assert, input, { collapseWhitespace: true }, output); }); QUnit.test('meta viewport', function(assert) { @@ -2759,36 +2811,36 @@ QUnit.test('meta viewport', function(assert) { input = ''; output = ''; - assert.equal(minify(input), output); + test_minify(assert, input, output); input = ''; output = ''; - assert.equal(minify(input), output); + test_minify(assert, input, output); input = ''; output = ''; - assert.equal(minify(input), output); + test_minify(assert, input, output); input = ''; output = ''; - assert.equal(minify(input), output); + test_minify(assert, input, output); }); QUnit.test('downlevel-revealed conditional comments', function(assert) { var input = ''; - assert.equal(minify(input), input); - assert.equal(minify(input, { removeComments: true }), input); + test_minify(assert, input, input); + test_minify(assert, input, { removeComments: true }, input); }); QUnit.test('noscript', function(assert) { var input; input = ''; - assert.equal(minify(input), ''); + test_minify(assert, input, ''); input = ''; - assert.equal(minify(input, { removeComments: true, collapseWhitespace: true, removeEmptyAttributes: true }), + test_minify(assert, input, { removeComments: true, collapseWhitespace: true, removeEmptyAttributes: true }, ''); }); @@ -2797,49 +2849,49 @@ QUnit.test('max line length', function(assert) { var options = { maxLineLength: 25 }; input = '
    '; - assert.equal(minify(input, options), '
    \n
    '); + test_minify(assert, input, options, '
    \n
    '); input = ' hello world \n world hello '; - assert.equal(minify(input, options), '\n hello world \n world hello \n'); + test_minify(assert, input, options, '\n hello world \n world hello \n'); - assert.equal(minify('

    x

    '), '

    x

    '); - assert.equal(minify('

    x

    '), '

    x

    '); - assert.equal(minify('

    x

    '), '

    x

    '); - assert.equal(minify('

    xxx

    '), '

    xxx

    '); - assert.equal(minify('

    xxx

    '), '

    xxx

    '); + test_minify(assert, '

    x

    ', '

    x

    '); + test_minify(assert, '

    x

    ', '

    x

    '); + test_minify(assert, '

    x

    ', '

    x

    '); + test_minify(assert, '

    xxx

    ', '

    xxx

    '); + test_minify(assert, '

    xxx

    ', '

    xxx

    '); input = '
    ' + 'i\'m 10 levels deep' + '
    '; - assert.equal(minify(input), input); + test_minify(assert, input, input); - assert.equal(minify('', options), ''); - assert.equal(minify('', options), ''); - assert.equal(minify('', options), ''); + test_minify(assert, '', options, ''); + test_minify(assert, '', options, ''); + test_minify(assert, '', options, ''); - assert.equal(minify('foo', options), 'foo\n'); - assert.equal(minify('

    x', options), '

    x

    '); - assert.equal(minify('

    x

    ', options), '

    x

    ', 'trailing quote should be ignored'); - assert.equal(minify('

    Click me

    ', options), '

    Click me\n

    '); - assert.equal(minify('', options), ''); - assert.equal(minify('
    [fallback image]
    ', options), + test_minify(assert, 'foo', options, 'foo\n'); + test_minify(assert, '

    x', options, '

    x

    '); + test_minify(assert, '

    x

    ', options, '

    x

    ', 'trailing quote should be ignored'); + test_minify(assert, '

    Click me

    ', options, '

    Click me\n

    '); + test_minify(assert, '', options, ''); + test_minify(assert, '
    [fallback image]
    ', options, '
    \n[fallback image]
    \n
    ' ); - assert.equal(minify('', options), '\n'); - assert.equal(minify('', options), '\n'); - assert.equal(minify('
    ', options), + test_minify(assert, '', options, '\n'); + test_minify(assert, '', options, '\n'); + test_minify(assert, '
    ', options, '\n
    ' ); - assert.equal(minify('', options), + test_minify(assert, '', options, '\n\n\n' ); - assert.equal(minify('[\']["]', options), '[\']["]'); - assert.equal(minify('
    hey
    ', options), '\n
    hey
    '); - assert.equal(minify(':) link', options), ':) \nlink'); + test_minify(assert, '[\']["]', options, '[\']["]'); + test_minify(assert, '
    hey
    ', options, '\n
    hey
    '); + test_minify(assert, ':) link', options, ':) \nlink'); - assert.equal(minify('ok', options), 'ok'); + test_minify(assert, 'ok', options, 'ok'); }); QUnit.test('custom attribute collapse', function(assert) { @@ -2847,24 +2899,24 @@ QUnit.test('custom attribute collapse', function(assert) { input = '
    foo
    '; - output = '
    foo
    '; + output = '
    foo
    '; - assert.equal(minify(input), input); - assert.equal(minify(input, { customAttrCollapse: /data-bind/ }), output); + test_minify(assert, input, input); + test_minify(assert, input, { customAttrCollapse: /data-bind/ }, output); input = '
    bar
    '; output = '
    bar
    '; - assert.equal(minify(input, { customAttrCollapse: /style/ }), output); + test_minify(assert, input, { customAttrCollapse: /style/ }, output); input = '
    ' + '
    '; output = '
    '; - assert.equal(minify(input, { customAttrCollapse: /ng-class/ }), output); + test_minify(assert, input, { customAttrCollapse: /ng-class/ }, output); }); QUnit.test('custom attribute collapse with empty attribute value', function(assert) { var input = '
    '; var output = '
    '; - assert.equal(minify(input, { customAttrCollapse: /.+/ }), output); + test_minify(assert, input, { customAttrCollapse: /.+/ }, output); }); QUnit.test('custom attribute collapse with newlines, whitespace, and carriage returns', function(assert) { @@ -2891,7 +2943,7 @@ QUnit.test('custom attribute collapse with newlines, whitespace, and carriage re ' value2:false \n\r' + ' }">'; var output = '
    '; - assert.equal(minify(input, { customAttrCollapse: /ng-class/ }), output); + test_minify(assert, input, { customAttrCollapse: /ng-class/ }, output); }); QUnit.test('do not escape attribute value', function(assert) { @@ -2900,23 +2952,23 @@ QUnit.test('do not escape attribute value', function(assert) { input = '
    \n"' + '}\'>'; - assert.equal(minify(input), input); - assert.equal(minify(input, { preventAttributesEscaping: true }), input); + test_minify(assert, input, input); + test_minify(assert, input, { preventAttributesEscaping: true }, input); input = '
    '; - assert.equal(minify(input, { preventAttributesEscaping: true }), input); + test_minify(assert, input, { preventAttributesEscaping: true }, input); output = '
    '; - assert.equal(minify(input), output); + test_minify(assert, input, output); }); QUnit.test('quoteCharacter is single quote', function(assert) { - assert.equal(minify('
    foo
    ', { quoteCharacter: '\'' }), '
    foo
    '); - assert.equal(minify('
    foo
    ', { quoteCharacter: '\'' }), '
    foo
    '); + test_minify(assert, '
    foo
    ', { quoteCharacter: '\'' }, '
    foo
    '); + test_minify(assert, '
    foo
    ', { quoteCharacter: '\'' }, '
    foo
    '); }); QUnit.test('quoteCharacter is not single quote or double quote', function(assert) { - assert.equal(minify('
    foo
    ', { quoteCharacter: 'm' }), '
    foo
    '); - assert.equal(minify('
    foo
    ', { quoteCharacter: 'm' }), '
    foo
    '); + test_minify(assert, '
    foo
    ', { quoteCharacter: 'm' }, '
    foo
    '); + test_minify(assert, '
    foo
    ', { quoteCharacter: 'm' }, '
    foo
    '); }); QUnit.test('remove space between attributes', function(assert) { @@ -2930,27 +2982,27 @@ QUnit.test('remove space between attributes', function(assert) { input = ''; output = ''; - assert.equal(minify(input, options), output); + test_minify(assert, input, options, output); input = ''; output = ''; - assert.equal(minify(input, options), output); + test_minify(assert, input, options, output); input = ''; output = ''; - assert.equal(minify(input, options), output); + test_minify(assert, input, options, output); input = ''; output = ''; - assert.equal(minify(input, options), output); + test_minify(assert, input, options, output); input = ''; output = ''; - assert.equal(minify(input, options), output); + test_minify(assert, input, options, output); input = ''; output = ''; - assert.equal(minify(input, options), output); + test_minify(assert, input, options, output); }); QUnit.test('markups from Angular 2', function(assert) { @@ -2976,7 +3028,7 @@ QUnit.test('markups from Angular 2', function(assert) { ' \n' + ' \n' + ''; - assert.equal(minify(input, { caseSensitive: true }), output); + test_minify(assert, input, { caseSensitive: true }, output); output = '' + @@ -2987,7 +3039,7 @@ QUnit.test('markups from Angular 2', function(assert) { '' + '' + ''; - assert.equal(minify(input, { + test_minify(assert, input, { caseSensitive: true, collapseBooleanAttributes: true, collapseWhitespace: true, @@ -3000,58 +3052,58 @@ QUnit.test('markups from Angular 2', function(assert) { removeStyleLinkTypeAttributes: true, removeTagWhitespace: true, useShortDoctype: true - }), output); + }, output); }); QUnit.test('auto-generated tags', function(assert) { var input, output; input = '

    '; - assert.equal(minify(input, { includeAutoGeneratedTags: false }), input); + test_minify(assert, input, { includeAutoGeneratedTags: false }, input); input = '

    x'; output = '

    x'; - assert.equal(minify(input, { includeAutoGeneratedTags: false }), output); + test_minify(assert, input, { includeAutoGeneratedTags: false }, output); output = '

    x

    '; - assert.equal(minify(input), output); - assert.equal(minify(input, { includeAutoGeneratedTags: true }), output); + test_minify(assert, input, output); + test_minify(assert, input, { includeAutoGeneratedTags: true }, output); input = '

    x'; output = '

    x'; - assert.equal(minify(input, { includeAutoGeneratedTags: false }), output); + test_minify(assert, input, { includeAutoGeneratedTags: false }, output); input = '

    '; output = '
    Well, look at me! I\'m a div!
    '; - assert.equal(minify(input, { html5: false, includeAutoGeneratedTags: false }), output); - assert.equal(minify('

    x', { + test_minify(assert, input, { html5: false, includeAutoGeneratedTags: false }, output); + test_minify(assert, '

    x', { maxLineLength: 25, includeAutoGeneratedTags: false - }), '

    x'); + }, '

    x'); input = '

    foo'; - assert.equal(minify(input, { includeAutoGeneratedTags: false }), input); - assert.equal(minify(input, { + test_minify(assert, input, { includeAutoGeneratedTags: false }, input); + test_minify(assert, input, { includeAutoGeneratedTags: false, removeOptionalTags: true - }), input); + }, input); input = '

    '; - assert.equal(minify(input, { includeAutoGeneratedTags: false }), input); + test_minify(assert, input, { includeAutoGeneratedTags: false }, input); output = ''; - assert.equal(minify(input, { + test_minify(assert, input, { includeAutoGeneratedTags: false, removeOptionalTags: true - }), output); + }, output); input = ''; - assert.equal(minify(input, { includeAutoGeneratedTags: false }), input); + test_minify(assert, input, { includeAutoGeneratedTags: false }, input); output = ''; - assert.equal(minify(input, { includeAutoGeneratedTags: true }), output); + test_minify(assert, input, { includeAutoGeneratedTags: true }, output); input = ''; - assert.equal(minify(input, { includeAutoGeneratedTags: false }), input); + test_minify(assert, input, { includeAutoGeneratedTags: false }, input); output = ''; - assert.equal(minify(input, { includeAutoGeneratedTags: true }), output); + test_minify(assert, input, { includeAutoGeneratedTags: true }, output); }); QUnit.test('sort attributes', function(assert) { @@ -3060,31 +3112,31 @@ QUnit.test('sort attributes', function(assert) { input = '' + '' + ''; - assert.equal(minify(input), input); - assert.equal(minify(input, { sortAttributes: false }), input); + test_minify(assert, input, input); + test_minify(assert, input, { sortAttributes: false }, input); output = '' + '' + ''; - assert.equal(minify(input, { sortAttributes: true }), output); + test_minify(assert, input, { sortAttributes: true }, output); input = '' + '' + ''; - assert.equal(minify(input), input); - assert.equal(minify(input, { sortAttributes: false }), input); + test_minify(assert, input, input); + test_minify(assert, input, { sortAttributes: false }, input); output = '' + '' + ''; - assert.equal(minify(input, { sortAttributes: true }), output); + test_minify(assert, input, { sortAttributes: true }, output); output = '' + '' + ''; - assert.equal(minify(input, { + test_minify(assert, input, { processScripts: [ 'text/html' ], sortAttributes: true - }), output); + }, output); input = '' + '' + @@ -3092,45 +3144,45 @@ QUnit.test('sort attributes', function(assert) { output = '' + '' + ''; - assert.equal(minify(input, { sortAttributes: true }), output); + test_minify(assert, input, { sortAttributes: true }, output); output = '' + '' + ''; - assert.equal(minify(input, { + test_minify(assert, input, { removeStyleLinkTypeAttributes: true, sortAttributes: true - }), output); + }, output); input = '
    ' + '' + '' + '' + ''; - assert.equal(minify(input), input); - assert.equal(minify(input, { sortAttributes: false }), input); + test_minify(assert, input, input); + test_minify(assert, input, { sortAttributes: false }, input); output = '' + '' + '' + '' + ''; - assert.equal(minify(input, { sortAttributes: true }), output); + test_minify(assert, input, { sortAttributes: true }, output); input = ' foo_bar>'; - assert.equal(minify(input, { + test_minify(assert, input, { ignoreCustomFragments: [/<#[\s\S]*?#>/] - }), input); - assert.equal(minify(input, { + }, input); + test_minify(assert, input, { ignoreCustomFragments: [/<#[\s\S]*?#>/], sortAttributes: false - }), input); + }, input); output = ' >'; - assert.equal(minify(input, { + test_minify(assert, input, { ignoreCustomFragments: [/<#[\s\S]*?#>/], sortAttributes: true - }), output); + }, output); input = ''; - assert.equal(minify(input, { sortAttributes: true }), input); + test_minify(assert, input, { sortAttributes: true }, input); }); QUnit.test('sort style classes', function(assert) { @@ -3141,125 +3193,125 @@ QUnit.test('sort style classes', function(assert) { '' + '' + ''; - assert.equal(minify(input), input); - assert.equal(minify(input, { sortClassName: false }), input); + test_minify(assert, input, input); + test_minify(assert, input, { sortClassName: false }, input); output = '' + '' + '' + '' + ''; - assert.equal(minify(input, { sortClassName: true }), output); + test_minify(assert, input, { sortClassName: true }, output); input = ''; output = ''; - assert.equal(minify(input), output); - assert.equal(minify(input, { sortClassName: false }), output); + test_minify(assert, input, output); + test_minify(assert, input, { sortClassName: false }, output); output = ''; - assert.equal(minify(input, { sortClassName: true }), output); + test_minify(assert, input, { sortClassName: true }, output); input = ''; - assert.equal(minify(input, { + test_minify(assert, input, { ignoreCustomFragments: [/<#[\s\S]*?#>/] - }), input); - assert.equal(minify(input, { + }, input); + test_minify(assert, input, { ignoreCustomFragments: [/<#[\s\S]*?#>/], sortClassName: false - }), input); - assert.equal(minify(input, { + }, input); + test_minify(assert, input, { ignoreCustomFragments: [/<#[\s\S]*?#>/], sortClassName: true - }), input); + }, input); input = ''; - assert.equal(minify(input, { sortClassName: false }), input); - assert.equal(minify(input, { sortClassName: true }), input); + test_minify(assert, input, { sortClassName: false }, input); + test_minify(assert, input, { sortClassName: true }, input); input = ''; - assert.equal(minify(input, { sortClassName: false }), input); + test_minify(assert, input, { sortClassName: false }, input); output = ''; - assert.equal(minify(input, { sortClassName: true }), output); + test_minify(assert, input, { sortClassName: true }, output); input = ''; - assert.equal(minify(input, { + test_minify(assert, input, { collapseWhitespace: true, ignoreCustomFragments: [/{{.*?}}/], removeAttributeQuotes: true, sortClassName: true - }), input); + }, input); input = ''; - assert.equal(minify(input, { + test_minify(assert, input, { collapseWhitespace: true, ignoreCustomFragments: [/{{.*?}}/], removeAttributeQuotes: true, sortClassName: true - }), input); + }, input); input = ''; - assert.equal(minify(input, { + test_minify(assert, input, { collapseWhitespace: true, ignoreCustomFragments: [/{{.*?}}/], removeAttributeQuotes: true, sortClassName: true - }), input); + }, input); input = ''; - assert.equal(minify(input, { + test_minify(assert, input, { collapseWhitespace: true, ignoreCustomFragments: [/{{.*?}}/], removeAttributeQuotes: true, sortClassName: true - }), input); + }, input); input = ''; output = ''; - assert.equal(minify(input, { + test_minify(assert, input, { collapseWhitespace: true, ignoreCustomFragments: [/{{.*?}}/], removeAttributeQuotes: true, sortClassName: true - }), output); + }, output); }); QUnit.test('decode entity characters', function(assert) { var input, output; input = ''; - assert.equal(minify(input), input); - assert.equal(minify(input, { decodeEntities: false }), input); - assert.equal(minify(input, { decodeEntities: true }), input); + test_minify(assert, input, input); + test_minify(assert, input, { decodeEntities: false }, input); + test_minify(assert, input, { decodeEntities: true }, input); input = ''; - assert.equal(minify(input), input); - assert.equal(minify(input, { decodeEntities: false }), input); - assert.equal(minify(input, { decodeEntities: true }), input); + test_minify(assert, input, input); + test_minify(assert, input, { decodeEntities: false }, input); + test_minify(assert, input, { decodeEntities: true }, input); output = ''; - assert.equal(minify(input, { decodeEntities: true, processScripts: ['text/html'] }), output); + test_minify(assert, input, { decodeEntities: true, processScripts: ['text/html'] }, output); input = '
    foo$
    '; - assert.equal(minify(input), input); - assert.equal(minify(input, { decodeEntities: false }), input); + test_minify(assert, input, input); + test_minify(assert, input, { decodeEntities: false }, input); output = '
    foo$
    '; - assert.equal(minify(input, { decodeEntities: true }), output); + test_minify(assert, input, { decodeEntities: true }, output); output = '
    foo$
    '; - assert.equal(minify(input, { minifyCSS: true }), output); - assert.equal(minify(input, { decodeEntities: false, minifyCSS: true }), output); + test_minify(assert, input, { minifyCSS: true }, output); + test_minify(assert, input, { decodeEntities: false, minifyCSS: true }, output); output = '
    foo$
    '; - assert.equal(minify(input, { decodeEntities: true, minifyCSS: true }), output); + test_minify(assert, input, { decodeEntities: true, minifyCSS: true }, output); input = 'baz<moo>©'; - assert.equal(minify(input), input); - assert.equal(minify(input, { decodeEntities: false }), input); + test_minify(assert, input, input); + test_minify(assert, input, { decodeEntities: false }, input); output = 'baz<moo>\u00a9'; - assert.equal(minify(input, { decodeEntities: true }), output); + test_minify(assert, input, { decodeEntities: true }, output); input = '&
    &
    '; - assert.equal(minify(input), input); - assert.equal(minify(input, { collapseWhitespace: false, decodeEntities: false }), input); - assert.equal(minify(input, { collapseWhitespace: true, decodeEntities: false }), input); + test_minify(assert, input, input); + test_minify(assert, input, { collapseWhitespace: false, decodeEntities: false }, input); + test_minify(assert, input, { collapseWhitespace: true, decodeEntities: false }, input); output = '&
    &
    '; - assert.equal(minify(input, { collapseWhitespace: false, decodeEntities: true }), output); - assert.equal(minify(input, { collapseWhitespace: true, decodeEntities: true }), output); + test_minify(assert, input, { collapseWhitespace: false, decodeEntities: true }, output); + test_minify(assert, input, { collapseWhitespace: true, decodeEntities: true }, output); }); QUnit.test('tests from PHPTAL', function(assert) { @@ -3341,7 +3393,7 @@ QUnit.test('tests from PHPTAL', function(assert) { 'foo ' ]*/ ].forEach(function(tokens) { - assert.equal(minify(tokens[1], { + test_minify(assert, tokens[1], { collapseBooleanAttributes: true, collapseWhitespace: true, removeAttributeQuotes: true, @@ -3354,7 +3406,7 @@ QUnit.test('tests from PHPTAL', function(assert) { removeTagWhitespace: true, sortAttributes: true, useShortDoctype: true - }), tokens[0]); + }, tokens[0]); }); }); @@ -3369,381 +3421,31 @@ QUnit.test('canCollapseWhitespace and canTrimWhitespace hooks', function(assert) var input = '
    foo bar
    '; var output = '
    foo bar
    '; - assert.equal(minify(input, { + test_minify(assert, input, { collapseWhitespace: true, canTrimWhitespace: canCollapseAndTrimWhitespace, canCollapseWhitespace: canCollapseAndTrimWhitespace - }), output); + }, output); // Regression test: Previously the first would clear the internal // stackNo{Collapse,Trim}Whitespace, so that ' foo bar' turned into ' foo bar' input = '
    foo bar
    '; output = '
    foo bar
    '; - assert.equal(minify(input, { + test_minify(assert, input, { collapseWhitespace: true, canTrimWhitespace: canCollapseAndTrimWhitespace, canCollapseWhitespace: canCollapseAndTrimWhitespace - }), output); + }, output); // Make sure that the stack does get reset when leaving the element for which // the hooks returned false: input = '
    foo bar
    '; output = '
    foo bar
    '; - assert.equal(minify(input, { + test_minify(assert, input, { collapseWhitespace: true, canTrimWhitespace: canCollapseAndTrimWhitespace, canCollapseWhitespace: canCollapseAndTrimWhitespace - }), output); -}); - -QUnit.test('style minification with callback', function(assert) { - var input = ''; - var output = ''; - var done = assert.async(); - assert.notOk(minify( - input, - { - minifyCSS: function(css, cb) { - setTimeout(function() { - cb(css + ' callback!'); - }, 0); - } - }, - function(error, result) { - assert.notOk(error); - assert.equal(result, output); - done(); - } - )); -}); - -QUnit.test('script minification with callback', function(assert) { - var input = ''; - var output = ''; - var done = assert.async(); - assert.notOk(minify( - input, - { - minifyJS: function(js, inline, cb) { - setTimeout(function() { - cb(js + '(function(){ console.log("World"); })()'); - }, 0); - } - }, - function(error, result) { - assert.notOk(error); - assert.equal(result, output); - done(); - } - )); -}); - -QUnit.test('style async minification with script sync minification', function(assert) { - var input = ''; - var output = ''; - var done = assert.async(); - assert.notOk(minify( - input, - { - minifyCSS: function(css, cb) { - setTimeout(function() { - cb(css + ' callback!'); - }, 0); - }, - minifyJS: true - }, - function(error, result) { - assert.notOk(error); - assert.equal(result, output); - done(); - } - )); -}); - -QUnit.test('style sync minification with script async minification', function(assert) { - var input = ''; - var output = ''; - var done = assert.async(); - assert.notOk(minify( - input, - { - minifyCSS: true, - minifyJS: function(js, inline, cb) { - setTimeout(function() { - cb(js + ' callback!'); - }, 0); - } - }, - function(error, result) { - assert.notOk(error); - assert.equal(result, output); - done(); - } - )); -}); - -QUnit.test('style async minification with script async minification', function(assert) { - var input = ''; - var output = ''; - var done = assert.async(); - assert.notOk(minify( - input, - { - minifyCSS: function(css, cb) { - setTimeout(function() { - cb(css + ' callback!'); - }, 0); - }, - minifyJS: function(js, inline, cb) { - setTimeout(function() { - cb(js + ' callback!'); - }, 0); - } - }, - function(error, result) { - assert.notOk(error); - assert.equal(result, output); - done(); - } - )); -}); - -QUnit.test('async minification alongside sync minification', function(assert) { - var input = ''; - var syncOutput = ''; - var asyncOutput = ''; - var done = assert.async(); - - assert.notOk(minify( - input, - { - minifyCSS: function(css, cb) { - setTimeout(function() { - cb(css + ' callback!'); - }, 0); - }, - minifyJS: function(js, inline, cb) { - setTimeout(function() { - cb(js + ' callback!'); - }, 0); - } - }, - function(error, result) { - assert.notOk(error); - assert.equal(result, asyncOutput); - done(); - } - )); - - assert.equal(minify(input, { - minifyCSS: true, - minifyJS: true - }), syncOutput); -}); - -QUnit.test('multiple async minifications', function(assert) { - var input = ''; - var output = ''; - var done = assert.async(2); - - assert.notOk(minify( - input, - { - minifyCSS: function(css, cb) { - setTimeout(function() { - cb(css + ' callback!'); - }, 0); - }, - minifyJS: function(js, inline, cb) { - setTimeout(function() { - cb(js + ' callback!'); - }, 0); - } - }, - function(error, result) { - assert.notOk(error); - assert.equal(result, output); - done(); - } - )); - - assert.notOk(minify( - input, - { - minifyCSS: function(css, cb) { - setTimeout(function() { - cb(css + ' callback!'); - }, 0); - }, - minifyJS: function(js, inline, cb) { - setTimeout(function() { - cb(js + ' callback!'); - }, 0); - } - }, - function(error, result) { - assert.notOk(error); - assert.equal(result, output); - done(); - } - )); -}); - -QUnit.test('sync minify with callback', function(assert) { - var input = 'TestHello World'; - var output = input; - var done = assert.async(); - assert.notOk(minify( - input, - {}, - function(error, result) { - assert.notOk(error); - assert.equal(result, output); - done(); - } - )); -}); - -QUnit.test('minify error with callback', function(assert) { - var input = ' Date: Wed, 18 Apr 2018 15:18:57 +1200 Subject: [PATCH 20/66] Fix potential issue with placeholder not being at the same index it was put at when it comes to replacing it with content. --- src/htmlminifier.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/htmlminifier.js b/src/htmlminifier.js index 388e9bdf..a2cbf118 100644 --- a/src/htmlminifier.js +++ b/src/htmlminifier.js @@ -1310,8 +1310,8 @@ function minify(value, options, partialMarkup, cb) { return; } - var insertIndex = buffer.length; - buffer.push(null); + var placeholder = {}; // Some unique object. + buffer.push(placeholder); // Create a new AsyncTask that will update the buffer once complete. asyncTasks.push( @@ -1319,7 +1319,9 @@ function minify(value, options, partialMarkup, cb) { asyncSubtasks, text, function(result) { - buffer[insertIndex] = result; + // The index of the placeholder may not be the same as where it + // was originally inserted at; therefore we need to search for it. + buffer[buffer.indexOf(placeholder)] = result; } ) ); From aa56a66f04de624a6a0fa33e93a6339a80bc447f Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Wed, 18 Apr 2018 16:26:51 +1200 Subject: [PATCH 21/66] Refactored. --- src/htmlminifier.js | 108 +++++++++++++++++++++++++++++--------------- 1 file changed, 72 insertions(+), 36 deletions(-) diff --git a/src/htmlminifier.js b/src/htmlminifier.js index a2cbf118..6d4fc93a 100644 --- a/src/htmlminifier.js +++ b/src/htmlminifier.js @@ -862,7 +862,7 @@ function minify(value, options, partialMarkup, cb) { * * @param {AsyncSubtask[]} tasks * @param {string} content - * @param {Function} cb + * @param {Function} cb */ function AsyncTask(tasks, content, cb) { this.tasks = tasks; @@ -871,47 +871,59 @@ function minify(value, options, partialMarkup, cb) { } /** - * Run the subtasks at the given index, giving it a callback to run the next - * subtask the same way. This therefore asynchronously runs all subtasks from - * the given index in series. + * Asynchronously runs all subtasks in this task in series. * * @private - * @param {string} content - * @param {number} index + * @param {Function} cb */ - AsyncTask.prototype.runSubtask = function(content, index) { - if (index < this.tasks.length) { - try { - this.tasks[index].exec( - content, - function(result) { - if (this.tasks[index].cbExecuted) { - throw new Error('Async completion has already occurred.'); - } - this.tasks[index].cbExecuted = true; + AsyncTask.prototype.execSubtaskChain = function(cb) { + /** + * Run the subtask at the given index, giving it a callback to run the next + * subtask the same way. + * + * @param {string} content + * @param {number} index + */ + (function implementation(content, index) { + if (index < this.tasks.length) { + try { + this.tasks[index].exec( + content, + function(result) { + if (this.tasks[index].cbExecuted) { + throw new Error('Async completion has already occurred.'); + } + this.tasks[index].cbExecuted = true; - this.runSubtask(result, index + 1); - }.bind(this) - ); - } - catch (error) { - cb(error); + implementation.call(this, result, index + 1, cb); + }.bind(this) + ); + } + catch (error) { + cb.call(this, error); + } } - } - else { - this.cb(content); - if (++asyncTasksComplete === asyncTasks.length) { - cb(null, finalize()); + else { + cb.call(this, null, content); } - } + }.bind(this))(this.content, 0); }; /** * Execute this task. + * + * @param {Function} cb */ - AsyncTask.prototype.exec = function() { - // Recursively run all subtasks. - this.runSubtask(this.content, 0); + AsyncTask.prototype.exec = function(cb) { + // Execute all subtasks. + this.execSubtaskChain(function(error, result) { + if (typeof this.cb === 'function') { + this.cb(error, result); + } + if (typeof cb === 'function') { + cb(error, result); + } + }); }; /** @@ -1318,7 +1330,12 @@ function minify(value, options, partialMarkup, cb) { new AsyncTask( asyncSubtasks, text, - function(result) { + function(error, result) { + // Don't do anything if there is an error. + if (error) { + return; + } + // The index of the placeholder may not be the same as where it // was originally inserted at; therefore we need to search for it. buffer[buffer.indexOf(placeholder)] = result; @@ -1415,20 +1432,39 @@ function minify(value, options, partialMarkup, cb) { return finalize(); } - // No async tasks? - if (asyncTasks.length === 0) { + function callCallBack() { try { cb(null, finalize()); } catch (error) { cb(error); } - return; + } + + // No async tasks? + if (asyncTasks.length === 0) { + return callCallBack(); + } + + var asyncTasksCallbackCalled = false; + function onAsyncTasksComplete(error) { + // If an error occurs immediately call the callback. + // If other tasks complete afterwards, ignore them. + if (!asyncTasksCallbackCalled) { + if (error) { + cb(error); + asyncTasksCallbackCalled = true; + return; + } + if (++asyncTasksComplete === asyncTasks.length) { + return callCallBack(); + } + } } // Execute all the async tasks. for (var i = 0; i < asyncTasks.length; i++) { - asyncTasks[i].exec(); + asyncTasks[i].exec(onAsyncTasksComplete); } return; } From f82ca4a7326828c1bc187296bdfd8e6222c3c0b2 Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Wed, 18 Apr 2018 16:53:54 +1200 Subject: [PATCH 22/66] Asynchronously tests now give more helpful feedback when an error occurs. --- tests/minifier.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/minifier.js b/tests/minifier.js index 1bfee7e0..d733f7d8 100644 --- a/tests/minifier.js +++ b/tests/minifier.js @@ -52,7 +52,15 @@ function test_minify(assert, input, options, output, description) { // Asynchronously test. assert.notOk(minify(input, options, function(error, result) { - assert.notOk(error); + // Error should be null + if (error !== null) { + if (error instanceof Error) { + assert.equal(error, null, 'An error occurred - stack trace:\n' + error.stack); + } + else { + assert.equal(error, null, 'Something that\'s not of type Error was returned as an error.'); + } + } assert.equal(result, output, 'Asynchronous Test: ' + description); done(); })); From 314c4b82809b088b464ffab6b40d90dcf718cb15 Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Wed, 18 Apr 2018 17:42:21 +1200 Subject: [PATCH 23/66] Created a test_minify_error function to test for expected errors. --- tests/minifier.js | 71 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 57 insertions(+), 14 deletions(-) diff --git a/tests/minifier.js b/tests/minifier.js index d733f7d8..3d517461 100644 --- a/tests/minifier.js +++ b/tests/minifier.js @@ -55,10 +55,10 @@ function test_minify(assert, input, options, output, description) { // Error should be null if (error !== null) { if (error instanceof Error) { - assert.equal(error, null, 'An error occurred - stack trace:\n' + error.stack); + assert.equal(error, null, 'Asynchronous Test: An error occurred - stack trace:\n' + error.stack); } else { - assert.equal(error, null, 'Something that\'s not of type Error was returned as an error.'); + assert.ok(false, 'Asynchronous Test: Something that\'s not of type Error was returned as an error.'); } } assert.equal(result, output, 'Asynchronous Test: ' + description); @@ -66,6 +66,47 @@ function test_minify(assert, input, options, output, description) { })); } +/** + * Test the minify function both synchronously and asynchronously for an expected error. + * + * @param {QUnit.assert} assert + * @param {string} input + * @param {Object} options + * @param {Error|Class|RegExp|Function} [errorMatcher] + * @param {string} [description] + */ +function test_minify_error(assert, input, options, errorMatcher, description) { + // Remove optional errorMatcher parameter if it is not given. + if (typeof errorMatcher === 'string') { + description = errorMatcher; + errorMatcher = null; + } + + // Set default description as input. + if (typeof description === 'undefined') { + description = input; + } + + // Synchronously test. + assert.throws(function() { minify(input, options); }, errorMatcher, 'Synchronous Test: ' + description); + + // Asynchronously test. + var done = assert.async(); + assert.notOk(minify(input, options, function(error, result) { + if (error === null) { + assert.ok(false, 'Asynchronous Test: An error should have occurred.'); + } + else if (error instanceof Error) { + assert.throws(function() { throw error; }, errorMatcher, 'Asynchronous Test: ' + description); + } + else { + assert.ok(false, 'Asynchronous Test: Something that\'s not of type Error was returned as an error.'); + } + assert.notOk(result); + done(); + })); +} + QUnit.test('`minifiy` exists', function(assert) { assert.ok(minify); }); @@ -121,9 +162,7 @@ QUnit.test('parsing non-trivial markup', function(assert) { test_minify(assert, input, input); input = '<$unicorn>'; - assert.throws(function() { - minify(input); - }, 'Invalid tag name'); + test_minify_error(assert, input, {}, 'Invalid tag name'); input = ''; test_minify(assert, input, input); @@ -153,9 +192,12 @@ QUnit.test('parsing non-trivial markup', function(assert) { // https://github.com/kangax/html-minifier/issues/507 input = ''; test_minify(assert, input, input); - assert.throws(function() { - minify(''); - }, 'invalid attribute name'); + test_minify_error( + assert, + '', + {}, + 'invalid attribute name' + ); // https://github.com/kangax/html-minifier/issues/512 input = ''; test_minify(assert, input, input); - assert.throws(function() { - minify( - '' + ' placeholder="YYYY-MM-DD"' + ' date-range-picker' + ' data-ng-model="vm.value"' + ' data-ng-model-options="{ debounce: 1000 }"' + ' data-ng-pattern="vm.options.format"' + - ' data-options="vm.datepickerOptions">' - ); - }, 'HTML comment inside tag'); + ' data-options="vm.datepickerOptions">', + {}, + 'HTML comment inside tag' + ); input = '
    '; output = '
    '; From 5bcb767e0e1d65208e87937122cb9d2dc05372ba Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Wed, 18 Apr 2018 17:43:55 +1200 Subject: [PATCH 24/66] Fixed issue with code still executing after callback. --- src/htmlminifier.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/htmlminifier.js b/src/htmlminifier.js index 6d4fc93a..c223ddb0 100644 --- a/src/htmlminifier.js +++ b/src/htmlminifier.js @@ -1506,19 +1506,17 @@ exports.minify = function(value, options, cb) { if (error) { if (hasCallback) { cb(error); + return; } - else { - throw error; - } + throw error; } options.log('minified in: ' + (Date.now() - start) + 'ms'); if (hasCallback) { cb(null, result); + return; } - else { - minified = result; - } + minified = result; }); return minified; }; From 3f2bc2439570e11f8e642ce82998fb940ad5138d Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Wed, 18 Apr 2018 19:34:52 +1200 Subject: [PATCH 25/66] Initial step to get normalizeAttr working with a callback. --- src/htmlminifier.js | 109 ++++++++++++++++++++++++++++++++------------ 1 file changed, 81 insertions(+), 28 deletions(-) diff --git a/src/htmlminifier.js b/src/htmlminifier.js index c223ddb0..930babe1 100644 --- a/src/htmlminifier.js +++ b/src/htmlminifier.js @@ -521,7 +521,7 @@ function canTrimWhitespace(tag) { return !/^(?:pre|textarea)$/.test(tag); } -function normalizeAttr(attr, attrs, tag, options) { +function normalizeAttr(attr, attrs, tag, options, cb) { var attrName = options.caseSensitive ? attr.name : attr.name.toLowerCase(), attrValue = attr.value; @@ -535,25 +535,25 @@ function normalizeAttr(attr, attrs, tag, options) { attrName === 'type' && isScriptTypeAttribute(attrValue) || options.removeStyleLinkTypeAttributes && (tag === 'style' || tag === 'link') && attrName === 'type' && isStyleLinkTypeAttribute(attrValue)) { - return; + return cb(); } attrValue = cleanAttributeValue(tag, attrName, attrValue, options, attrs); if (options.removeEmptyAttributes && canDeleteEmptyAttribute(tag, attrName, attrValue, options)) { - return; + return cb(); } if (options.decodeEntities && attrValue) { attrValue = attrValue.replace(/&(#?[0-9a-zA-Z]+;)/g, '&$1'); } - return { + return cb(null, { attr: attr, name: attrName, value: attrValue - }; + }); } function buildAttr(normalized, hasUnarySlash, options, isLast, uidAttr) { @@ -889,7 +889,11 @@ function minify(value, options, partialMarkup, cb) { try { this.tasks[index].exec( content, - function(result) { + function(error, result) { + if (error) { + throw error; + } + if (this.tasks[index].cbExecuted) { throw new Error('Async completion has already occurred.'); } @@ -946,7 +950,7 @@ function minify(value, options, partialMarkup, cb) { // Finished synchronously? if (typeof result !== 'undefined') { // Call the callback manually. - cb(result); + cb(null, result); } }; @@ -1130,29 +1134,78 @@ function minify(value, options, partialMarkup, cb) { options.sortAttributes(tag, attrs); } - var parts = []; - for (var i = attrs.length, isLast = true; --i >= 0;) { - var normalized = normalizeAttr(attrs[i], attrs, tag, options); - if (normalized) { - parts.unshift(buildAttr(normalized, hasUnarySlash, options, isLast, uidAttr)); - isLast = false; - } - } - if (parts.length > 0) { - buffer.push(' '); - buffer.push.apply(buffer, parts); - } - // start tag must never be omitted if it has any attributes - else if (optional && optionalStartTags(tag)) { - optionalStartTag = tag; - } + var placeholder = {}; // Some unique object. + buffer.push(placeholder); - buffer.push(buffer.pop() + (hasUnarySlash ? '/' : '') + '>'); + // Create a new AsyncTask that will update the buffer once complete. + asyncTasks.push( + new AsyncTask( + [new AsyncSubtask(function(content, cb) { + var parts = []; + var isLast = true; + + // Loop through all the attributes and normalize them. + return (function normalizeAttrLoop(i) { + // Attributes to normalize? + if (--i >= 0) { + var loopResult; + // Normalize all the attributes in series. + normalizeAttr(attrs[i], attrs, tag, options, function(error, normalized) { + if (error) { + cb(error); + return; + } + + if (normalized) { + parts.unshift(buildAttr(normalized, hasUnarySlash, options, isLast, uidAttr)); + isLast = false; + } + + loopResult = normalizeAttrLoop(i); + }); + return loopResult; + } - if (autoGenerated && !options.includeAutoGeneratedTags) { - removeStartTag(); - optionalStartTag = ''; - } + // Attributes all normalize? + var bufferChanges = []; + + if (parts.length > 0) { + bufferChanges.push(' '); + bufferChanges.push.apply(bufferChanges, parts); + } + // start tag must never be omitted if it has any attributes + else if (optional && optionalStartTags(tag)) { + optionalStartTag = tag; + } + + if (bufferChanges.length > 0) { + bufferChanges.push(bufferChanges.pop() + (hasUnarySlash ? '/' : '') + '>'); + } + else { + bufferChanges.push((hasUnarySlash ? '/' : '') + '>'); + } + + if (autoGenerated && !options.includeAutoGeneratedTags) { + removeStartTag(); + optionalStartTag = ''; + } + + return bufferChanges; + })(attrs.length); + })], + null, + function(error, result) { + // Don't do anything if there is an error. + if (error) { + return; + } + + // The index of the placeholder may not be the same as where it + // was originally inserted at; therefore we need to search for it. + buffer.splice.apply(buffer, [buffer.indexOf(placeholder), 1].concat(result)); + } + ) + ); }, end: function(tag, attrs, autoGenerated) { var lowerTag = tag.toLowerCase(); From 0a5e9b826232cb35198e933bd75ca5f49aebdde8 Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Wed, 18 Apr 2018 21:39:16 +1200 Subject: [PATCH 26/66] Fixed conversion from sync to async minifyJS and minifyCSS. --- tests/minifier.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/minifier.js b/tests/minifier.js index 3d517461..c6fbd410 100644 --- a/tests/minifier.js +++ b/tests/minifier.js @@ -37,14 +37,14 @@ function test_minify(assert, input, options, output, description) { if (typeof options.minifyJS === 'function') { var minifyJS = options.minifyJS; options.minifyJS = function(text, inline, callback) { - callback(minifyJS(text, inline)); + callback(null, minifyJS(text, inline)); }; } // Convert `minifyCSS` to use a callback. if (typeof options.minifyCSS === 'function') { var minifyCSS = options.minifyCSS; options.minifyCSS = function(text, type, callback) { - callback(minifyCSS(text, type)); + callback(null, minifyCSS(text, type)); }; } } From fe5da2d1eed09d32e2cce4ff5f738d75928777d1 Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Wed, 18 Apr 2018 21:40:01 +1200 Subject: [PATCH 27/66] Refactored. --- src/htmlminifier.js | 227 ++++++++++++++++++++++---------------------- 1 file changed, 111 insertions(+), 116 deletions(-) diff --git a/src/htmlminifier.js b/src/htmlminifier.js index 930babe1..2902dbf5 100644 --- a/src/htmlminifier.js +++ b/src/htmlminifier.js @@ -843,7 +843,7 @@ function minify(value, options, partialMarkup, cb) { /** * Set of tasks to perform asynchronously. * - * @type {AsyncTask[]} + * @type {Array} */ var asyncTasks = []; @@ -855,40 +855,57 @@ function minify(value, options, partialMarkup, cb) { var asyncTasksComplete = 0; /** - * A task that will be executed asynchronously after all the synchronous - * code has executed. + * A placeholder that can be inserted into the buffer in place of a string. + * + * Placeholder objects in the buffer will be removed by async tasks before + * completion of the `minify` function. + * + * @constructor + */ + function Placeholder() {} + + /** + * A group of AsyncTasks to execute in series. * * @constructor * - * @param {AsyncSubtask[]} tasks - * @param {string} content - * @param {Function} cb + * @param {AsyncTask[]} tasks + * @param {*} data + * @param {Function} cb */ - function AsyncTask(tasks, content, cb) { + function AsyncTaskGroup(tasks, data, cb) { this.tasks = tasks; - this.content = content; + this.data = data; this.cb = cb; } /** - * Asynchronously runs all subtasks in this task in series. + * Asynchronously runs all tasks in this group in series. * - * @private - * @param {Function} cb + * @param {Function} cb */ - AsyncTask.prototype.execSubtaskChain = function(cb) { + AsyncTaskGroup.prototype.exec = function(cb) { + function multiCb(error, result) { + if (typeof this.cb === 'function') { + this.cb(error, result); + } + if (typeof cb === 'function') { + cb(error, result); + } + } + /** - * Run the subtask at the given index, giving it a callback to run the next - * subtask the same way. + * Run the task at the given index, giving it a callback to run the next + * task the same way. * - * @param {string} content + * @param {string} data * @param {number} index */ - (function implementation(content, index) { + (function implementation(data, index) { if (index < this.tasks.length) { try { + this.tasks[index].data = data; this.tasks[index].exec( - content, function(error, result) { if (error) { throw error; @@ -899,59 +916,40 @@ function minify(value, options, partialMarkup, cb) { } this.tasks[index].cbExecuted = true; - implementation.call(this, result, index + 1, cb); + implementation.call(this, result, index + 1); }.bind(this) ); } catch (error) { - cb.call(this, error); + multiCb.call(this, error); } } else { - cb.call(this, null, content); + multiCb.call(this, null, data); } - }.bind(this))(this.content, 0); + }.bind(this))(this.data, 0); }; /** - * Execute this task. - * - * @param {Function} cb - */ - AsyncTask.prototype.exec = function(cb) { - // Execute all subtasks. - this.execSubtaskChain(function(error, result) { - if (typeof this.cb === 'function') { - this.cb(error, result); - } - if (typeof cb === 'function') { - cb(error, result); - } - }); - }; - - /** - * A subtask in an AsyncTask. + * An async task. * * @constructor * - * @param {Function>} task + * @param {Function>} task + * @param {*} [data] */ - function AsyncSubtask(task) { + function AsyncTask(task, data) { this.task = task; + this.data = data; } /** - * Execute this subtask. + * Execute this task. + * + * @param {Function} cb */ - AsyncSubtask.prototype.exec = function(content, cb) { - var result = this.task(content, cb); - - // Finished synchronously? - if (typeof result !== 'undefined') { - // Call the callback manually. - cb(null, result); - } + AsyncTask.prototype.exec = function(cb) { + this.task(this.data, cb); }; // temporarily replace ignored chunks with comments, @@ -1134,77 +1132,68 @@ function minify(value, options, partialMarkup, cb) { options.sortAttributes(tag, attrs); } - var placeholder = {}; // Some unique object. + var placeholder = new Placeholder(); // Some unique reference. buffer.push(placeholder); - // Create a new AsyncTask that will update the buffer once complete. + // Create a new AsyncTask that will update the buffer. asyncTasks.push( - new AsyncTask( - [new AsyncSubtask(function(content, cb) { - var parts = []; - var isLast = true; - - // Loop through all the attributes and normalize them. - return (function normalizeAttrLoop(i) { - // Attributes to normalize? - if (--i >= 0) { - var loopResult; - // Normalize all the attributes in series. - normalizeAttr(attrs[i], attrs, tag, options, function(error, normalized) { - if (error) { - cb(error); - return; - } - - if (normalized) { - parts.unshift(buildAttr(normalized, hasUnarySlash, options, isLast, uidAttr)); - isLast = false; - } - - loopResult = normalizeAttrLoop(i); - }); - return loopResult; - } + new AsyncTask(function(data, cb) { + var parts = []; + var isLast = true; + + // Loop through all the attributes and normalize them. + (function normalizeAttrLoop(i) { + // Attributes to normalize? + if (--i >= 0) { + var innerLoopResult; + // Normalize all the attributes in series. + normalizeAttr(attrs[i], attrs, tag, options, function(error, normalized) { + if (error) { + cb(error); + return; + } - // Attributes all normalize? - var bufferChanges = []; + if (normalized) { + parts.unshift(buildAttr(normalized, hasUnarySlash, options, isLast, uidAttr)); + isLast = false; + } - if (parts.length > 0) { - bufferChanges.push(' '); - bufferChanges.push.apply(bufferChanges, parts); - } - // start tag must never be omitted if it has any attributes - else if (optional && optionalStartTags(tag)) { - optionalStartTag = tag; - } + innerLoopResult = normalizeAttrLoop(i); + }); + return innerLoopResult; + } - if (bufferChanges.length > 0) { - bufferChanges.push(bufferChanges.pop() + (hasUnarySlash ? '/' : '') + '>'); - } - else { - bufferChanges.push((hasUnarySlash ? '/' : '') + '>'); - } + // Attributes all normalize? + var bufferChanges = []; - if (autoGenerated && !options.includeAutoGeneratedTags) { - removeStartTag(); - optionalStartTag = ''; - } + if (parts.length > 0) { + bufferChanges.push(' '); + bufferChanges.push.apply(bufferChanges, parts); + } + // start tag must never be omitted if it has any attributes + else if (optional && optionalStartTags(tag)) { + optionalStartTag = tag; + } - return bufferChanges; - })(attrs.length); - })], - null, - function(error, result) { - // Don't do anything if there is an error. - if (error) { - return; + if (bufferChanges.length > 0) { + bufferChanges.push(bufferChanges.pop() + (hasUnarySlash ? '/' : '') + '>'); + } + else { + bufferChanges.push((hasUnarySlash ? '/' : '') + '>'); + } + + if (autoGenerated && !options.includeAutoGeneratedTags) { + removeStartTag(); + optionalStartTag = ''; } + // Update the buffer. // The index of the placeholder may not be the same as where it // was originally inserted at; therefore we need to search for it. - buffer.splice.apply(buffer, [buffer.indexOf(placeholder), 1].concat(result)); - } - ) + buffer.splice.apply(buffer, [buffer.indexOf(placeholder), 1].concat(bufferChanges)); + return cb(); + })(attrs.length); + }) ); }, end: function(tag, attrs, autoGenerated) { @@ -1330,13 +1319,19 @@ function minify(value, options, partialMarkup, cb) { text = processScript(text, options, currentAttrs); } if (isExecutableScript(currentTag, currentAttrs)) { - asyncSubtasks.push(new AsyncSubtask(function(content, cb) { - return options.minifyJS(content, null, cb); + asyncSubtasks.push(new AsyncTask(function(data, cb) { + var result = options.minifyJS(data, null, cb); + if (typeof result !== 'undefined') { + cb(null, result); + } })); } if (isStyleSheet(currentTag, currentAttrs)) { - asyncSubtasks.push(new AsyncSubtask(function(content, cb) { - return options.minifyCSS(content, null, cb); + asyncSubtasks.push(new AsyncTask(function(data, cb) { + var result = options.minifyCSS(data, null, cb); + if (typeof result !== 'undefined') { + cb(null, result); + } })); } if (options.removeOptionalTags && text) { @@ -1375,12 +1370,12 @@ function minify(value, options, partialMarkup, cb) { return; } - var placeholder = {}; // Some unique object. + var placeholder = new Placeholder(); // Some unique reference. buffer.push(placeholder); - // Create a new AsyncTask that will update the buffer once complete. + // Create a new AsyncTaskGroup that will update the buffer once complete. asyncTasks.push( - new AsyncTask( + new AsyncTaskGroup( asyncSubtasks, text, function(error, result) { From f23648e0c0243326944e39c51de920202404e340 Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Thu, 19 Apr 2018 12:52:47 +1200 Subject: [PATCH 28/66] Async start tasks now modifies the buffer inplace. --- src/htmlminifier.js | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/htmlminifier.js b/src/htmlminifier.js index 0ae433e0..686ef5d3 100644 --- a/src/htmlminifier.js +++ b/src/htmlminifier.js @@ -1163,34 +1163,33 @@ function minify(value, options, partialMarkup, cb) { return innerLoopResult; } - // Attributes all normalize? - var bufferChanges = []; + // All attributes are now normalize. + + // The index of the placeholder may not be the same as where it + // was originally inserted at; therefore we need to search for it. + var insertionIndex = buffer.indexOf(placeholder); + + // Remove the placeholder. + buffer.splice(insertionIndex, 1); if (parts.length > 0) { - bufferChanges.push(' '); - bufferChanges.push.apply(bufferChanges, parts); + buffer.splice.apply(buffer, [insertionIndex, 0, ' '].concat(parts)); + insertionIndex += 1 + parts.length; } // start tag must never be omitted if it has any attributes else if (optional && optionalStartTags(tag)) { optionalStartTag = tag; } - if (bufferChanges.length > 0) { - bufferChanges.push(bufferChanges.pop() + (hasUnarySlash ? '/' : '') + '>'); - } - else { - bufferChanges.push((hasUnarySlash ? '/' : '') + '>'); - } + // Remove the last inserted element, modify it and put it back. + var lastElem = buffer.splice(--insertionIndex, 1)[0]; + buffer.splice(insertionIndex++, 0, lastElem + (hasUnarySlash ? '/' : '') + '>'); if (autoGenerated && !options.includeAutoGeneratedTags) { removeStartTag(); optionalStartTag = ''; } - // Update the buffer. - // The index of the placeholder may not be the same as where it - // was originally inserted at; therefore we need to search for it. - buffer.splice.apply(buffer, [buffer.indexOf(placeholder), 1].concat(bufferChanges)); return cb(); })(attrs.length); }) From 37b4ea7088ec5be211af6936b235b0e9fe6a276a Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Thu, 19 Apr 2018 13:20:09 +1200 Subject: [PATCH 29/66] removeStartTag and removeEndTag now take an indexBound which prevents modification to the buffer at or past its value. --- src/htmlminifier.js | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/htmlminifier.js b/src/htmlminifier.js index 686ef5d3..9b84317e 100644 --- a/src/htmlminifier.js +++ b/src/htmlminifier.js @@ -1018,20 +1018,28 @@ function minify(value, options, partialMarkup, cb) { return options.canTrimWhitespace(tag, attrs, canTrimWhitespace); } - function removeStartTag() { - var index = buffer.length - 1; + function removeStartTag(indexBound) { + if (typeof indexBound === 'undefined') { + indexBound = buffer.length; + } + + var index = indexBound - 1; while (index > 0 && !/^<[^/!]/.test(buffer[index])) { index--; } - buffer.length = Math.max(0, index); + return buffer.splice(index, indexBound - index).length; } - function removeEndTag() { - var index = buffer.length - 1; + function removeEndTag(indexBound) { + if (typeof indexBound === 'undefined') { + indexBound = buffer.length; + } + + var index = indexBound - 1; while (index > 0 && !/^<\//.test(buffer[index])) { index--; } - buffer.length = Math.max(0, index); + return buffer.splice(index, indexBound - index).length; } // look for trailing whitespaces, bypass any inline tags @@ -1186,7 +1194,7 @@ function minify(value, options, partialMarkup, cb) { buffer.splice(insertionIndex++, 0, lastElem + (hasUnarySlash ? '/' : '') + '>'); if (autoGenerated && !options.includeAutoGeneratedTags) { - removeStartTag(); + insertionIndex -= removeStartTag(insertionIndex); optionalStartTag = ''; } From cebb7177a2a51c139a2e3aa030e0403f64b11953 Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Thu, 19 Apr 2018 17:55:02 +1200 Subject: [PATCH 30/66] Added callbacks to more functions and wrapped them in AsyncTasks. --- src/htmlminifier.js | 875 ++++++++++++++++++++++++-------------------- 1 file changed, 478 insertions(+), 397 deletions(-) diff --git a/src/htmlminifier.js b/src/htmlminifier.js index 9b84317e..81b7f955 100644 --- a/src/htmlminifier.js +++ b/src/htmlminifier.js @@ -358,20 +358,22 @@ function unwrapMediaQuery(text) { return matches ? matches[1] : text; } -function cleanConditionalComment(comment, options) { +function cleanConditionalComment(comment, options, cb) { return options.processConditionalComments ? comment.replace(/^(\[if\s[^\]]+]>)([\s\S]*?)( -1) { - return minify(text, options); + return minify(text, options, false, cb); } } - return text; + return cb(text); } // Tag omission rules from https://html.spec.whatwg.org/multipage/syntax.html#optional-tags @@ -726,7 +728,7 @@ function uniqueId(value) { var specialContentTags = createMapFromString('script,style'); -function createSortFns(value, options, uidIgnore, uidAttr) { +function createSortFns(value, options, uidIgnore, uidAttr, cb) { var attrChains = options.sortAttributes && Object.create(null); var classChain = options.sortClassName && new TokenChain(); @@ -781,33 +783,41 @@ function createSortFns(value, options, uidIgnore, uidAttr) { options.log = identity; options.sortAttributes = false; options.sortClassName = false; - scan(minify(value, options)); - options.log = log; - if (attrChains) { - var attrSorters = Object.create(null); - for (var tag in attrChains) { - attrSorters[tag] = attrChains[tag].createSorter(); + minify(value, options, false, function(error, result) { + if (error) { + return cb(error); } - options.sortAttributes = function(tag, attrs) { - var sorter = attrSorters[tag]; - if (sorter) { - var attrMap = Object.create(null); - var names = attrNames(attrs); - names.forEach(function(name, index) { - (attrMap[name] || (attrMap[name] = [])).push(attrs[index]); - }); - sorter.sort(names).forEach(function(name, index) { - attrs[index] = attrMap[name].shift(); - }); + + scan(result); + options.log = log; + if (attrChains) { + var attrSorters = Object.create(null); + for (var tag in attrChains) { + attrSorters[tag] = attrChains[tag].createSorter(); } - }; - } - if (classChain) { - var sorter = classChain.createSorter(); - options.sortClassName = function(value) { - return sorter.sort(value.split(/[ \n\f\r]+/)).join(' '); - }; - } + options.sortAttributes = function(tag, attrs) { + var sorter = attrSorters[tag]; + if (sorter) { + var attrMap = Object.create(null); + var names = attrNames(attrs); + names.forEach(function(name, index) { + (attrMap[name] || (attrMap[name] = [])).push(attrs[index]); + }); + sorter.sort(names).forEach(function(name, index) { + attrs[index] = attrMap[name].shift(); + }); + } + }; + } + if (classChain) { + var sorter = classChain.createSorter(); + options.sortClassName = function(value) { + return sorter.sort(value.split(/[ \n\f\r]+/)).join(' '); + }; + } + + return cb(); + }); } /** @@ -815,8 +825,8 @@ function createSortFns(value, options, uidIgnore, uidAttr) { * * @param {string} value * @param {Object} options - * @param {boolean} [partialMarkup=false] - * @param {Function} [cb] + * @param {boolean} partialMarkup + * @param {Function} cb */ function minify(value, options, partialMarkup, cb) { if (options.collapseWhitespace) { @@ -826,7 +836,6 @@ function minify(value, options, partialMarkup, cb) { var buffer = [], charsPrevTag, currentChars = '', - hasCallback = typeof cb === 'function', hasChars, currentTag = '', currentAttrs = [], @@ -847,13 +856,6 @@ function minify(value, options, partialMarkup, cb) { */ var asyncTasks = []; - /** - * The number of async tasks that have completed. - * - * @type {number} - */ - var asyncTasksComplete = 0; - /** * A placeholder that can be inserted into the buffer in place of a string. * @@ -869,12 +871,12 @@ function minify(value, options, partialMarkup, cb) { * * @constructor * - * @param {AsyncTask[]} tasks - * @param {*} data - * @param {Function} cb + * @param {AsyncTask[]} [tasks] + * @param {*} [data] + * @param {Function} [cb] */ function AsyncTaskGroup(tasks, data, cb) { - this.tasks = tasks; + this.tasks = tasks ? tasks : []; this.data = data; this.cb = cb; } @@ -904,7 +906,9 @@ function minify(value, options, partialMarkup, cb) { (function implementation(data, index) { if (index < this.tasks.length) { try { - this.tasks[index].data = data; + if (typeof this.tasks[index].data === 'undefined') { + this.tasks[index].data = data; + } this.tasks[index].exec( function(error, result) { if (error) { @@ -1007,7 +1011,9 @@ function minify(value, options, partialMarkup, cb) { if (options.sortAttributes && typeof options.sortAttributes !== 'function' || options.sortClassName && typeof options.sortClassName !== 'function') { - createSortFns(value, options, uidIgnore, uidAttr); + asyncTasks.push(new AsyncTask(function(data, cb) { + createSortFns(value, options, uidIgnore, uidAttr, cb); + })); } function _canCollapseWhitespace(tag, attrs) { @@ -1070,109 +1076,150 @@ function minify(value, options, partialMarkup, cb) { trimTrailingWhitespace(charsIndex, nextTag); } - try { - new HTMLParser(value, { - partialMarkup: partialMarkup, - html5: options.html5, - - start: function(tag, attrs, unary, unarySlash, autoGenerated) { - var lowerTag = tag.toLowerCase(); + asyncTasks.push(new AsyncTask(function(data, cb) { + try { + new HTMLParser(value, { + partialMarkup: partialMarkup, + html5: options.html5, - if (lowerTag === 'svg') { - options = Object.create(options); - options.keepClosingSlash = true; - options.caseSensitive = true; - } + start: function(tag, attrs, unary, unarySlash, autoGenerated) { + var placeholder = new Placeholder(); // Some unique reference. + buffer.push(placeholder); - tag = options.caseSensitive ? tag : lowerTag; + asyncTasks.push( + new AsyncTask(function(data, cb) { + // The index of the placeholder may not be the same as where it + // was originally inserted at; therefore we need to search for it. + var insertionIndex = buffer.indexOf(placeholder); - currentTag = tag; - charsPrevTag = tag; - if (!inlineTextTags(tag)) { - currentChars = ''; - } - hasChars = false; - currentAttrs = attrs; - - var optional = options.removeOptionalTags; - if (optional) { - var htmlTag = htmlTags(tag); - // may be omitted if first thing inside is not comment - // may be omitted if first thing inside is an element - // may be omitted if first thing inside is not space, comment, , , ', ''); - test_minify(assert, '', ''); - test_minify(assert, '', ''); + test_minify_sync(assert, '', ''); + test_minify_sync(assert, '', ''); + test_minify_sync(assert, '', ''); - test_minify(assert, 'foo', 'foo'); - test_minify(assert, '

    x', '

    x

    '); - test_minify(assert, '

    x

    ', '

    x

    ', 'trailing quote should be ignored'); - test_minify(assert, '

    Click me

    ', '

    Click me

    '); - test_minify(assert, '', ''); - test_minify(assert, '
    [fallback image]
    ', + test_minify_sync(assert, 'foo', 'foo'); + test_minify_sync(assert, '

    x', '

    x

    '); + test_minify_sync(assert, '

    x

    ', '

    x

    ', 'trailing quote should be ignored'); + test_minify_sync(assert, '

    Click me

    ', '

    Click me

    '); + test_minify_sync(assert, '', ''); + test_minify_sync(assert, '
    [fallback image]
    ', '
    [fallback image]
    ' ); - test_minify(assert, '', ''); - test_minify(assert, '', ''); - test_minify(assert, '
    ', + test_minify_sync(assert, '', ''); + test_minify_sync(assert, '', ''); + test_minify_sync(assert, '
    ', '
    ' ); // will cause test to time-out if fail input = '

    For more information, read this Stack Overflow answer.

    '; output = '

    For more information, read this Stack Overflow answer.

    '; - test_minify(assert, input, output); + test_minify_sync(assert, input, output); input = ''; - test_minify(assert, input, input); + test_minify_sync(assert, input, input); input = ''; - test_minify(assert, input, input); + test_minify_sync(assert, input, input); input = '<$unicorn>'; - test_minify_error(assert, input, {}, 'Invalid tag name'); + test_minify_sync_error(assert, input, {}, 'Invalid tag name'); input = ''; - test_minify(assert, input, input); + test_minify_sync(assert, input, input); // https://github.com/kangax/html-minifier/issues/41 - test_minify(assert, '', + test_minify_sync(assert, '', '' ); // https://github.com/kangax/html-minifier/issues/40 - test_minify(assert, '[\']["]', '[\']["]'); + test_minify_sync(assert, '[\']["]', '[\']["]'); // https://github.com/kangax/html-minifier/issues/21 - test_minify(assert, '
    hey
    ', '
    hey
    '); + test_minify_sync(assert, '
    hey
    ', '
    hey
    '); // https://github.com/kangax/html-minifier/issues/17 - test_minify(assert, ':) link', ':) link'); + test_minify_sync(assert, ':) link', ':) link'); // https://github.com/kangax/html-minifier/issues/169 - test_minify(assert, 'ok', 'ok'); + test_minify_sync(assert, 'ok', 'ok'); - test_minify(assert, '', ''); + test_minify_sync(assert, '', ''); // https://github.com/kangax/html-minifier/issues/229 - test_minify(assert, '
    Hello :)
    ', '
    Hello :)
    '); + test_minify_sync(assert, '
    Hello :)
    ', '
    Hello :)
    '); // https://github.com/kangax/html-minifier/issues/507 input = ''; - test_minify(assert, input, input); - test_minify_error( + test_minify_sync(assert, input, input); + test_minify_sync_error( assert, '', {}, @@ -207,8 +237,8 @@ QUnit.test('parsing non-trivial markup', function(assert) { ' data-ng-model-options="{ debounce: 1000 }"' + ' data-ng-pattern="vm.options.format"' + ' data-options="vm.datepickerOptions">'; - test_minify(assert, input, input); - test_minify_error( + test_minify_sync(assert, input, input); + test_minify_sync_error( assert, '' + @@ -224,18 +254,18 @@ QUnit.test('parsing non-trivial markup', function(assert) { input = '
    '; output = '
    '; - test_minify(assert, input, output); + test_minify_sync(assert, input, output); output = '
    '; - test_minify(assert, input, { + test_minify_sync(assert, input, { decodeEntities: true, removeTagWhitespace: true, }, output); output = '
    '; - test_minify(assert, input, { + test_minify_sync(assert, input, { decodeEntities: true, removeAttributeQuotes: true }, output); - test_minify(assert, input, { + test_minify_sync(assert, input, { decodeEntities: true, removeAttributeQuotes: true, removeTagWhitespace: true, @@ -244,46 +274,46 @@ QUnit.test('parsing non-trivial markup', function(assert) { QUnit.test('options', function(assert) { var input = '

    blahblah 2blah 3

    '; - test_minify(assert, input, input); - test_minify(assert, input, {}, input); + test_minify_sync(assert, input, input); + test_minify_sync(assert, input, {}, input); }); QUnit.test('case normalization', function(assert) { - test_minify(assert, '

    foo

    ', '

    foo

    '); - test_minify(assert, '
    boo
    ', '
    boo
    '); - test_minify(assert, '
    boo
    ', '
    boo
    '); - test_minify(assert, '
    boo
    ', '
    boo
    '); - test_minify(assert, '
    boo
    ', '
    boo
    '); - test_minify(assert, '
    boo
    ', '
    boo
    '); + test_minify_sync(assert, '

    foo

    ', '

    foo

    '); + test_minify_sync(assert, '
    boo
    ', '
    boo
    '); + test_minify_sync(assert, '
    boo
    ', '
    boo
    '); + test_minify_sync(assert, '
    boo
    ', '
    boo
    '); + test_minify_sync(assert, '
    boo
    ', '
    boo
    '); + test_minify_sync(assert, '
    boo
    ', '
    boo
    '); }); QUnit.test('space normalization between attributes', function(assert) { - test_minify(assert, '

    foo

    ', '

    foo

    '); - test_minify(assert, '', ''); - test_minify(assert, '

    foo

    ', '

    foo

    '); - test_minify(assert, '

    foo

    ', '

    foo

    '); - test_minify(assert, '', ''); - test_minify(assert, '', ''); + test_minify_sync(assert, '

    foo

    ', '

    foo

    '); + test_minify_sync(assert, '', ''); + test_minify_sync(assert, '

    foo

    ', '

    foo

    '); + test_minify_sync(assert, '

    foo

    ', '

    foo

    '); + test_minify_sync(assert, '', ''); + test_minify_sync(assert, '', ''); }); QUnit.test('space normalization around text', function(assert) { var input, output; input = '

    blah

    \n\n\n '; - test_minify(assert, input, input); + test_minify_sync(assert, input, input); output = '

    blah

    '; - test_minify(assert, input, { collapseWhitespace: true }, output); + test_minify_sync(assert, input, { collapseWhitespace: true }, output); output = '

    blah

    '; - test_minify(assert, input, { + test_minify_sync(assert, input, { collapseWhitespace: true, conservativeCollapse: true }, output); output = '

    blah

    \n'; - test_minify(assert, input, { + test_minify_sync(assert, input, { collapseWhitespace: true, preserveLineBreaks: true }, output); output = '

    blah

    \n'; - test_minify(assert, input, { + test_minify_sync(assert, input, { collapseWhitespace: true, conservativeCollapse: true, preserveLineBreaks: true @@ -293,43 +323,43 @@ QUnit.test('space normalization around text', function(assert) { 'mark', 's', 'samp', 'small', 'span', 'strike', 'strong', 'sub', 'sup', 'time', 'tt', 'u', 'var' ].forEach(function(el) { - test_minify(assert, 'foo <' + el + '>baz bar', { collapseWhitespace: true }, 'foo <' + el + '>baz bar'); - test_minify(assert, 'foo<' + el + '>bazbar', { collapseWhitespace: true }, 'foo<' + el + '>bazbar'); - test_minify(assert, 'foo <' + el + '>bazbar', { collapseWhitespace: true }, 'foo <' + el + '>bazbar'); - test_minify(assert, 'foo<' + el + '>baz bar', { collapseWhitespace: true }, 'foo<' + el + '>baz bar'); - test_minify(assert, 'foo <' + el + '> baz bar', { collapseWhitespace: true }, 'foo <' + el + '>baz bar'); - test_minify(assert, 'foo<' + el + '> baz bar', { collapseWhitespace: true }, 'foo<' + el + '> baz bar'); - test_minify(assert, 'foo <' + el + '> baz bar', { collapseWhitespace: true }, 'foo <' + el + '>baz bar'); - test_minify(assert, 'foo<' + el + '> baz bar', { collapseWhitespace: true }, 'foo<' + el + '> baz bar'); - test_minify(assert, '
    foo <' + el + '>baz bar
    ', { collapseWhitespace: true }, '
    foo <' + el + '>baz bar
    '); - test_minify(assert, '
    foo<' + el + '>bazbar
    ', { collapseWhitespace: true }, '
    foo<' + el + '>bazbar
    '); - test_minify(assert, '
    foo <' + el + '>bazbar
    ', { collapseWhitespace: true }, '
    foo <' + el + '>bazbar
    '); - test_minify(assert, '
    foo<' + el + '>baz bar
    ', { collapseWhitespace: true }, '
    foo<' + el + '>baz bar
    '); - test_minify(assert, '
    foo <' + el + '> baz bar
    ', { collapseWhitespace: true }, '
    foo <' + el + '>baz bar
    '); - test_minify(assert, '
    foo<' + el + '> baz bar
    ', { collapseWhitespace: true }, '
    foo<' + el + '> baz bar
    '); - test_minify(assert, '
    foo <' + el + '> baz bar
    ', { collapseWhitespace: true }, '
    foo <' + el + '>baz bar
    '); - test_minify(assert, '
    foo<' + el + '> baz bar
    ', { collapseWhitespace: true }, '
    foo<' + el + '> baz bar
    '); + test_minify_sync(assert, 'foo <' + el + '>baz bar', { collapseWhitespace: true }, 'foo <' + el + '>baz bar'); + test_minify_sync(assert, 'foo<' + el + '>bazbar', { collapseWhitespace: true }, 'foo<' + el + '>bazbar'); + test_minify_sync(assert, 'foo <' + el + '>bazbar', { collapseWhitespace: true }, 'foo <' + el + '>bazbar'); + test_minify_sync(assert, 'foo<' + el + '>baz bar', { collapseWhitespace: true }, 'foo<' + el + '>baz bar'); + test_minify_sync(assert, 'foo <' + el + '> baz bar', { collapseWhitespace: true }, 'foo <' + el + '>baz bar'); + test_minify_sync(assert, 'foo<' + el + '> baz bar', { collapseWhitespace: true }, 'foo<' + el + '> baz bar'); + test_minify_sync(assert, 'foo <' + el + '> baz bar', { collapseWhitespace: true }, 'foo <' + el + '>baz bar'); + test_minify_sync(assert, 'foo<' + el + '> baz bar', { collapseWhitespace: true }, 'foo<' + el + '> baz bar'); + test_minify_sync(assert, '
    foo <' + el + '>baz bar
    ', { collapseWhitespace: true }, '
    foo <' + el + '>baz bar
    '); + test_minify_sync(assert, '
    foo<' + el + '>bazbar
    ', { collapseWhitespace: true }, '
    foo<' + el + '>bazbar
    '); + test_minify_sync(assert, '
    foo <' + el + '>bazbar
    ', { collapseWhitespace: true }, '
    foo <' + el + '>bazbar
    '); + test_minify_sync(assert, '
    foo<' + el + '>baz bar
    ', { collapseWhitespace: true }, '
    foo<' + el + '>baz bar
    '); + test_minify_sync(assert, '
    foo <' + el + '> baz bar
    ', { collapseWhitespace: true }, '
    foo <' + el + '>baz bar
    '); + test_minify_sync(assert, '
    foo<' + el + '> baz bar
    ', { collapseWhitespace: true }, '
    foo<' + el + '> baz bar
    '); + test_minify_sync(assert, '
    foo <' + el + '> baz bar
    ', { collapseWhitespace: true }, '
    foo <' + el + '>baz bar
    '); + test_minify_sync(assert, '
    foo<' + el + '> baz bar
    ', { collapseWhitespace: true }, '
    foo<' + el + '> baz bar
    '); }); // Don't trim whitespace around element, but do trim within [ 'bdi', 'bdo', 'button', 'cite', 'code', 'dfn', 'math', 'q', 'rt', 'rtc', 'ruby', 'svg' ].forEach(function(el) { - test_minify(assert, 'foo <' + el + '>baz bar', { collapseWhitespace: true }, 'foo <' + el + '>baz bar'); - test_minify(assert, 'foo<' + el + '>bazbar', { collapseWhitespace: true }, 'foo<' + el + '>bazbar'); - test_minify(assert, 'foo <' + el + '>bazbar', { collapseWhitespace: true }, 'foo <' + el + '>bazbar'); - test_minify(assert, 'foo<' + el + '>baz bar', { collapseWhitespace: true }, 'foo<' + el + '>baz bar'); - test_minify(assert, 'foo <' + el + '> baz bar', { collapseWhitespace: true }, 'foo <' + el + '>baz bar'); - test_minify(assert, 'foo<' + el + '> baz bar', { collapseWhitespace: true }, 'foo<' + el + '>bazbar'); - test_minify(assert, 'foo <' + el + '> baz bar', { collapseWhitespace: true }, 'foo <' + el + '>bazbar'); - test_minify(assert, 'foo<' + el + '> baz bar', { collapseWhitespace: true }, 'foo<' + el + '>baz bar'); - test_minify(assert, '
    foo <' + el + '>baz bar
    ', { collapseWhitespace: true }, '
    foo <' + el + '>baz bar
    '); - test_minify(assert, '
    foo<' + el + '>bazbar
    ', { collapseWhitespace: true }, '
    foo<' + el + '>bazbar
    '); - test_minify(assert, '
    foo <' + el + '>bazbar
    ', { collapseWhitespace: true }, '
    foo <' + el + '>bazbar
    '); - test_minify(assert, '
    foo<' + el + '>baz bar
    ', { collapseWhitespace: true }, '
    foo<' + el + '>baz bar
    '); - test_minify(assert, '
    foo <' + el + '> baz bar
    ', { collapseWhitespace: true }, '
    foo <' + el + '>baz bar
    '); - test_minify(assert, '
    foo<' + el + '> baz bar
    ', { collapseWhitespace: true }, '
    foo<' + el + '>bazbar
    '); - test_minify(assert, '
    foo <' + el + '> baz bar
    ', { collapseWhitespace: true }, '
    foo <' + el + '>bazbar
    '); - test_minify(assert, '
    foo<' + el + '> baz bar
    ', { collapseWhitespace: true }, '
    foo<' + el + '>baz bar
    '); + test_minify_sync(assert, 'foo <' + el + '>baz bar', { collapseWhitespace: true }, 'foo <' + el + '>baz bar'); + test_minify_sync(assert, 'foo<' + el + '>bazbar', { collapseWhitespace: true }, 'foo<' + el + '>bazbar'); + test_minify_sync(assert, 'foo <' + el + '>bazbar', { collapseWhitespace: true }, 'foo <' + el + '>bazbar'); + test_minify_sync(assert, 'foo<' + el + '>baz bar', { collapseWhitespace: true }, 'foo<' + el + '>baz bar'); + test_minify_sync(assert, 'foo <' + el + '> baz bar', { collapseWhitespace: true }, 'foo <' + el + '>baz bar'); + test_minify_sync(assert, 'foo<' + el + '> baz bar', { collapseWhitespace: true }, 'foo<' + el + '>bazbar'); + test_minify_sync(assert, 'foo <' + el + '> baz bar', { collapseWhitespace: true }, 'foo <' + el + '>bazbar'); + test_minify_sync(assert, 'foo<' + el + '> baz bar', { collapseWhitespace: true }, 'foo<' + el + '>baz bar'); + test_minify_sync(assert, '
    foo <' + el + '>baz bar
    ', { collapseWhitespace: true }, '
    foo <' + el + '>baz bar
    '); + test_minify_sync(assert, '
    foo<' + el + '>bazbar
    ', { collapseWhitespace: true }, '
    foo<' + el + '>bazbar
    '); + test_minify_sync(assert, '
    foo <' + el + '>bazbar
    ', { collapseWhitespace: true }, '
    foo <' + el + '>bazbar
    '); + test_minify_sync(assert, '
    foo<' + el + '>baz bar
    ', { collapseWhitespace: true }, '
    foo<' + el + '>baz bar
    '); + test_minify_sync(assert, '
    foo <' + el + '> baz bar
    ', { collapseWhitespace: true }, '
    foo <' + el + '>baz bar
    '); + test_minify_sync(assert, '
    foo<' + el + '> baz bar
    ', { collapseWhitespace: true }, '
    foo<' + el + '>bazbar
    '); + test_minify_sync(assert, '
    foo <' + el + '> baz bar
    ', { collapseWhitespace: true }, '
    foo <' + el + '>bazbar
    '); + test_minify_sync(assert, '
    foo<' + el + '> baz bar
    ', { collapseWhitespace: true }, '
    foo<' + el + '>baz bar
    '); }); [ [' foo ', 'foo'], @@ -355,36 +385,36 @@ QUnit.test('space normalization around text', function(assert) { ['a b c', 'a b c'], ['a b c', 'a b c'] ].forEach(function(inputs) { - test_minify(assert, inputs[0], { + test_minify_sync(assert, inputs[0], { collapseWhitespace: true, conservativeCollapse: true }, inputs[0], inputs[0]); - test_minify(assert, inputs[0], { collapseWhitespace: true }, inputs[1], inputs[0]); + test_minify_sync(assert, inputs[0], { collapseWhitespace: true }, inputs[1], inputs[0]); var input = '
    ' + inputs[0] + '
    '; - test_minify(assert, input, { + test_minify_sync(assert, input, { collapseWhitespace: true, conservativeCollapse: true }, input, input); var output = '
    ' + inputs[1] + '
    '; - test_minify(assert, input, { collapseWhitespace: true }, output, input); + test_minify_sync(assert, input, { collapseWhitespace: true }, output, input); }); - test_minify(assert, '

    foo bar

    ', { collapseWhitespace: true }, '

    foo bar

    '); - test_minify(assert, '

    foobar

    ', { collapseWhitespace: true }, '

    foobar

    '); - test_minify(assert, '

    foo bar

    ', { collapseWhitespace: true }, '

    foo bar

    '); - test_minify(assert, '

    foo bar

    ', { collapseWhitespace: true }, '

    foo bar

    '); - test_minify(assert, '

    foo bar

    ', { collapseWhitespace: true }, '

    foo bar

    '); - test_minify(assert, '

    foobar

    ', { collapseWhitespace: true }, '

    foobar

    '); - test_minify(assert, '

    foo bar

    ', { collapseWhitespace: true }, '

    foo bar

    '); - test_minify(assert, '

    foo bar

    ', { collapseWhitespace: true }, '

    foo bar

    '); - test_minify(assert, '

    foo bar

    ', { collapseWhitespace: true }, '

    foo bar

    '); - test_minify(assert, '

    foobar

    ', { collapseWhitespace: true }, '

    foobar

    '); - test_minify(assert, '

    foo bar

    ', { collapseWhitespace: true }, '

    foo bar

    '); - test_minify(assert, '

    foo bar

    ', { collapseWhitespace: true }, '

    foo bar

    '); - test_minify(assert, '

    foo bar

    ', { collapseWhitespace: true }, '

    foo bar

    '); - test_minify(assert, '

    foo bar

    ', { collapseWhitespace: true }, '

    foo bar

    '); - test_minify(assert, '

    foo bar

    ', { collapseWhitespace: true }, '

    foo bar

    '); - test_minify(assert, '
    Empty not
    ', { collapseWhitespace: true }, '
    Empty not
    '); - test_minify(assert, '
    a c
    ', { + test_minify_sync(assert, '

    foo bar

    ', { collapseWhitespace: true }, '

    foo bar

    '); + test_minify_sync(assert, '

    foobar

    ', { collapseWhitespace: true }, '

    foobar

    '); + test_minify_sync(assert, '

    foo bar

    ', { collapseWhitespace: true }, '

    foo bar

    '); + test_minify_sync(assert, '

    foo bar

    ', { collapseWhitespace: true }, '

    foo bar

    '); + test_minify_sync(assert, '

    foo bar

    ', { collapseWhitespace: true }, '

    foo bar

    '); + test_minify_sync(assert, '

    foobar

    ', { collapseWhitespace: true }, '

    foobar

    '); + test_minify_sync(assert, '

    foo bar

    ', { collapseWhitespace: true }, '

    foo bar

    '); + test_minify_sync(assert, '

    foo bar

    ', { collapseWhitespace: true }, '

    foo bar

    '); + test_minify_sync(assert, '

    foo bar

    ', { collapseWhitespace: true }, '

    foo bar

    '); + test_minify_sync(assert, '

    foobar

    ', { collapseWhitespace: true }, '

    foobar

    '); + test_minify_sync(assert, '

    foo bar

    ', { collapseWhitespace: true }, '

    foo bar

    '); + test_minify_sync(assert, '

    foo bar

    ', { collapseWhitespace: true }, '

    foo bar

    '); + test_minify_sync(assert, '

    foo bar

    ', { collapseWhitespace: true }, '

    foo bar

    '); + test_minify_sync(assert, '

    foo bar

    ', { collapseWhitespace: true }, '

    foo bar

    '); + test_minify_sync(assert, '

    foo bar

    ', { collapseWhitespace: true }, '

    foo bar

    '); + test_minify_sync(assert, '
    Empty not
    ', { collapseWhitespace: true }, '
    Empty not
    '); + test_minify_sync(assert, '
    a c
    ', { collapseWhitespace: true, removeComments: true }, '
    a c
    '); @@ -399,29 +429,29 @@ QUnit.test('space normalization around text', function(assert) { ' a c ', ' a c ' ].forEach(function(input) { - test_minify(assert, input, { + test_minify_sync(assert, input, { collapseWhitespace: true, conservativeCollapse: true }, input, input); - test_minify(assert, input, { + test_minify_sync(assert, input, { collapseWhitespace: true, removeComments: true }, 'a c', input); - test_minify(assert, input, { + test_minify_sync(assert, input, { collapseWhitespace: true, conservativeCollapse: true, removeComments: true }, ' a c ', input); input = '

    ' + input + '

    '; - test_minify(assert, input, { + test_minify_sync(assert, input, { collapseWhitespace: true, conservativeCollapse: true }, input, input); - test_minify(assert, input, { + test_minify_sync(assert, input, { collapseWhitespace: true, removeComments: true }, '

    a c

    ', input); - test_minify(assert, input, { + test_minify_sync(assert, input, { collapseWhitespace: true, conservativeCollapse: true, removeComments: true @@ -429,34 +459,34 @@ QUnit.test('space normalization around text', function(assert) { }); input = '
  • foo
  • '; output = '
  • foo
  • '; - test_minify(assert, input, { collapseWhitespace: true }, output); + test_minify_sync(assert, input, { collapseWhitespace: true }, output); input = '
  • foo
  • '; - test_minify(assert, input, { collapseWhitespace: true }, output); + test_minify_sync(assert, input, { collapseWhitespace: true }, output); input = '
  • foo
  • '; - test_minify(assert, input, { collapseWhitespace: true }, output); + test_minify_sync(assert, input, { collapseWhitespace: true }, output); input = '
  • foo
  • '; - test_minify(assert, input, { collapseWhitespace: true }, output); + test_minify_sync(assert, input, { collapseWhitespace: true }, output); input = '
  • foo
  • '; - test_minify(assert, input, { collapseWhitespace: true }, output); + test_minify_sync(assert, input, { collapseWhitespace: true }, output); input = ''; output = ''; - test_minify(assert, input, { collapseWhitespace: true }, output); + test_minify_sync(assert, input, { collapseWhitespace: true }, output); input = ' '; output = ''; - test_minify(assert, input, { collapseWhitespace: true }, output); + test_minify_sync(assert, input, { collapseWhitespace: true }, output); input = ' '; output = ''; - test_minify(assert, input, { collapseWhitespace: true }, output); + test_minify_sync(assert, input, { collapseWhitespace: true }, output); input = '

    foo\u00A0bar\nbaz \u00A0\nmoo\t

    '; output = '

    foo\u00A0bar baz \u00A0 moo

    '; - test_minify(assert, input, { collapseWhitespace: true }, output); + test_minify_sync(assert, input, { collapseWhitespace: true }, output); input = '\n' + '\n' + ' bar \n' + '\n' + '\n'; output = ' bar '; - test_minify(assert, input, { collapseWhitespace: true }, output); + test_minify_sync(assert, input, { collapseWhitespace: true }, output); input = '
    \n' +
               'foo\n' +
               '
    \n' + @@ -464,130 +494,130 @@ QUnit.test('space normalization around text', function(assert) { '
    \n' + 'baz\n'; output = '
    \nfoo\n
    \nbar\n
    baz'; - test_minify(assert, input, { collapseWhitespace: true }, output); + test_minify_sync(assert, input, { collapseWhitespace: true }, output); }); QUnit.test('types of whitespace that should always be preserved', function(assert) { // Hair space: var input = '
    \u200afo\u200ao\u200a
    '; - test_minify(assert, input, { collapseWhitespace: true }, input); + test_minify_sync(assert, input, { collapseWhitespace: true }, input); // Hair space passed as HTML entity: var inputWithEntities = '
     fo o 
    '; - test_minify(assert, inputWithEntities, { collapseWhitespace: true }, inputWithEntities); + test_minify_sync(assert, inputWithEntities, { collapseWhitespace: true }, inputWithEntities); // Hair space passed as HTML entity, in decodeEntities:true mode: - test_minify(assert, inputWithEntities, { collapseWhitespace: true, decodeEntities: true }, input); + test_minify_sync(assert, inputWithEntities, { collapseWhitespace: true, decodeEntities: true }, input); // Non-breaking space: input = '
    \xa0fo\xa0o\xa0
    '; - test_minify(assert, input, { collapseWhitespace: true }, input); + test_minify_sync(assert, input, { collapseWhitespace: true }, input); // Non-breaking space passed as HTML entity: inputWithEntities = '
     fo o 
    '; - test_minify(assert, inputWithEntities, { collapseWhitespace: true }, inputWithEntities); + test_minify_sync(assert, inputWithEntities, { collapseWhitespace: true }, inputWithEntities); // Non-breaking space passed as HTML entity, in decodeEntities:true mode: - test_minify(assert, inputWithEntities, { collapseWhitespace: true, decodeEntities: true }, input); + test_minify_sync(assert, inputWithEntities, { collapseWhitespace: true, decodeEntities: true }, input); // Do not remove hair space when preserving line breaks between tags: input = '

    \u200a\n

    \n'; - test_minify(assert, input, { collapseWhitespace: true, preserveLineBreaks: true }, input); + test_minify_sync(assert, input, { collapseWhitespace: true, preserveLineBreaks: true }, input); // Preserve hair space in attributes: input = '

    '; - test_minify(assert, input, { collapseWhitespace: true }, input); + test_minify_sync(assert, input, { collapseWhitespace: true }, input); // Preserve hair space in class names when deduplicating and reordering: input = ''; - test_minify(assert, input, { sortClassName: false }, input); - test_minify(assert, input, { sortClassName: true }, input); + test_minify_sync(assert, input, { sortClassName: false }, input); + test_minify_sync(assert, input, { sortClassName: true }, input); }); QUnit.test('doctype normalization', function(assert) { var input; input = ''; - test_minify(assert, input, { useShortDoctype: true }, ''); + test_minify_sync(assert, input, { useShortDoctype: true }, ''); input = ''; - test_minify(assert, input, { useShortDoctype: true }, input); + test_minify_sync(assert, input, { useShortDoctype: true }, input); input = ''; - test_minify(assert, input, { useShortDoctype: false }, input); + test_minify_sync(assert, input, { useShortDoctype: false }, input); }); QUnit.test('removing comments', function(assert) { var input; input = ''; - test_minify(assert, input, { removeComments: true }, ''); + test_minify_sync(assert, input, { removeComments: true }, ''); input = '
    baz
    '; - test_minify(assert, input, { removeComments: true }, '
    baz
    '); - test_minify(assert, input, { removeComments: false }, input); + test_minify_sync(assert, input, { removeComments: true }, '
    baz
    '); + test_minify_sync(assert, input, { removeComments: false }, input); input = '

    foo

    '; - test_minify(assert, input, { removeComments: true }, input); + test_minify_sync(assert, input, { removeComments: true }, input); input = ''; - test_minify(assert, input, { removeComments: true }, input); + test_minify_sync(assert, input, { removeComments: true }, input); input = ''; - test_minify(assert, input, { removeComments: true }, ''); + test_minify_sync(assert, input, { removeComments: true }, ''); }); QUnit.test('ignoring comments', function(assert) { var input, output; input = ''; - test_minify(assert, input, { removeComments: true }, input); - test_minify(assert, input, { removeComments: false }, input); + test_minify_sync(assert, input, { removeComments: true }, input); + test_minify_sync(assert, input, { removeComments: false }, input); input = '
    baz
    '; - test_minify(assert, input, { removeComments: true }, input); - test_minify(assert, input, { removeComments: false }, input); + test_minify_sync(assert, input, { removeComments: true }, input); + test_minify_sync(assert, input, { removeComments: false }, input); input = '
    baz
    '; - test_minify(assert, input, { removeComments: true }, '
    baz
    '); - test_minify(assert, input, { removeComments: false }, input); + test_minify_sync(assert, input, { removeComments: true }, '
    baz
    '); + test_minify_sync(assert, input, { removeComments: false }, input); input = ''; - test_minify(assert, input, { removeComments: true }, ''); - test_minify(assert, input, { removeComments: false }, input); + test_minify_sync(assert, input, { removeComments: true }, ''); + test_minify_sync(assert, input, { removeComments: false }, input); input = '
    \n\n \t
    \n\n

    \n\n \n\n

    \n\n
    '; output = '

    '; - test_minify(assert, input, { removeComments: true }, input); - test_minify(assert, input, { removeComments: true, collapseWhitespace: true }, output); - test_minify(assert, input, { removeComments: false }, input); - test_minify(assert, input, { removeComments: false, collapseWhitespace: true }, output); + test_minify_sync(assert, input, { removeComments: true }, input); + test_minify_sync(assert, input, { removeComments: true, collapseWhitespace: true }, output); + test_minify_sync(assert, input, { removeComments: false }, input); + test_minify_sync(assert, input, { removeComments: false, collapseWhitespace: true }, output); input = '

    foo

    '; - test_minify(assert, input, { removeComments: true }, input); + test_minify_sync(assert, input, { removeComments: true }, input); }); - +// FIXME: QUnit.test('conditional comments', function(assert) { var input, output; input = 'test'; - test_minify(assert, input, { removeComments: true }, input); + test_minify_sync(assert, input, { removeComments: true }, input); input = ''; - test_minify(assert, input, { removeComments: true }, input); + test_minify_sync(assert, input, { removeComments: true }, input); input = 'test'; - test_minify(assert, input, { removeComments: true }, input); + test_minify_sync(assert, input, { removeComments: true }, input); input = 'test'; - test_minify(assert, input, { removeComments: true }, input); + test_minify_sync(assert, input, { removeComments: true }, input); input = ''; - test_minify(assert, input, { removeComments: true }, input); + test_minify_sync(assert, input, { removeComments: true }, input); input = ''; - test_minify(assert, input, { removeComments: true }, input); + test_minify_sync(assert, input, { removeComments: true }, input); input = '\n' + ' \n' + @@ -605,7 +635,7 @@ QUnit.test('conditional comments', function(assert) { ' alert("ie8!");\n' + ' \n' + ' '; - test_minify(assert, input, { + test_minify_sync(assert, input, { minifyJS: true, removeComments: true, collapseWhitespace: true, @@ -613,7 +643,7 @@ QUnit.test('conditional comments', function(assert) { removeScriptTypeAttributes: true }, output); output = ''; - test_minify(assert, input, { + test_minify_sync(assert, input, { minifyJS: true, removeComments: true, collapseWhitespace: true, @@ -648,11 +678,11 @@ QUnit.test('conditional comments', function(assert) { '' + '' + 'Document'; - test_minify(assert, input, { + test_minify_sync(assert, input, { removeComments: true, collapseWhitespace: true }, output); - test_minify(assert, input, { + test_minify_sync(assert, input, { removeComments: true, collapseWhitespace: true, processConditionalComments: true @@ -665,16 +695,16 @@ QUnit.test('collapsing space in conditional comments', function(assert) { input = ''; - test_minify(assert, input, { removeComments: true }, input); - test_minify(assert, input, { removeComments: true, collapseWhitespace: true }, input); + test_minify_sync(assert, input, { removeComments: true }, input); + test_minify_sync(assert, input, { removeComments: true, collapseWhitespace: true }, input); output = ''; - test_minify(assert, input, { removeComments: true, processConditionalComments: true }, output); + test_minify_sync(assert, input, { removeComments: true, processConditionalComments: true }, output); output = ''; - test_minify(assert, input, { + test_minify_sync(assert, input, { removeComments: true, collapseWhitespace: true, processConditionalComments: true @@ -683,12 +713,12 @@ QUnit.test('collapsing space in conditional comments', function(assert) { input = ''; - test_minify(assert, input, { removeComments: true }, input); - test_minify(assert, input, { removeComments: true, collapseWhitespace: true }, input); + test_minify_sync(assert, input, { removeComments: true }, input); + test_minify_sync(assert, input, { removeComments: true, collapseWhitespace: true }, input); output = ''; - test_minify(assert, input, { + test_minify_sync(assert, input, { removeComments: true, collapseWhitespace: true, processConditionalComments: true @@ -699,181 +729,181 @@ QUnit.test('remove comments from scripts', function(assert) { var input, output; input = ''; - test_minify(assert, input, input); + test_minify_sync(assert, input, input); output = ''; - test_minify(assert, input, { minifyJS: true }, output); + test_minify_sync(assert, input, { minifyJS: true }, output); input = ''; - test_minify(assert, input, input); + test_minify_sync(assert, input, input); output = ''; - test_minify(assert, input, { minifyJS: true }, output); + test_minify_sync(assert, input, { minifyJS: true }, output); input = ''; - test_minify(assert, input, input); + test_minify_sync(assert, input, input); output = ''; - test_minify(assert, input, { minifyJS: true }, output); + test_minify_sync(assert, input, { minifyJS: true }, output); input = ''; - test_minify(assert, input, input); - test_minify(assert, input, { minifyJS: true }, input); + test_minify_sync(assert, input, input); + test_minify_sync(assert, input, { minifyJS: true }, input); input = ''; - test_minify(assert, input, input); - test_minify(assert, input, { minifyJS: true }, input); + test_minify_sync(assert, input, input); + test_minify_sync(assert, input, { minifyJS: true }, input); input = ''; - test_minify(assert, input, input); + test_minify_sync(assert, input, input); output = ''; - test_minify(assert, input, { minifyJS: true }, output); + test_minify_sync(assert, input, { minifyJS: true }, output); input = ''; - test_minify(assert, input, input); - test_minify(assert, input, { minifyJS: true }, input); + test_minify_sync(assert, input, input); + test_minify_sync(assert, input, { minifyJS: true }, input); input = ''; - test_minify(assert, input, input); + test_minify_sync(assert, input, input); output = ''; - test_minify(assert, input, { minifyJS: true }, output); + test_minify_sync(assert, input, { minifyJS: true }, output); input = ''; - test_minify(assert, input, input); + test_minify_sync(assert, input, input); output = ''; - test_minify(assert, input, { minifyJS: true }, output); + test_minify_sync(assert, input, { minifyJS: true }, output); input = ''; - test_minify(assert, input, input); - test_minify(assert, input, { minifyJS: true }, input); + test_minify_sync(assert, input, input); + test_minify_sync(assert, input, { minifyJS: true }, input); }); QUnit.test('remove comments from styles', function(assert) { var input, output; input = ''; - test_minify(assert, input, input); + test_minify_sync(assert, input, input); output = ''; - test_minify(assert, input, { minifyCSS: true }, output); + test_minify_sync(assert, input, { minifyCSS: true }, output); input = ''; - test_minify(assert, input, input); + test_minify_sync(assert, input, input); output = ''; - test_minify(assert, input, { minifyCSS: true }, output); + test_minify_sync(assert, input, { minifyCSS: true }, output); input = ''; - test_minify(assert, input, input); + test_minify_sync(assert, input, input); output = ''; - test_minify(assert, input, { minifyCSS: true }, output); + test_minify_sync(assert, input, { minifyCSS: true }, output); input = ''; - test_minify(assert, input, input); + test_minify_sync(assert, input, input); output = ''; - test_minify(assert, input, { minifyCSS: true }, output); + test_minify_sync(assert, input, { minifyCSS: true }, output); input = ''; - test_minify(assert, input, input); + test_minify_sync(assert, input, input); output = ''; - test_minify(assert, input, { minifyCSS: true }, output); + test_minify_sync(assert, input, { minifyCSS: true }, output); input = ''; - test_minify(assert, input, input); + test_minify_sync(assert, input, input); output = ''; - test_minify(assert, input, { minifyCSS: true }, output); + test_minify_sync(assert, input, { minifyCSS: true }, output); input = ''; - test_minify(assert, input, input); + test_minify_sync(assert, input, input); output = ''; - test_minify(assert, input, { minifyCSS: true }, output); + test_minify_sync(assert, input, { minifyCSS: true }, output); input = ''; - test_minify(assert, input, input); + test_minify_sync(assert, input, input); output = ''; - test_minify(assert, input, { minifyCSS: true }, output); + test_minify_sync(assert, input, { minifyCSS: true }, output); input = ''; - test_minify(assert, input, input); - test_minify(assert, input, { minifyCSS: true }, input); + test_minify_sync(assert, input, input); + test_minify_sync(assert, input, { minifyCSS: true }, input); }); QUnit.test('remove CDATA sections from scripts/styles', function(assert) { var input, output; input = ''; - test_minify(assert, input, input); - test_minify(assert, input, { minifyJS: true }, input); + test_minify_sync(assert, input, input); + test_minify_sync(assert, input, { minifyJS: true }, input); input = ''; - test_minify(assert, input, input); - test_minify(assert, input, { minifyJS: true }, input); + test_minify_sync(assert, input, input); + test_minify_sync(assert, input, { minifyJS: true }, input); input = ''; - test_minify(assert, input, input); - test_minify(assert, input, { minifyJS: true }, input); + test_minify_sync(assert, input, input); + test_minify_sync(assert, input, { minifyJS: true }, input); input = ''; - test_minify(assert, input, input); - test_minify(assert, input, { minifyJS: true }, input); + test_minify_sync(assert, input, input); + test_minify_sync(assert, input, { minifyJS: true }, input); input = ''; - test_minify(assert, input, input); - test_minify(assert, input, { minifyJS: true }, input); + test_minify_sync(assert, input, input); + test_minify_sync(assert, input, { minifyJS: true }, input); input = ''; - test_minify(assert, input, input); + test_minify_sync(assert, input, input); output = ''; - test_minify(assert, input, { minifyJS: true }, output); + test_minify_sync(assert, input, { minifyJS: true }, output); input = ''; - test_minify(assert, input, input); + test_minify_sync(assert, input, input); output = ''; - test_minify(assert, input, { minifyJS: true }, output); + test_minify_sync(assert, input, { minifyJS: true }, output); input = ''; - test_minify(assert, input, input); + test_minify_sync(assert, input, input); output = ''; - test_minify(assert, input, { minifyJS: true }, output); + test_minify_sync(assert, input, { minifyJS: true }, output); input = ''; - test_minify(assert, input, input); + test_minify_sync(assert, input, input); output = ''; - test_minify(assert, input, { minifyJS: true }, output); + test_minify_sync(assert, input, { minifyJS: true }, output); input = ''; - test_minify(assert, input, input); + test_minify_sync(assert, input, input); output = ''; - test_minify(assert, input, { minifyCSS: true }, output); + test_minify_sync(assert, input, { minifyCSS: true }, output); input = ''; - test_minify(assert, input, input); + test_minify_sync(assert, input, input); output = ''; - test_minify(assert, input, { minifyCSS: true }, output); + test_minify_sync(assert, input, { minifyCSS: true }, output); input = ''; - test_minify(assert, input, input); + test_minify_sync(assert, input, input); output = ''; - test_minify(assert, input, { minifyCSS: true }, output); + test_minify_sync(assert, input, { minifyCSS: true }, output); input = ''; - test_minify(assert, input, input); + test_minify_sync(assert, input, input); output = ''; - test_minify(assert, input, { minifyCSS: true }, output); + test_minify_sync(assert, input, { minifyCSS: true }, output); input = ''; - test_minify(assert, input, input); + test_minify_sync(assert, input, input); output = ''; - test_minify(assert, input, { minifyCSS: true }, output); + test_minify_sync(assert, input, { minifyCSS: true }, output); input = ''; - test_minify(assert, input, input); + test_minify_sync(assert, input, input); output = ''; - test_minify(assert, input, { minifyCSS: true }, output); + test_minify_sync(assert, input, { minifyCSS: true }, output); input = ''; - test_minify(assert, input, input); + test_minify_sync(assert, input, input); output = ''; - test_minify(assert, input, { minifyCSS: true }, output); + test_minify_sync(assert, input, { minifyCSS: true }, output); input = ''; - test_minify(assert, input, input); - test_minify(assert, input, { minifyCSS: true }, input); + test_minify_sync(assert, input, input); + test_minify_sync(assert, input, { minifyCSS: true }, input); }); QUnit.test('custom processors', function(assert) { @@ -884,125 +914,125 @@ QUnit.test('custom processors', function(assert) { } input = ''; - test_minify(assert, input, input); - test_minify(assert, input, { minifyCSS: null }, input); - test_minify(assert, input, { minifyCSS: false }, input); + test_minify_sync(assert, input, input); + test_minify_sync(assert, input, { minifyCSS: null }, input); + test_minify_sync(assert, input, { minifyCSS: false }, input); output = ''; - test_minify(assert, input, { minifyCSS: css }, output); + test_minify_sync(assert, input, { minifyCSS: css }, output); input = '

    '; - test_minify(assert, input, input); - test_minify(assert, input, { minifyCSS: null }, input); - test_minify(assert, input, { minifyCSS: false }, input); + test_minify_sync(assert, input, input); + test_minify_sync(assert, input, { minifyCSS: null }, input); + test_minify_sync(assert, input, { minifyCSS: false }, input); output = '

    '; - test_minify(assert, input, { minifyCSS: css }, output); + test_minify_sync(assert, input, { minifyCSS: css }, output); input = ''; - test_minify(assert, input, input); - test_minify(assert, input, { minifyCSS: null }, input); - test_minify(assert, input, { minifyCSS: false }, input); + test_minify_sync(assert, input, input); + test_minify_sync(assert, input, { minifyCSS: null }, input); + test_minify_sync(assert, input, { minifyCSS: false }, input); output = ''; - test_minify(assert, input, { minifyCSS: css }, output); + test_minify_sync(assert, input, { minifyCSS: css }, output); input = ''; - test_minify(assert, input, input); - test_minify(assert, input, { minifyCSS: null }, input); - test_minify(assert, input, { minifyCSS: false }, input); + test_minify_sync(assert, input, input); + test_minify_sync(assert, input, { minifyCSS: null }, input); + test_minify_sync(assert, input, { minifyCSS: false }, input); output = ''; - test_minify(assert, input, { minifyCSS: css }, output); + test_minify_sync(assert, input, { minifyCSS: css }, output); function js(text, inline) { return inline ? 'Inline JS' : 'Normal JS'; } input = ''; - test_minify(assert, input, input); - test_minify(assert, input, { minifyJS: null }, input); - test_minify(assert, input, { minifyJS: false }, input); + test_minify_sync(assert, input, input); + test_minify_sync(assert, input, { minifyJS: null }, input); + test_minify_sync(assert, input, { minifyJS: false }, input); output = ''; - test_minify(assert, input, { minifyJS: js }, output); + test_minify_sync(assert, input, { minifyJS: js }, output); input = '

    '; - test_minify(assert, input, input); - test_minify(assert, input, { minifyJS: null }, input); - test_minify(assert, input, { minifyJS: false }, input); + test_minify_sync(assert, input, input); + test_minify_sync(assert, input, { minifyJS: null }, input); + test_minify_sync(assert, input, { minifyJS: false }, input); output = '

    '; - test_minify(assert, input, { minifyJS: js }, output); + test_minify_sync(assert, input, { minifyJS: js }, output); function url() { return 'URL'; } input = 'bar'; - test_minify(assert, input, input); - test_minify(assert, input, { minifyURLs: null }, input); - test_minify(assert, input, { minifyURLs: false }, input); + test_minify_sync(assert, input, input); + test_minify_sync(assert, input, { minifyURLs: null }, input); + test_minify_sync(assert, input, { minifyURLs: false }, input); output = 'bar'; - test_minify(assert, input, { minifyURLs: url }, output); + test_minify_sync(assert, input, { minifyURLs: url }, output); input = ''; - test_minify(assert, input, input); - test_minify(assert, input, { minifyURLs: null }, input); - test_minify(assert, input, { minifyURLs: false }, input); - test_minify(assert, input, { minifyURLs: url }, input); + test_minify_sync(assert, input, input); + test_minify_sync(assert, input, { minifyURLs: null }, input); + test_minify_sync(assert, input, { minifyURLs: false }, input); + test_minify_sync(assert, input, { minifyURLs: url }, input); output = ''; - test_minify(assert, input, { minifyCSS: true, minifyURLs: url }, output); + test_minify_sync(assert, input, { minifyCSS: true, minifyURLs: url }, output); }); QUnit.test('empty attributes', function(assert) { var input; input = '

    x

    '; - test_minify(assert, input, { removeEmptyAttributes: true }, '

    x

    '); + test_minify_sync(assert, input, { removeEmptyAttributes: true }, '

    x

    '); input = '

    x

    '; - test_minify(assert, input, { removeEmptyAttributes: true }, '

    x

    '); + test_minify_sync(assert, input, { removeEmptyAttributes: true }, '

    x

    '); input = ''; - test_minify(assert, input, { removeEmptyAttributes: true }, ''); + test_minify_sync(assert, input, { removeEmptyAttributes: true }, ''); input = ''; - test_minify(assert, input, { removeEmptyAttributes: true }, ''); + test_minify_sync(assert, input, { removeEmptyAttributes: true }, ''); input = ''; - test_minify(assert, input, { removeEmptyAttributes: true }, ''); + test_minify_sync(assert, input, { removeEmptyAttributes: true }, ''); // preserve unrecognized attribute // remove recognized attrs with unspecified values input = '
    '; - test_minify(assert, input, { removeEmptyAttributes: true }, '
    '); + test_minify_sync(assert, input, { removeEmptyAttributes: true }, '
    '); // additional remove attributes input = ''; - test_minify(assert, input, { removeEmptyAttributes: function(attrName, tag) { return tag === 'img' && attrName === 'src'; } }, ''); + test_minify_sync(assert, input, { removeEmptyAttributes: function(attrName, tag) { return tag === 'img' && attrName === 'src'; } }, ''); }); QUnit.test('cleaning class/style attributes', function(assert) { var input, output; input = '

    foo bar baz

    '; - test_minify(assert, input, '

    foo bar baz

    '); + test_minify_sync(assert, input, '

    foo bar baz

    '); input = '

    foo bar baz

    '; - test_minify(assert, input, '

    foo bar baz

    '); - test_minify(assert, input, { removeAttributeQuotes: true }, '

    foo bar baz

    '); + test_minify_sync(assert, input, '

    foo bar baz

    '); + test_minify_sync(assert, input, { removeAttributeQuotes: true }, '

    foo bar baz

    '); input = '

    foo bar baz

    '; output = '

    foo bar baz

    '; - test_minify(assert, input, output); + test_minify_sync(assert, input, output); input = '

    foo bar baz

    '; output = '

    foo bar baz

    '; - test_minify(assert, input, output); + test_minify_sync(assert, input, output); input = '

    '; output = '

    '; - test_minify(assert, input, output); + test_minify_sync(assert, input, output); input = '

    '; output = '

    '; - test_minify(assert, input, output); + test_minify_sync(assert, input, output); }); QUnit.test('cleaning URI-based attributes', function(assert) { @@ -1010,41 +1040,41 @@ QUnit.test('cleaning URI-based attributes', function(assert) { input = 'x'; output = 'x'; - test_minify(assert, input, output); + test_minify_sync(assert, input, output); input = 'x'; output = 'x'; - test_minify(assert, input, output); + test_minify_sync(assert, input, output); input = ''; output = ''; - test_minify(assert, input, output); + test_minify_sync(assert, input, output); input = ''; output = ''; - test_minify(assert, input, output); + test_minify_sync(assert, input, output); input = '
    '; output = '
    '; - test_minify(assert, input, output); + test_minify_sync(assert, input, output); input = '

    foobar

    '; output = '

    foobar

    '; - test_minify(assert, input, output); + test_minify_sync(assert, input, output); input = ''; output = ''; - test_minify(assert, input, output); + test_minify_sync(assert, input, output); input = ''; output = ''; - test_minify(assert, input, output); + test_minify_sync(assert, input, output); input = 'foo'; - test_minify(assert, input, input); + test_minify_sync(assert, input, input); input = '
    blah
    '; - test_minify(assert, input, input); + test_minify_sync(assert, input, input); }); QUnit.test('cleaning Number-based attributes', function(assert) { @@ -1052,27 +1082,27 @@ QUnit.test('cleaning Number-based attributes', function(assert) { input = 'x'; output = 'x'; - test_minify(assert, input, output); + test_minify_sync(assert, input, output); input = ''; output = ''; - test_minify(assert, input, output); + test_minify_sync(assert, input, output); input = ''; output = ''; - test_minify(assert, input, output); + test_minify_sync(assert, input, output); input = ''; output = ''; - test_minify(assert, input, output); + test_minify_sync(assert, input, output); input = ''; output = ''; - test_minify(assert, input, output); + test_minify_sync(assert, input, output); input = 'x'; output = 'x'; - test_minify(assert, input, output); + test_minify_sync(assert, input, output); }); QUnit.test('cleaning other attributes', function(assert) { @@ -1080,50 +1110,50 @@ QUnit.test('cleaning other attributes', function(assert) { input = 'blah'; output = 'blah'; - test_minify(assert, input, output); + test_minify_sync(assert, input, output); input = '

    x'; output = '

    x

    '; - test_minify(assert, input, output); + test_minify_sync(assert, input, output); }); QUnit.test('removing redundant attributes (<form method="get" ...>)', function(assert) { var input; input = '
    hello world
    '; - test_minify(assert, input, { removeRedundantAttributes: true }, '
    hello world
    '); + test_minify_sync(assert, input, { removeRedundantAttributes: true }, '
    hello world
    '); input = '
    hello world
    '; - test_minify(assert, input, { removeRedundantAttributes: true }, '
    hello world
    '); + test_minify_sync(assert, input, { removeRedundantAttributes: true }, '
    hello world
    '); }); QUnit.test('removing redundant attributes (<input type="text" ...>)', function(assert) { var input; input = ''; - test_minify(assert, input, { removeRedundantAttributes: true }, ''); + test_minify_sync(assert, input, { removeRedundantAttributes: true }, ''); input = ''; - test_minify(assert, input, { removeRedundantAttributes: true }, ''); + test_minify_sync(assert, input, { removeRedundantAttributes: true }, ''); input = ''; - test_minify(assert, input, { removeRedundantAttributes: true }, ''); + test_minify_sync(assert, input, { removeRedundantAttributes: true }, ''); }); QUnit.test('removing redundant attributes (<a name="..." id="..." ...>)', function(assert) { var input; input = 'blah'; - test_minify(assert, input, { removeRedundantAttributes: true }, 'blah'); + test_minify_sync(assert, input, { removeRedundantAttributes: true }, 'blah'); input = ''; - test_minify(assert, input, { removeRedundantAttributes: true }, input); + test_minify_sync(assert, input, { removeRedundantAttributes: true }, input); input = 'blah'; - test_minify(assert, input, { removeRedundantAttributes: true }, input); + test_minify_sync(assert, input, { removeRedundantAttributes: true }, input); input = 'blah'; - test_minify(assert, input, { removeRedundantAttributes: true }, 'blah'); + test_minify_sync(assert, input, { removeRedundantAttributes: true }, 'blah'); }); QUnit.test('removing redundant attributes (<script src="..." charset="...">)', function(assert) { @@ -1131,125 +1161,125 @@ QUnit.test('removing redundant attributes (<script src="..." charset="...">)' input = ''; output = ''; - test_minify(assert, input, { removeRedundantAttributes: true }, output); + test_minify_sync(assert, input, { removeRedundantAttributes: true }, output); input = ''; - test_minify(assert, input, { removeRedundantAttributes: true }, input); + test_minify_sync(assert, input, { removeRedundantAttributes: true }, input); input = ''; output = ''; - test_minify(assert, input, { removeRedundantAttributes: true }, output); + test_minify_sync(assert, input, { removeRedundantAttributes: true }, output); }); QUnit.test('removing redundant attributes (<... language="javascript" ...>)', function(assert) { var input; input = ''; - test_minify(assert, input, { removeRedundantAttributes: true }, ''); + test_minify_sync(assert, input, { removeRedundantAttributes: true }, ''); input = ''; - test_minify(assert, input, { removeRedundantAttributes: true }, ''); + test_minify_sync(assert, input, { removeRedundantAttributes: true }, ''); }); QUnit.test('removing redundant attributes (<area shape="rect" ...>)', function(assert) { var input = ''; var output = ''; - test_minify(assert, input, { removeRedundantAttributes: true }, output); + test_minify_sync(assert, input, { removeRedundantAttributes: true }, output); }); QUnit.test('removing redundant attributes (<... = "javascript: ..." ...>)', function(assert) { var input; input = '

    x

    '; - test_minify(assert, input, '

    x

    '); + test_minify_sync(assert, input, '

    x

    '); input = '

    x

    '; - test_minify(assert, input, { removeAttributeQuotes: true }, '

    x

    '); + test_minify_sync(assert, input, { removeAttributeQuotes: true }, '

    x

    '); input = '

    x

    '; - test_minify(assert, input, '

    x

    '); + test_minify_sync(assert, input, '

    x

    '); input = '

    x

    '; - test_minify(assert, input, input); + test_minify_sync(assert, input, input); }); QUnit.test('removing javascript type attributes', function(assert) { var input, output; input = ''; - test_minify(assert, input, { removeScriptTypeAttributes: false }, input); + test_minify_sync(assert, input, { removeScriptTypeAttributes: false }, input); output = ''; - test_minify(assert, input, { removeScriptTypeAttributes: true }, output); + test_minify_sync(assert, input, { removeScriptTypeAttributes: true }, output); input = ''; - test_minify(assert, input, { removeScriptTypeAttributes: false }, input); + test_minify_sync(assert, input, { removeScriptTypeAttributes: false }, input); output = ''; - test_minify(assert, input, { removeScriptTypeAttributes: true }, output); + test_minify_sync(assert, input, { removeScriptTypeAttributes: true }, output); input = ''; output = ''; - test_minify(assert, input, { removeScriptTypeAttributes: true }, output); + test_minify_sync(assert, input, { removeScriptTypeAttributes: true }, output); input = ''; output = ''; - test_minify(assert, input, { removeScriptTypeAttributes: true }, output); + test_minify_sync(assert, input, { removeScriptTypeAttributes: true }, output); input = ''; output = ''; - test_minify(assert, input, { removeScriptTypeAttributes: true }, output); + test_minify_sync(assert, input, { removeScriptTypeAttributes: true }, output); }); QUnit.test('removing type="text/css" attributes', function(assert) { var input, output; input = ''; - test_minify(assert, input, { removeStyleLinkTypeAttributes: false }, input); + test_minify_sync(assert, input, { removeStyleLinkTypeAttributes: false }, input); output = ''; - test_minify(assert, input, { removeStyleLinkTypeAttributes: true }, output); + test_minify_sync(assert, input, { removeStyleLinkTypeAttributes: true }, output); input = ''; - test_minify(assert, input, { removeStyleLinkTypeAttributes: false }, input); + test_minify_sync(assert, input, { removeStyleLinkTypeAttributes: false }, input); output = ''; - test_minify(assert, input, { removeStyleLinkTypeAttributes: true }, output); + test_minify_sync(assert, input, { removeStyleLinkTypeAttributes: true }, output); input = ''; output = ''; - test_minify(assert, input, { removeStyleLinkTypeAttributes: true }, output); + test_minify_sync(assert, input, { removeStyleLinkTypeAttributes: true }, output); input = ''; - test_minify(assert, input, { removeStyleLinkTypeAttributes: true }, input); + test_minify_sync(assert, input, { removeStyleLinkTypeAttributes: true }, input); input = ''; output = ''; - test_minify(assert, input, { removeStyleLinkTypeAttributes: true }, output); + test_minify_sync(assert, input, { removeStyleLinkTypeAttributes: true }, output); input = ''; - test_minify(assert, input, { removeStyleLinkTypeAttributes: true }, input); + test_minify_sync(assert, input, { removeStyleLinkTypeAttributes: true }, input); }); QUnit.test('removing attribute quotes', function(assert) { var input; input = '

    foo

    '; - test_minify(assert, input, { removeAttributeQuotes: true }, '

    foo

    '); + test_minify_sync(assert, input, { removeAttributeQuotes: true }, '

    foo

    '); input = ''; - test_minify(assert, input, { removeAttributeQuotes: true }, ''); + test_minify_sync(assert, input, { removeAttributeQuotes: true }, ''); input = 'x'; - test_minify(assert, input, { removeAttributeQuotes: true }, 'x'); + test_minify_sync(assert, input, { removeAttributeQuotes: true }, 'x'); input = '\nfoo\n\n'; - test_minify(assert, input, { removeAttributeQuotes: true }, '\nfoo\n\n'); + test_minify_sync(assert, input, { removeAttributeQuotes: true }, '\nfoo\n\n'); input = '\nfoo\n\n'; - test_minify(assert, input, { removeAttributeQuotes: true }, '\nfoo\n\n'); + test_minify_sync(assert, input, { removeAttributeQuotes: true }, '\nfoo\n\n'); input = '\nfoo\n\n'; - test_minify(assert, input, { removeAttributeQuotes: true, removeEmptyAttributes: true }, '\nfoo\n\n'); + test_minify_sync(assert, input, { removeAttributeQuotes: true, removeEmptyAttributes: true }, '\nfoo\n\n'); input = '

    '; - test_minify(assert, input, { removeAttributeQuotes: true }, '

    '); + test_minify_sync(assert, input, { removeAttributeQuotes: true }, '

    '); }); QUnit.test('preserving custom attribute-wrapping markup', function(assert) { @@ -1261,10 +1291,10 @@ QUnit.test('preserving custom attribute-wrapping markup', function(assert) { }; input = ''; - test_minify(assert, input, customAttrOptions, input); + test_minify_sync(assert, input, customAttrOptions, input); input = ''; - test_minify(assert, input, customAttrOptions, input); + test_minify_sync(assert, input, customAttrOptions, input); // With multiple rules customAttrOptions = { @@ -1275,16 +1305,16 @@ QUnit.test('preserving custom attribute-wrapping markup', function(assert) { }; input = ''; - test_minify(assert, input, customAttrOptions, input); + test_minify_sync(assert, input, customAttrOptions, input); input = ''; - test_minify(assert, input, customAttrOptions, input); + test_minify_sync(assert, input, customAttrOptions, input); input = ''; - test_minify(assert, input, customAttrOptions, input); + test_minify_sync(assert, input, customAttrOptions, input); input = ''; - test_minify(assert, input, customAttrOptions, input); + test_minify_sync(assert, input, customAttrOptions, input); // With multiple rules and richer options customAttrOptions = { @@ -1297,13 +1327,13 @@ QUnit.test('preserving custom attribute-wrapping markup', function(assert) { }; input = ''; - test_minify(assert, input, customAttrOptions, ''); + test_minify_sync(assert, input, customAttrOptions, ''); input = ''; - test_minify(assert, input, customAttrOptions, ''); + test_minify_sync(assert, input, customAttrOptions, ''); customAttrOptions.keepClosingSlash = true; - test_minify(assert, input, customAttrOptions, ''); + test_minify_sync(assert, input, customAttrOptions, ''); }); QUnit.test('preserving custom attribute-joining markup', function(assert) { @@ -1313,9 +1343,9 @@ QUnit.test('preserving custom attribute-joining markup', function(assert) { customAttrAssign: [polymerConditionalAttributeJoin] }; input = '
    '; - test_minify(assert, input, customAttrOptions, input); + test_minify_sync(assert, input, customAttrOptions, input); input = '
    '; - test_minify(assert, input, customAttrOptions, input); + test_minify_sync(assert, input, customAttrOptions, input); }); QUnit.test('collapsing whitespace', function(assert) { @@ -1323,37 +1353,37 @@ QUnit.test('collapsing whitespace', function(assert) { input = ''; output = ''; - test_minify(assert, input, { collapseWhitespace: true }, output); + test_minify_sync(assert, input, { collapseWhitespace: true }, output); input = '

    foo

    bar

    \n\n \n\t\t
    baz
    '; output = '

    foo

    bar

    baz
    '; - test_minify(assert, input, { collapseWhitespace: true }, output); + test_minify_sync(assert, input, { collapseWhitespace: true }, output); input = '

    foo bar

    '; output = '

    foo bar

    '; - test_minify(assert, input, { collapseWhitespace: true }, output); + test_minify_sync(assert, input, { collapseWhitespace: true }, output); input = '

    foo\nbar

    '; output = '

    foo bar

    '; - test_minify(assert, input, { collapseWhitespace: true }, output); + test_minify_sync(assert, input, { collapseWhitespace: true }, output); input = '

    foo blah 22 bar

    '; output = '

    foo blah 22 bar

    '; - test_minify(assert, input, { collapseWhitespace: true }, output); + test_minify_sync(assert, input, { collapseWhitespace: true }, output); input = ''; output = ''; - test_minify(assert, input, { collapseWhitespace: true }, output); + test_minify_sync(assert, input, { collapseWhitespace: true }, output); input = '
    '; output = '
    '; - test_minify(assert, input, { collapseWhitespace: true }, output); + test_minify_sync(assert, input, { collapseWhitespace: true }, output); input = '
     $foo = "baz"; 
    '; output = '
     $foo = "baz"; 
    '; - test_minify(assert, input, { collapseWhitespace: true }, output); + test_minify_sync(assert, input, { collapseWhitespace: true }, output); output = '
    $foo = "baz";
    '; - test_minify(assert, input, { collapseWhitespace: true, caseSensitive: true }, output); + test_minify_sync(assert, input, { collapseWhitespace: true, caseSensitive: true }, output); input = '\r\n\r\n\r\n' + '\r\n\r\n\r\n' + @@ -1371,153 +1401,153 @@ QUnit.test('collapsing whitespace', function(assert) { '' + '
           \r\nxxxx
    x Hello billy ' + '
    ';
    -  test_minify(assert, input, { collapseWhitespace: true }, output);
    +  test_minify_sync(assert, input, { collapseWhitespace: true }, output);
     
       input = '
       hello     world 
    '; output = '
       hello     world 
    '; - test_minify(assert, input, { collapseWhitespace: true }, output); + test_minify_sync(assert, input, { collapseWhitespace: true }, output); input = '
       hello     world 
    '; output = '
       hello     world 
    '; - test_minify(assert, input, { collapseWhitespace: true }, output); + test_minify_sync(assert, input, { collapseWhitespace: true }, output); input = ''; output = ''; - test_minify(assert, input, { collapseWhitespace: true }, output); + test_minify_sync(assert, input, { collapseWhitespace: true }, output); input = ''; output = ''; - test_minify(assert, input, { collapseWhitespace: true }, output); + test_minify_sync(assert, input, { collapseWhitespace: true }, output); }); QUnit.test('removing empty elements', function(assert) { var input, output; - test_minify(assert, '

    x

    ', { removeEmptyElements: true }, '

    x

    '); - test_minify(assert, '

    ', { removeEmptyElements: true }, ''); + test_minify_sync(assert, '

    x

    ', { removeEmptyElements: true }, '

    x

    '); + test_minify_sync(assert, '

    ', { removeEmptyElements: true }, ''); input = '

    foobar

    '; output = '

    foobar

    '; - test_minify(assert, input, { removeEmptyElements: true }, output); + test_minify_sync(assert, input, { removeEmptyElements: true }, output); input = ''; output = ''; - test_minify(assert, input, { removeEmptyElements: true }, output); + test_minify_sync(assert, input, { removeEmptyElements: true }, output); input = ''; output = ''; - test_minify(assert, input, { removeEmptyElements: true }, output); + test_minify_sync(assert, input, { removeEmptyElements: true }, output); input = ''; - test_minify(assert, input, { removeEmptyElements: true }, input); + test_minify_sync(assert, input, { removeEmptyElements: true }, input); input = ''; - test_minify(assert, input, { removeEmptyElements: true }, input); + test_minify_sync(assert, input, { removeEmptyElements: true }, input); input = ''; output = ''; - test_minify(assert, input, { removeEmptyElements: true }, output); + test_minify_sync(assert, input, { removeEmptyElements: true }, output); input = ''; - test_minify(assert, input, { removeEmptyElements: true }, input); + test_minify_sync(assert, input, { removeEmptyElements: true }, input); input = ''; output = ''; - test_minify(assert, input, { removeEmptyElements: true }, output); + test_minify_sync(assert, input, { removeEmptyElements: true }, output); input = ''; - test_minify(assert, input, { removeEmptyElements: true }, input); + test_minify_sync(assert, input, { removeEmptyElements: true }, input); input = ''; output = ''; - test_minify(assert, input, { removeEmptyElements: true }, output); + test_minify_sync(assert, input, { removeEmptyElements: true }, output); input = ''; - test_minify(assert, input, { removeEmptyElements: true }, input); + test_minify_sync(assert, input, { removeEmptyElements: true }, input); input = ''; output = ''; - test_minify(assert, input, { removeEmptyElements: true }, output); + test_minify_sync(assert, input, { removeEmptyElements: true }, output); input = ''; - test_minify(assert, input, { removeEmptyElements: true }, input); + test_minify_sync(assert, input, { removeEmptyElements: true }, input); input = ''; - test_minify(assert, input, { removeEmptyElements: true }, input); + test_minify_sync(assert, input, { removeEmptyElements: true }, input); input = '
    helloworld
    '; - test_minify(assert, input, { removeEmptyElements: true }, input); + test_minify_sync(assert, input, { removeEmptyElements: true }, input); input = '

    x

    '; output = '

    x

    '; - test_minify(assert, input, { removeEmptyElements: true }, output); + test_minify_sync(assert, input, { removeEmptyElements: true }, output); input = '
    x
    y
    blah
    foo
    z
    '; output = '
    x
    y
    blah
    foo
    z
    '; - test_minify(assert, input, { removeEmptyElements: true }, output); + test_minify_sync(assert, input, { removeEmptyElements: true }, output); input = ''; - test_minify(assert, input, { removeEmptyElements: true }, input); + test_minify_sync(assert, input, { removeEmptyElements: true }, input); input = '

    '; output = ''; - test_minify(assert, input, { removeEmptyElements: true }, output); + test_minify_sync(assert, input, { removeEmptyElements: true }, output); input = ''; - test_minify(assert, input, { removeEmptyElements: true }, input); + test_minify_sync(assert, input, { removeEmptyElements: true }, input); input = ''; - test_minify(assert, input, { removeEmptyElements: true }, ''); + test_minify_sync(assert, input, { removeEmptyElements: true }, ''); input = '
    after
    '; output = '
    after
    '; - test_minify(assert, input, { removeEmptyElements: true }, output); + test_minify_sync(assert, input, { removeEmptyElements: true }, output); output = '
    after
    '; - test_minify(assert, input, { collapseWhitespace: true, removeEmptyElements: true }, output); + test_minify_sync(assert, input, { collapseWhitespace: true, removeEmptyElements: true }, output); input = '
    before
    '; output = '
    before
    '; - test_minify(assert, input, { removeEmptyElements: true }, output); + test_minify_sync(assert, input, { removeEmptyElements: true }, output); output = '
    before
    '; - test_minify(assert, input, { collapseWhitespace: true, removeEmptyElements: true }, output); + test_minify_sync(assert, input, { collapseWhitespace: true, removeEmptyElements: true }, output); input = '
    both
    '; output = '
    both
    '; - test_minify(assert, input, { removeEmptyElements: true }, output); + test_minify_sync(assert, input, { removeEmptyElements: true }, output); output = '
    both
    '; - test_minify(assert, input, { collapseWhitespace: true, removeEmptyElements: true }, output); + test_minify_sync(assert, input, { collapseWhitespace: true, removeEmptyElements: true }, output); input = '
    unary
    '; output = '
    unary
    '; - test_minify(assert, input, { removeEmptyElements: true }, output); + test_minify_sync(assert, input, { removeEmptyElements: true }, output); output = '
    unary
    '; - test_minify(assert, input, { collapseWhitespace: true, removeEmptyElements: true }, output); + test_minify_sync(assert, input, { collapseWhitespace: true, removeEmptyElements: true }, output); input = '
    Empty
    '; - test_minify(assert, input, { removeEmptyElements: true }, input); + test_minify_sync(assert, input, { removeEmptyElements: true }, input); output = '
    Empty
    '; - test_minify(assert, input, { collapseWhitespace: true, removeEmptyElements: true }, output); + test_minify_sync(assert, input, { collapseWhitespace: true, removeEmptyElements: true }, output); }); QUnit.test('collapsing boolean attributes', function(assert) { var input, output; input = ''; - test_minify(assert, input, { collapseBooleanAttributes: true }, ''); + test_minify_sync(assert, input, { collapseBooleanAttributes: true }, ''); input = ''; - test_minify(assert, input, { collapseBooleanAttributes: true }, ''); + test_minify_sync(assert, input, { collapseBooleanAttributes: true }, ''); input = ''; - test_minify(assert, input, { collapseBooleanAttributes: true }, ''); + test_minify_sync(assert, input, { collapseBooleanAttributes: true }, ''); input = ''; - test_minify(assert, input, { collapseBooleanAttributes: true }, ''); + test_minify_sync(assert, input, { collapseBooleanAttributes: true }, ''); input = ''; - test_minify(assert, input, { collapseBooleanAttributes: true }, ''); + test_minify_sync(assert, input, { collapseBooleanAttributes: true }, ''); input = ''; - test_minify(assert, input, { collapseBooleanAttributes: true }, ''); + test_minify_sync(assert, input, { collapseBooleanAttributes: true }, ''); input = ''; - test_minify(assert, input, { collapseBooleanAttributes: true }, output); + test_minify_sync(assert, input, { collapseBooleanAttributes: true }, output); output = ''; - test_minify(assert, input, { collapseBooleanAttributes: true, caseSensitive: true }, output); + test_minify_sync(assert, input, { collapseBooleanAttributes: true, caseSensitive: true }, output); }); QUnit.test('collapsing enumerated attributes', function(assert) { - test_minify(assert, '
    ', { collapseBooleanAttributes: true }, '
    '); - test_minify(assert, '
    ', { collapseBooleanAttributes: true }, '
    '); - test_minify(assert, '
    ', { collapseBooleanAttributes: true }, '
    '); - test_minify(assert, '
    ', { collapseBooleanAttributes: true }, '
    '); - test_minify(assert, '
    ', { collapseBooleanAttributes: true }, '
    '); - test_minify(assert, '
    ', { collapseBooleanAttributes: true }, '
    '); - test_minify(assert, '
    ', { collapseBooleanAttributes: true }, '
    '); - test_minify(assert, '
    ', { collapseBooleanAttributes: true }, '
    '); - test_minify(assert, '
    ', { collapseBooleanAttributes: true }, '
    '); - test_minify(assert, '
    ', { collapseBooleanAttributes: true }, '
    '); - test_minify(assert, '
    ', { collapseBooleanAttributes: true }, '
    '); + test_minify_sync(assert, '
    ', { collapseBooleanAttributes: true }, '
    '); + test_minify_sync(assert, '
    ', { collapseBooleanAttributes: true }, '
    '); + test_minify_sync(assert, '
    ', { collapseBooleanAttributes: true }, '
    '); + test_minify_sync(assert, '
    ', { collapseBooleanAttributes: true }, '
    '); + test_minify_sync(assert, '
    ', { collapseBooleanAttributes: true }, '
    '); + test_minify_sync(assert, '
    ', { collapseBooleanAttributes: true }, '
    '); + test_minify_sync(assert, '
    ', { collapseBooleanAttributes: true }, '
    '); + test_minify_sync(assert, '
    ', { collapseBooleanAttributes: true }, '
    '); + test_minify_sync(assert, '
    ', { collapseBooleanAttributes: true }, '
    '); + test_minify_sync(assert, '
    ', { collapseBooleanAttributes: true }, '
    '); + test_minify_sync(assert, '
    ', { collapseBooleanAttributes: true }, '
    '); }); QUnit.test('keeping trailing slashes in tags', function(assert) { - test_minify(assert, '', { keepClosingSlash: true }, ''); + test_minify_sync(assert, '', { keepClosingSlash: true }, ''); // https://github.com/kangax/html-minifier/issues/233 - test_minify(assert, '', { keepClosingSlash: true, removeAttributeQuotes: true }, ''); - test_minify(assert, '', { keepClosingSlash: true, removeAttributeQuotes: true, removeEmptyAttributes: true }, ''); - test_minify(assert, '', { keepClosingSlash: true, removeAttributeQuotes: true }, ''); + test_minify_sync(assert, '', { keepClosingSlash: true, removeAttributeQuotes: true }, ''); + test_minify_sync(assert, '', { keepClosingSlash: true, removeAttributeQuotes: true, removeEmptyAttributes: true }, ''); + test_minify_sync(assert, '', { keepClosingSlash: true, removeAttributeQuotes: true }, ''); }); QUnit.test('removing optional tags', function(assert) { var input, output; input = '

    foo'; - test_minify(assert, input, { removeOptionalTags: true }, input); + test_minify_sync(assert, input, { removeOptionalTags: true }, input); input = '

    '; output = '

    '; - test_minify(assert, input, { removeOptionalTags: true }, output); + test_minify_sync(assert, input, { removeOptionalTags: true }, output); input = ''; output = ''; - test_minify(assert, input, { removeOptionalTags: true }, output); - test_minify(assert, input, { removeOptionalTags: true, removeEmptyElements: true }, output); + test_minify_sync(assert, input, { removeOptionalTags: true }, output); + test_minify_sync(assert, input, { removeOptionalTags: true, removeEmptyElements: true }, output); input = ''; output = ''; - test_minify(assert, input, { removeOptionalTags: true }, output); - test_minify(assert, input, { removeOptionalTags: true, removeEmptyElements: true }, output); + test_minify_sync(assert, input, { removeOptionalTags: true }, output); + test_minify_sync(assert, input, { removeOptionalTags: true, removeEmptyElements: true }, output); input = ' '; output = ' '; - test_minify(assert, input, { removeOptionalTags: true }, output); + test_minify_sync(assert, input, { removeOptionalTags: true }, output); output = ''; - test_minify(assert, input, { collapseWhitespace: true, removeOptionalTags: true }, output); + test_minify_sync(assert, input, { collapseWhitespace: true, removeOptionalTags: true }, output); input = ' '; output = ' '; - test_minify(assert, input, { removeOptionalTags: true }, output); + test_minify_sync(assert, input, { removeOptionalTags: true }, output); output = ''; - test_minify(assert, input, { collapseWhitespace: true, removeOptionalTags: true }, output); + test_minify_sync(assert, input, { collapseWhitespace: true, removeOptionalTags: true }, output); input = ' '; output = ' '; - test_minify(assert, input, { removeOptionalTags: true }, output); + test_minify_sync(assert, input, { removeOptionalTags: true }, output); output = ''; - test_minify(assert, input, { collapseWhitespace: true, removeOptionalTags: true }, output); + test_minify_sync(assert, input, { collapseWhitespace: true, removeOptionalTags: true }, output); input = ' '; output = ' '; - test_minify(assert, input, { removeOptionalTags: true }, output); + test_minify_sync(assert, input, { removeOptionalTags: true }, output); output = ''; - test_minify(assert, input, { collapseWhitespace: true, removeOptionalTags: true }, output); + test_minify_sync(assert, input, { collapseWhitespace: true, removeOptionalTags: true }, output); input = ' '; output = ' '; - test_minify(assert, input, { removeOptionalTags: true }, output); + test_minify_sync(assert, input, { removeOptionalTags: true }, output); output = ''; - test_minify(assert, input, { collapseWhitespace: true, removeOptionalTags: true }, output); + test_minify_sync(assert, input, { collapseWhitespace: true, removeOptionalTags: true }, output); input = ' '; output = ' '; - test_minify(assert, input, { removeOptionalTags: true }, output); + test_minify_sync(assert, input, { removeOptionalTags: true }, output); output = ''; - test_minify(assert, input, { collapseWhitespace: true, removeOptionalTags: true }, output); + test_minify_sync(assert, input, { collapseWhitespace: true, removeOptionalTags: true }, output); input = ' '; output = ' '; - test_minify(assert, input, { removeOptionalTags: true }, output); + test_minify_sync(assert, input, { removeOptionalTags: true }, output); output = ''; - test_minify(assert, input, { collapseWhitespace: true, removeOptionalTags: true }, output); + test_minify_sync(assert, input, { collapseWhitespace: true, removeOptionalTags: true }, output); input = ' '; output = ' '; - test_minify(assert, input, { removeOptionalTags: true }, output); + test_minify_sync(assert, input, { removeOptionalTags: true }, output); output = ''; - test_minify(assert, input, { collapseWhitespace: true, removeOptionalTags: true }, output); + test_minify_sync(assert, input, { collapseWhitespace: true, removeOptionalTags: true }, output); input = 'hello

    foobar

    '; - test_minify(assert, input, input); + test_minify_sync(assert, input, input); output = 'hello

    foobar'; - test_minify(assert, input, { removeOptionalTags: true }, output); + test_minify_sync(assert, input, { removeOptionalTags: true }, output); input = 'hello

    foobar

    '; output = 'hello

    foobar'; - test_minify(assert, input, { removeOptionalTags: true }, output); + test_minify_sync(assert, input, { removeOptionalTags: true }, output); output = 'hello

    foobar'; - test_minify(assert, input, { removeOptionalTags: true, removeEmptyAttributes: true }, output); + test_minify_sync(assert, input, { removeOptionalTags: true, removeEmptyAttributes: true }, output); input = 'a

    '; output = 'a
    '; - test_minify(assert, input, { removeOptionalTags: true }, output); + test_minify_sync(assert, input, { removeOptionalTags: true }, output); input = 'Blah

    This is some text in a div

    Followed by some details

    This is some more text in a div

    '; output = 'Blah

    This is some text in a div

    Followed by some details

    This is some more text in a div

    '; - test_minify(assert, input, { removeOptionalTags: true }, output); + test_minify_sync(assert, input, { removeOptionalTags: true }, output); input = 'Blah'; output = 'Blah'; - test_minify(assert, input, { removeOptionalTags: true }, output); + test_minify_sync(assert, input, { removeOptionalTags: true }, output); input = '

    Configure

    '; - test_minify(assert, input, { removeOptionalTags: true }, input); + test_minify_sync(assert, input, { removeOptionalTags: true }, input); }); QUnit.test('removing optional tags in tables', function(assert) { @@ -1662,22 +1692,22 @@ QUnit.test('removing optional tags in tables', function(assert) { 'boomooloo ' + 'baz quxboo' + ''; - test_minify(assert, input, input); + test_minify_sync(assert, input, input); output = '' + ' ' + ' ' + '
    foobar baz
    boomooloo
    baz quxboo' + '
    '; - test_minify(assert, input, { removeOptionalTags: true }, output); + test_minify_sync(assert, input, { removeOptionalTags: true }, output); output = '' + '
    foobarbaz' + '
    boomooloo' + '
    bazquxboo' + '
    '; - test_minify(assert, input, { collapseWhitespace: true, removeOptionalTags: true }, output); - test_minify(assert, output, { collapseWhitespace: true, removeOptionalTags: true }, output); + test_minify_sync(assert, input, { collapseWhitespace: true, removeOptionalTags: true }, output); + test_minify_sync(assert, output, { collapseWhitespace: true, removeOptionalTags: true }, output); input = '' + '' + @@ -1686,7 +1716,7 @@ QUnit.test('removing optional tags in tables', function(assert) { '' + '' + '
    foo
    barbazqux
    '; - test_minify(assert, input, input); + test_minify_sync(assert, input, input); output = '' + '' + @@ -1695,23 +1725,23 @@ QUnit.test('removing optional tags in tables', function(assert) { '' + '
    foo
    barbazqux' + '
    '; - test_minify(assert, input, { removeOptionalTags: true }, output); - test_minify(assert, output, { removeOptionalTags: true }, output); + test_minify_sync(assert, input, { removeOptionalTags: true }, output); + test_minify_sync(assert, output, { removeOptionalTags: true }, output); output = '' + '' + '
    foo' + '
    barbazqux' + '
    '; - test_minify(assert, input, { removeComments: true, removeOptionalTags: true }, output); + test_minify_sync(assert, input, { removeComments: true, removeOptionalTags: true }, output); input = '' + '' + '
    '; - test_minify(assert, input, input); + test_minify_sync(assert, input, input); output = '
    '; - test_minify(assert, input, { removeOptionalTags: true }, output); + test_minify_sync(assert, input, { removeOptionalTags: true }, output); }); QUnit.test('removing optional tags in options', function(assert) { @@ -1719,17 +1749,17 @@ QUnit.test('removing optional tags in options', function(assert) { input = ''; output = ''; - test_minify(assert, input, { removeOptionalTags: true }, output); + test_minify_sync(assert, input, { removeOptionalTags: true }, output); input = ''; - test_minify(assert, input, { removeOptionalTags: true }, input); + test_minify_sync(assert, input, { removeOptionalTags: true }, input); output = ''; - test_minify(assert, input, { removeOptionalTags: true, collapseWhitespace: true }, output); + test_minify_sync(assert, input, { removeOptionalTags: true, collapseWhitespace: true }, output); output = ''; - test_minify(assert, input, { removeOptionalTags: true, collapseWhitespace: true, conservativeCollapse: true }, output); + test_minify_sync(assert, input, { removeOptionalTags: true, collapseWhitespace: true, conservativeCollapse: true }, output); // example from htmldog.com input = ''; - test_minify(assert, input, { removeOptionalTags: true }, output); + test_minify_sync(assert, input, { removeOptionalTags: true }, output); }); QUnit.test('custom components', function(assert) { var input = 'Oh, my.'; var output = 'Oh, my.'; - test_minify(assert, input, output); + test_minify_sync(assert, input, output); }); QUnit.test('HTML4: anchor with inline elements', function(assert) { var input = 'Well, look at me! I\'m a span!'; - test_minify(assert, input, { html5: false }, input); + test_minify_sync(assert, input, { html5: false }, input); }); QUnit.test('HTML5: anchor with inline elements', function(assert) { var input = 'Well, look at me! I\'m a span!'; - test_minify(assert, input, { html5: true }, input); + test_minify_sync(assert, input, { html5: true }, input); }); QUnit.test('HTML4: anchor with block elements', function(assert) { var input = '
    Well, look at me! I\'m a div!
    '; var output = '
    Well, look at me! I\'m a div!
    '; - test_minify(assert, input, { html5: false }, output); + test_minify_sync(assert, input, { html5: false }, output); }); QUnit.test('HTML5: anchor with block elements', function(assert) { var input = '
    Well, look at me! I\'m a div!
    '; var output = '
    Well, look at me! I\'m a div!
    '; - test_minify(assert, input, { html5: true }, output); + test_minify_sync(assert, input, { html5: true }, output); }); QUnit.test('HTML5: enabled by default', function(assert) { var input = '
    Well, look at me! I\'m a div!
    '; - test_minify(assert, input, { html5: true }, minify(input)); + test_minify_sync(assert, input, { html5: true }, minify(input)); }); QUnit.test('phrasing content', function(assert) { @@ -1789,12 +1819,12 @@ QUnit.test('phrasing content', function(assert) { input = '

    a

    b
    '; output = '

    a

    b
    '; - test_minify(assert, input, { html5: true }, output); + test_minify_sync(assert, input, { html5: true }, output); output = '

    a

    b

    '; - test_minify(assert, input, { html5: false }, output); + test_minify_sync(assert, input, { html5: false }, output); input = ''; - test_minify(assert, input, { html5: true }, input); + test_minify_sync(assert, input, { html5: true }, input); }); // https://github.com/kangax/html-minifier/issues/888 @@ -1803,29 +1833,29 @@ QUnit.test('ul/ol should be phrasing content', function(assert) { input = '

    a

    • item
    '; output = '

    a

    • item
    '; - test_minify(assert, input, { html5: true }, output); + test_minify_sync(assert, input, { html5: true }, output); output = '

    a

    • item
    '; - test_minify(assert, input, { html5: true, removeOptionalTags: true }, output); + test_minify_sync(assert, input, { html5: true, removeOptionalTags: true }, output); output = '

    a

    • item

    '; - test_minify(assert, input, { html5: false }, output); + test_minify_sync(assert, input, { html5: false }, output); input = '

    a

    1. item

    '; output = '

    a

    1. item

    '; - test_minify(assert, input, { html5: true }, output); + test_minify_sync(assert, input, { html5: true }, output); output = '

    a

    1. item

    '; - test_minify(assert, input, { html5: true, removeOptionalTags: true }, output); + test_minify_sync(assert, input, { html5: true, removeOptionalTags: true }, output); output = '

    a

    1. item
    '; - test_minify(assert, input, { html5: true, removeEmptyElements: true }, output); + test_minify_sync(assert, input, { html5: true, removeEmptyElements: true }, output); }); QUnit.test('phrasing content with Web Components', function(assert) { var input = ''; var output = ''; - test_minify(assert, input, { html5: true }, output); + test_minify_sync(assert, input, { html5: true }, output); }); // https://github.com/kangax/html-minifier/issues/10 @@ -1835,23 +1865,23 @@ QUnit.test('Ignore custom fragments', function(assert) { input = 'This is the start. <% ... %>\r\n<%= ... %>\r\n\r\n\r\nNo comment, but middle.\r\n{{ ... }}\r\n\r\n\r\nHello, this is the end!'; output = 'This is the start. <% ... %> <%= ... %> No comment, but middle. {{ ... }} Hello, this is the end!'; - test_minify(assert, input, {}, input); - test_minify(assert, input, { removeComments: true, collapseWhitespace: true }, output); - test_minify(assert, input, { + test_minify_sync(assert, input, {}, input); + test_minify_sync(assert, input, { removeComments: true, collapseWhitespace: true }, output); + test_minify_sync(assert, input, { removeComments: true, collapseWhitespace: true, ignoreCustomFragments: reFragments }, output); output = 'This is the start. <% ... %>\n<%= ... %>\n\nNo comment, but middle. {{ ... }}\n\n\nHello, this is the end!'; - test_minify(assert, input, { + test_minify_sync(assert, input, { removeComments: true, collapseWhitespace: true, preserveLineBreaks: true }, output); output = 'This is the start. <% ... %>\n<%= ... %>\n\nNo comment, but middle.\n{{ ... }}\n\n\nHello, this is the end!'; - test_minify(assert, input, { + test_minify_sync(assert, input, { removeComments: true, collapseWhitespace: true, preserveLineBreaks: true, @@ -1860,27 +1890,27 @@ QUnit.test('Ignore custom fragments', function(assert) { input = '{{ if foo? }}\r\n
    \r\n ...\r\n
    \r\n{{ end \n}}'; output = '{{ if foo? }}
    ...
    {{ end }}'; - test_minify(assert, input, {}, input); - test_minify(assert, input, { collapseWhitespace: true }, output); - test_minify(assert, input, { collapseWhitespace: true, ignoreCustomFragments: [] }, output); + test_minify_sync(assert, input, {}, input); + test_minify_sync(assert, input, { collapseWhitespace: true }, output); + test_minify_sync(assert, input, { collapseWhitespace: true, ignoreCustomFragments: [] }, output); output = '{{ if foo? }}
    ...
    {{ end \n}}'; - test_minify(assert, input, { collapseWhitespace: true, ignoreCustomFragments: reFragments }, output); + test_minify_sync(assert, input, { collapseWhitespace: true, ignoreCustomFragments: reFragments }, output); output = '{{ if foo? }}\n
    \n...\n
    \n{{ end \n}}'; - test_minify(assert, input, { + test_minify_sync(assert, input, { collapseWhitespace: true, preserveLineBreaks: true, ignoreCustomFragments: reFragments }, output); input = ''; - test_minify(assert, input, {}, input); - test_minify(assert, input, { ignoreCustomFragments: reFragments }, input); + test_minify_sync(assert, input, {}, input); + test_minify_sync(assert, input, { ignoreCustomFragments: reFragments }, input); input = ''; output = ''; - test_minify(assert, input, { ignoreCustomFragments: [/\{%[^%]*?%\}/g] }, output); + test_minify_sync(assert, input, { ignoreCustomFragments: [/\{%[^%]*?%\}/g] }, output); input = '' + '{{ form.name.label_tag }}' + @@ -1892,7 +1922,7 @@ QUnit.test('Ignore custom fragments', function(assert) { '{% endfor %}' + '{% endif %}' + '

    '; - test_minify(assert, input, { + test_minify_sync(assert, input, { ignoreCustomFragments: [ /\{%[\s\S]*?%\}/g, /\{\{[\s\S]*?\}\}/g @@ -1909,7 +1939,7 @@ QUnit.test('Ignore custom fragments', function(assert) { '{% endfor %}' + '{% endif %}' + '

    '; - test_minify(assert, input, { + test_minify_sync(assert, input, { ignoreCustomFragments: [ /\{%[\s\S]*?%\}/g, /\{\{[\s\S]*?\}\}/g @@ -1919,14 +1949,14 @@ QUnit.test('Ignore custom fragments', function(assert) { }, output); input = '>Legal Notices'; - test_minify(assert, input, { + test_minify_sync(assert, input, { ignoreCustomFragments: [ /<\?php[\s\S]*?\?>/g ] }, input); input = '>'; - test_minify(assert, input, { + test_minify_sync(assert, input, { ignoreCustomFragments: [ /<%=[\s\S]*?%>/g ] @@ -1936,7 +1966,7 @@ QUnit.test('Ignore custom fragments', function(assert) { '{{IF text}}' + 'data-yashareDescription="{{shorted(text, 300)}}"' + '{{END IF}}>'; - test_minify(assert, input, { + test_minify_sync(assert, input, { ignoreCustomFragments: [ /\{\{[\s\S]*?\}\}/g ], @@ -1944,14 +1974,14 @@ QUnit.test('Ignore custom fragments', function(assert) { }, input); input = ''; - test_minify(assert, input, { + test_minify_sync(assert, input, { ignoreCustomFragments: [ /\{%[^%]*?%\}/g ] }, input); // trimCustomFragments withOUT collapseWhitespace, does // not break the "{% foo %} {% bar %}" test - test_minify(assert, input, { + test_minify_sync(assert, input, { ignoreCustomFragments: [ /\{%[^%]*?%\}/g ], @@ -1959,7 +1989,7 @@ QUnit.test('Ignore custom fragments', function(assert) { }, input); // trimCustomFragments WITH collapseWhitespace, changes output output = ''; - test_minify(assert, input, { + test_minify_sync(assert, input, { ignoreCustomFragments: [ /\{%[^%]*?%\}/g ], @@ -1968,21 +1998,21 @@ QUnit.test('Ignore custom fragments', function(assert) { }, output); input = ''; - test_minify(assert, input, input); - test_minify(assert, input, { + test_minify_sync(assert, input, input); + test_minify_sync(assert, input, { collapseWhitespace: true }, input); input = '
    '; - test_minify(assert, input, input); - test_minify(assert, input, { + test_minify_sync(assert, input, input); + test_minify_sync(assert, input, { collapseWhitespace: true }, input); input = '{{if a}}
    b
    {{/if}}'; - test_minify(assert, input, input); + test_minify_sync(assert, input, input); output = '{{if a}}
    b
    {{/if}}'; - test_minify(assert, input, { + test_minify_sync(assert, input, { removeComments: true, ignoreCustomFragments: [ /\{\{.*?\}\}/g @@ -1991,69 +2021,69 @@ QUnit.test('Ignore custom fragments', function(assert) { // https://github.com/kangax/html-minifier/issues/722 input = ' bar'; - test_minify(assert, input, input); - test_minify(assert, input, { + test_minify_sync(assert, input, input); + test_minify_sync(assert, input, { collapseWhitespace: true }, input); output = 'bar'; - test_minify(assert, input, { + test_minify_sync(assert, input, { collapseWhitespace: true, trimCustomFragments: true }, output); input = ' bar'; - test_minify(assert, input, input); + test_minify_sync(assert, input, input); output = ' bar'; - test_minify(assert, input, { + test_minify_sync(assert, input, { collapseWhitespace: true }, output); output = 'bar'; - test_minify(assert, input, { + test_minify_sync(assert, input, { collapseWhitespace: true, trimCustomFragments: true }, output); input = 'foo baz'; - test_minify(assert, input, input); - test_minify(assert, input, { + test_minify_sync(assert, input, input); + test_minify_sync(assert, input, { collapseWhitespace: true }, input); output = 'foobaz'; - test_minify(assert, input, { + test_minify_sync(assert, input, { collapseWhitespace: true, trimCustomFragments: true }, output); input = 'foo foo'; - test_minify(assert, input, input); - test_minify(assert, input, { + test_minify_sync(assert, input, input); + test_minify_sync(assert, input, { collapseWhitespace: true }, input); output = 'foofoo'; - test_minify(assert, input, { + test_minify_sync(assert, input, { collapseWhitespace: true, trimCustomFragments: true }, output); input = 'foo baz moo loo'; - test_minify(assert, input, { + test_minify_sync(assert, input, { collapseWhitespace: true, ignoreCustomFragments: [ /<(WC@[\s\S]*?)>(.*?)<\/\1>/ ] }, input); output = 'foobaz mooloo'; - test_minify(assert, input, { + test_minify_sync(assert, input, { collapseWhitespace: true }, output); input = ''; - test_minify(assert, input, input); - test_minify(assert, input, { removeAttributeQuotes: true }, input); + test_minify_sync(assert, input, input); + test_minify_sync(assert, input, { removeAttributeQuotes: true }, input); input = '
    \nfoo\n\nbaz\n
    '; - test_minify(assert, input, input); - test_minify(assert, input, { collapseWhitespace: true }, input); + test_minify_sync(assert, input, input); + test_minify_sync(assert, input, { collapseWhitespace: true }, input); }); QUnit.test('bootstrap\'s span > button > span', function(assert) { @@ -2063,15 +2093,15 @@ QUnit.test('bootstrap\'s span > button > span', function(assert) { '\n ' + ''; var output = ''; - test_minify(assert, input, { collapseWhitespace: true, removeAttributeQuotes: true }, output); + test_minify_sync(assert, input, { collapseWhitespace: true, removeAttributeQuotes: true }, output); }); QUnit.test('caseSensitive', function(assert) { var input = '
    '; var caseSensitiveOutput = '
    '; var caseInSensitiveOutput = '
    '; - test_minify(assert, input, caseInSensitiveOutput); - test_minify(assert, input, { caseSensitive: true }, caseSensitiveOutput); + test_minify_sync(assert, input, caseInSensitiveOutput); + test_minify_sync(assert, input, { caseSensitive: true }, caseSensitiveOutput); }); QUnit.test('source & track', function(assert) { @@ -2081,8 +2111,8 @@ QUnit.test('source & track', function(assert) { '' + '' + ''; - test_minify(assert, input, input); - test_minify(assert, input, { removeOptionalTags: true }, input); + test_minify_sync(assert, input, input); + test_minify_sync(assert, input, { removeOptionalTags: true }, input); }); QUnit.test('mixed html and svg', function(assert) { @@ -2107,18 +2137,18 @@ QUnit.test('mixed html and svg', function(assert) { '' + ''; // Should preserve case-sensitivity and closing slashes within svg tags - test_minify(assert, input, { collapseWhitespace: true }, output); + test_minify_sync(assert, input, { collapseWhitespace: true }, output); }); QUnit.test('nested quotes', function(assert) { var input, output; input = '
    '; - test_minify(assert, input, input); - test_minify(assert, input, { quoteCharacter: '\'' }, input); + test_minify_sync(assert, input, input); + test_minify_sync(assert, input, { quoteCharacter: '\'' }, input); output = '
    '; - test_minify(assert, input, { quoteCharacter: '"' }, output); + test_minify_sync(assert, input, { quoteCharacter: '"' }, output); }); QUnit.test('script minification', function(assert) { @@ -2126,32 +2156,32 @@ QUnit.test('script minification', function(assert) { input = '(function(){ var foo = 1; var bar = 2; alert(foo + " " + bar); })()'; - test_minify(assert, input, { minifyJS: true }, input); + test_minify_sync(assert, input, { minifyJS: true }, input); input = ''; output = ''; - test_minify(assert, input, { minifyJS: true }, output); + test_minify_sync(assert, input, { minifyJS: true }, output); input = ''; output = ''; - test_minify(assert, input, { minifyJS: true }, output); + test_minify_sync(assert, input, { minifyJS: true }, output); input = ''; output = ''; - test_minify(assert, input, { minifyJS: true }, output); + test_minify_sync(assert, input, { minifyJS: true }, output); input = ''; output = ''; - test_minify(assert, input, { minifyJS: true }, output); + test_minify_sync(assert, input, { minifyJS: true }, output); input = ''; output = ''; - test_minify(assert, input, { minifyJS: { mangle: false } }, output); + test_minify_sync(assert, input, { minifyJS: { mangle: false } }, output); input = ''; output = ''; - test_minify(assert, input, { minifyJS: true }, output); + test_minify_sync(assert, input, { minifyJS: true }, output); }); QUnit.test('minification of scripts with different mimetypes', function(assert) { @@ -2172,68 +2202,68 @@ QUnit.test('minification of scripts with different mimetypes', function(assert) input = ''; output = ''; - test_minify(assert, input, { minifyJS: true }, output); + test_minify_sync(assert, input, { minifyJS: true }, output); input = ''; output = ''; - test_minify(assert, input, { minifyJS: true }, output); + test_minify_sync(assert, input, { minifyJS: true }, output); input = ''; output = ''; - test_minify(assert, input, { minifyJS: true }, output); + test_minify_sync(assert, input, { minifyJS: true }, output); input = ''; output = ''; - test_minify(assert, input, { minifyJS: true }, output); + test_minify_sync(assert, input, { minifyJS: true }, output); input = ''; output = ''; - test_minify(assert, input, { minifyJS: true }, output); + test_minify_sync(assert, input, { minifyJS: true }, output); input = ''; - test_minify(assert, input, { minifyJS: true }, input); + test_minify_sync(assert, input, { minifyJS: true }, input); input = ''; - test_minify(assert, input, { minifyJS: true }, input); + test_minify_sync(assert, input, { minifyJS: true }, input); }); QUnit.test('minification of scripts with custom fragments', function(assert) { var input, output; input = ''; - test_minify(assert, input, { minifyJS: true }, input); - test_minify(assert, input, { collapseWhitespace: true, minifyJS: true }, input); - test_minify(assert, input, { + test_minify_sync(assert, input, { minifyJS: true }, input); + test_minify_sync(assert, input, { collapseWhitespace: true, minifyJS: true }, input); + test_minify_sync(assert, input, { collapseWhitespace: true, minifyJS: true, preserveLineBreaks: true }, input); input = ''; - test_minify(assert, input, { minifyJS: true }, input); + test_minify_sync(assert, input, { minifyJS: true }, input); output = ''; - test_minify(assert, input, { collapseWhitespace: true, minifyJS: true }, output); - test_minify(assert, input, { + test_minify_sync(assert, input, { collapseWhitespace: true, minifyJS: true }, output); + test_minify_sync(assert, input, { collapseWhitespace: true, minifyJS: true, preserveLineBreaks: true }, input); input = ''; - test_minify(assert, input, { minifyJS: true }, input); + test_minify_sync(assert, input, { minifyJS: true }, input); output = ''; - test_minify(assert, input, { collapseWhitespace: true, minifyJS: true }, output); - test_minify(assert, input, { + test_minify_sync(assert, input, { collapseWhitespace: true, minifyJS: true }, output); + test_minify_sync(assert, input, { collapseWhitespace: true, minifyJS: true, preserveLineBreaks: true }, input); input = ''; - test_minify(assert, input, { minifyJS: true }, input); + test_minify_sync(assert, input, { minifyJS: true }, input); output = ''; - test_minify(assert, input, { collapseWhitespace: true, minifyJS: true }, output); - test_minify(assert, input, { + test_minify_sync(assert, input, { collapseWhitespace: true, minifyJS: true }, output); + test_minify_sync(assert, input, { collapseWhitespace: true, minifyJS: true, preserveLineBreaks: true @@ -2241,9 +2271,9 @@ QUnit.test('minification of scripts with custom fragments', function(assert) { input = ''; output = ''; - test_minify(assert, input, { minifyJS: true }, output); - test_minify(assert, input, { collapseWhitespace: true, minifyJS: true }, output); - test_minify(assert, input, { + test_minify_sync(assert, input, { minifyJS: true }, output); + test_minify_sync(assert, input, { collapseWhitespace: true, minifyJS: true }, output); + test_minify_sync(assert, input, { collapseWhitespace: true, minifyJS: true, preserveLineBreaks: true @@ -2251,11 +2281,11 @@ QUnit.test('minification of scripts with custom fragments', function(assert) { input = ''; output = ''; - test_minify(assert, input, { minifyJS: true }, output); + test_minify_sync(assert, input, { minifyJS: true }, output); output = ''; - test_minify(assert, input, { collapseWhitespace: true, minifyJS: true }, output); + test_minify_sync(assert, input, { collapseWhitespace: true, minifyJS: true }, output); output = ''; - test_minify(assert, input, { + test_minify_sync(assert, input, { collapseWhitespace: true, minifyJS: true, preserveLineBreaks: true @@ -2263,9 +2293,9 @@ QUnit.test('minification of scripts with custom fragments', function(assert) { input = ''; output = ''; - test_minify(assert, input, { minifyJS: true }, output); - test_minify(assert, input, { collapseWhitespace: true, minifyJS: true }, output); - test_minify(assert, input, { + test_minify_sync(assert, input, { minifyJS: true }, output); + test_minify_sync(assert, input, { collapseWhitespace: true, minifyJS: true }, output); + test_minify_sync(assert, input, { collapseWhitespace: true, minifyJS: true, preserveLineBreaks: true @@ -2273,11 +2303,11 @@ QUnit.test('minification of scripts with custom fragments', function(assert) { input = ''; output = ''; - test_minify(assert, input, { minifyJS: true }, output); + test_minify_sync(assert, input, { minifyJS: true }, output); output = ''; - test_minify(assert, input, { collapseWhitespace: true, minifyJS: true }, output); + test_minify_sync(assert, input, { collapseWhitespace: true, minifyJS: true }, output); output = ''; - test_minify(assert, input, { + test_minify_sync(assert, input, { collapseWhitespace: true, minifyJS: true, preserveLineBreaks: true @@ -2285,146 +2315,146 @@ QUnit.test('minification of scripts with custom fragments', function(assert) { input = ''; output = ''; - test_minify(assert, input, { minifyJS: true }, output); + test_minify_sync(assert, input, { minifyJS: true }, output); output = ''; - test_minify(assert, input, { collapseWhitespace: true, minifyJS: true }, output); + test_minify_sync(assert, input, { collapseWhitespace: true, minifyJS: true }, output); input = ''; output = ''; - test_minify(assert, input, { minifyJS: true }, output); - test_minify(assert, input, { collapseWhitespace: true, minifyJS: true }, output); + test_minify_sync(assert, input, { minifyJS: true }, output); + test_minify_sync(assert, input, { collapseWhitespace: true, minifyJS: true }, output); }); QUnit.test('event minification', function(assert) { var input, output; input = '
    '; - test_minify(assert, input, { minifyJS: true }, input); + test_minify_sync(assert, input, { minifyJS: true }, input); input = '
    '; output = '
    '; - test_minify(assert, input, { minifyJS: true }, output); + test_minify_sync(assert, input, { minifyJS: true }, output); input = 'test'; output = 'test'; - test_minify(assert, input, { minifyJS: true }, output); + test_minify_sync(assert, input, { minifyJS: true }, output); input = ' foobar'; output = ' foobar'; - test_minify(assert, input, { minifyJS: { mangle: false } }, output); - test_minify(assert, input, { minifyJS: { mangle: false }, quoteCharacter: '\'' }, output); + test_minify_sync(assert, input, { minifyJS: { mangle: false } }, output); + test_minify_sync(assert, input, { minifyJS: { mangle: false }, quoteCharacter: '\'' }, output); input = ' foobar'; output = ' foobar'; - test_minify(assert, input, { minifyJS: { mangle: false }, quoteCharacter: '"' }, output); + test_minify_sync(assert, input, { minifyJS: { mangle: false }, quoteCharacter: '"' }, output); input = ''; output = ''; - test_minify(assert, input, { minifyJS: true }, output); - test_minify(assert, input, { minifyJS: true, quoteCharacter: '\'' }, output); + test_minify_sync(assert, input, { minifyJS: true }, output); + test_minify_sync(assert, input, { minifyJS: true, quoteCharacter: '\'' }, output); input = ''; output = ''; - test_minify(assert, input, { minifyJS: true, quoteCharacter: '"' }, output); + test_minify_sync(assert, input, { minifyJS: true, quoteCharacter: '"' }, output); input = ''; output = ''; - test_minify(assert, input, { minifyJS: true }, output); + test_minify_sync(assert, input, { minifyJS: true }, output); input = ''; output = ''; - test_minify(assert, input, { minifyJS: true }, output); - test_minify(assert, input, { minifyJS: true, customEventAttributes: [] }, input); + test_minify_sync(assert, input, { minifyJS: true }, output); + test_minify_sync(assert, input, { minifyJS: true, customEventAttributes: [] }, input); output = ''; - test_minify(assert, input, { minifyJS: true, customEventAttributes: [/^ng-/] }, output); + test_minify_sync(assert, input, { minifyJS: true, customEventAttributes: [/^ng-/] }, output); output = ''; - test_minify(assert, input, { minifyJS: true, customEventAttributes: [/^on/, /^ng-/] }, output); + test_minify_sync(assert, input, { minifyJS: true, customEventAttributes: [/^on/, /^ng-/] }, output); input = '
    '; - test_minify(assert, input, { minifyJS: true }, input); + test_minify_sync(assert, input, { minifyJS: true }, input); input = '
    '; output = '
    '; - test_minify(assert, input, { minifyJS: true }, output); + test_minify_sync(assert, input, { minifyJS: true }, output); input = '
    '; output = '
    ")\'>
    '; - test_minify(assert, input, { minifyJS: true }, output); + test_minify_sync(assert, input, { minifyJS: true }, output); }); QUnit.test('escaping closing script tag', function(assert) { var input = ''; var output = ''; - test_minify(assert, input, { minifyJS: true }, output); + test_minify_sync(assert, input, { minifyJS: true }, output); }); QUnit.test('style minification', function(assert) { var input, output; input = 'div#foo { background-color: red; color: white }'; - test_minify(assert, input, { minifyCSS: true }, input); + test_minify_sync(assert, input, { minifyCSS: true }, input); input = ''; output = ''; - test_minify(assert, input, input); - test_minify(assert, input, { minifyCSS: true }, output); + test_minify_sync(assert, input, input); + test_minify_sync(assert, input, { minifyCSS: true }, output); input = ''; output = ''; - test_minify(assert, input, { minifyCSS: true }, output); + test_minify_sync(assert, input, { minifyCSS: true }, output); input = '
    '; - test_minify(assert, input, input); + test_minify_sync(assert, input, input); output = '
    '; - test_minify(assert, input, { minifyCSS: true }, output); - test_minify(assert, input, { + test_minify_sync(assert, input, { minifyCSS: true }, output); + test_minify_sync(assert, input, { collapseWhitespace: true, minifyCSS: true }, output); input = '
    '; - test_minify(assert, input, input); + test_minify_sync(assert, input, input); output = '
    '; - test_minify(assert, input, { minifyCSS: true }, output); - test_minify(assert, input, { + test_minify_sync(assert, input, { minifyCSS: true }, output); + test_minify_sync(assert, input, { collapseWhitespace: true, minifyCSS: true }, output); input = ''; - test_minify(assert, input, input); + test_minify_sync(assert, input, input); output = ''; - test_minify(assert, input, { minifyCSS: true }, output); - test_minify(assert, input, { + test_minify_sync(assert, input, { minifyCSS: true }, output); + test_minify_sync(assert, input, { collapseWhitespace: true, minifyCSS: true }, output); input = ''; - test_minify(assert, input, input); + test_minify_sync(assert, input, input); output = ''; - test_minify(assert, input, { minifyCSS: true }, output); - test_minify(assert, input, { + test_minify_sync(assert, input, { minifyCSS: true }, output); + test_minify_sync(assert, input, { collapseWhitespace: true, minifyCSS: true }, output); input = ''; - test_minify(assert, input, input); + test_minify_sync(assert, input, input); output = ''; - test_minify(assert, input, { minifyCSS: true }, output); + test_minify_sync(assert, input, { minifyCSS: true }, output); output = ''; - test_minify(assert, input, { + test_minify_sync(assert, input, { minifyCSS: true, removeAttributeQuotes: true }, output); input = ''; - test_minify(assert, input, input); + test_minify_sync(assert, input, input); output = ''; - test_minify(assert, input, { minifyCSS: true }, output); + test_minify_sync(assert, input, { minifyCSS: true }, output); output = ''; - test_minify(assert, input, { + test_minify_sync(assert, input, { minifyCSS: true, removeAttributeQuotes: true }, output); @@ -2433,7 +2463,7 @@ QUnit.test('style minification', function(assert) { QUnit.test('style attribute minification', function(assert) { var input = '
    '; var output = '
    '; - test_minify(assert, input, { minifyCSS: true }, output); + test_minify_sync(assert, input, { minifyCSS: true }, output); }); QUnit.test('url attribute minification', function(assert) { @@ -2441,61 +2471,61 @@ QUnit.test('url attribute minification', function(assert) { input = '
    link
    '; output = '
    link
    '; - test_minify(assert, input, { minifyURLs: 'http://website.com/folder/' }, output); - test_minify(assert, input, { minifyURLs: { site: 'http://website.com/folder/' } }, output); + test_minify_sync(assert, input, { minifyURLs: 'http://website.com/folder/' }, output); + test_minify_sync(assert, input, { minifyURLs: { site: 'http://website.com/folder/' } }, output); input = ''; - test_minify(assert, input, { minifyURLs: 'http://website.com/' }, input); - test_minify(assert, input, { minifyURLs: { site: 'http://website.com/' } }, input); + test_minify_sync(assert, input, { minifyURLs: 'http://website.com/' }, input); + test_minify_sync(assert, input, { minifyURLs: { site: 'http://website.com/' } }, input); input = ''; - test_minify(assert, input, { minifyURLs: 'http://website.com/' }, input); - test_minify(assert, input, { minifyURLs: { site: 'http://website.com/' } }, input); + test_minify_sync(assert, input, { minifyURLs: 'http://website.com/' }, input); + test_minify_sync(assert, input, { minifyURLs: { site: 'http://website.com/' } }, input); output = ''; - test_minify(assert, input, { minifyCSS: true }, output); + test_minify_sync(assert, input, { minifyCSS: true }, output); output = ''; - test_minify(assert, input, { + test_minify_sync(assert, input, { minifyCSS: true, minifyURLs: 'http://website.com/' }, output); - test_minify(assert, input, { + test_minify_sync(assert, input, { minifyCSS: true, minifyURLs: { site: 'http://website.com/' } }, output); input = ''; - test_minify(assert, input, { minifyURLs: { site: 'http://website.com/foo bar/' } }, input); + test_minify_sync(assert, input, { minifyURLs: { site: 'http://website.com/foo bar/' } }, input); output = ''; - test_minify(assert, input, { minifyCSS: true }, output); + test_minify_sync(assert, input, { minifyCSS: true }, output); output = ''; - test_minify(assert, input, { + test_minify_sync(assert, input, { minifyCSS: true, minifyURLs: { site: 'http://website.com/foo bar/' } }, output); input = ''; - test_minify(assert, input, { minifyURLs: { site: 'http://website.com/' } }, input); - test_minify(assert, input, { minifyURLs: { site: 'http://website.com/foo%20bar/' } }, input); - test_minify(assert, input, { minifyURLs: { site: 'http://website.com/foo%20bar/(baz)/' } }, input); + test_minify_sync(assert, input, { minifyURLs: { site: 'http://website.com/' } }, input); + test_minify_sync(assert, input, { minifyURLs: { site: 'http://website.com/foo%20bar/' } }, input); + test_minify_sync(assert, input, { minifyURLs: { site: 'http://website.com/foo%20bar/(baz)/' } }, input); output = ''; - test_minify(assert, input, { + test_minify_sync(assert, input, { minifyCSS: true, minifyURLs: { site: 'http://website.com/' } }, output); output = ''; - test_minify(assert, input, { + test_minify_sync(assert, input, { minifyCSS: true, minifyURLs: { site: 'http://website.com/foo%20bar/' } }, output); output = ''; - test_minify(assert, input, { + test_minify_sync(assert, input, { minifyCSS: true, minifyURLs: { site: 'http://website.com/foo%20bar/(baz)/' } }, output); input = ''; output = ''; - test_minify(assert, input, { minifyURLs: { site: 'http://site.com/' } }, output); + test_minify_sync(assert, input, { minifyURLs: { site: 'http://site.com/' } }, output); }); QUnit.test('srcset attribute minification', function(assert) { @@ -2503,20 +2533,20 @@ QUnit.test('srcset attribute minification', function(assert) { input = ''; output = ''; - test_minify(assert, input, output); + test_minify_sync(assert, input, output); output = ''; - test_minify(assert, input, { minifyURLs: { site: 'http://site.com/' } }, output); + test_minify_sync(assert, input, { minifyURLs: { site: 'http://site.com/' } }, output); }); QUnit.test('valueless attributes', function(assert) { var input = '
    '; - test_minify(assert, input, input); + test_minify_sync(assert, input, input); }); QUnit.test('newlines becoming whitespaces', function(assert) { var input = 'test\n\n\n\ntest'; var output = 'test test'; - test_minify(assert, input, { collapseWhitespace: true }, output); + test_minify_sync(assert, input, { collapseWhitespace: true }, output); }); QUnit.test('conservative collapse', function(assert) { @@ -2524,86 +2554,86 @@ QUnit.test('conservative collapse', function(assert) { input = ' foo \n\n'; output = ' foo '; - test_minify(assert, input, { + test_minify_sync(assert, input, { collapseWhitespace: true, conservativeCollapse: true }, output); input = '\n\n\n\n'; output = ' '; - test_minify(assert, input, { + test_minify_sync(assert, input, { removeComments: true, collapseWhitespace: true, conservativeCollapse: true }, output); input = '

    \u00A0

    '; - test_minify(assert, input, { collapseWhitespace: true }, input); - test_minify(assert, input, { + test_minify_sync(assert, input, { collapseWhitespace: true }, input); + test_minify_sync(assert, input, { collapseWhitespace: true, conservativeCollapse: true }, input); input = '

    \u00A0

    '; output = '

    \u00A0

    '; - test_minify(assert, input, { collapseWhitespace: true }, output); - test_minify(assert, input, { + test_minify_sync(assert, input, { collapseWhitespace: true }, output); + test_minify_sync(assert, input, { collapseWhitespace: true, conservativeCollapse: true }, output); input = '

    \u00A0

    '; output = '

    \u00A0

    '; - test_minify(assert, input, { collapseWhitespace: true }, output); - test_minify(assert, input, { + test_minify_sync(assert, input, { collapseWhitespace: true }, output); + test_minify_sync(assert, input, { collapseWhitespace: true, conservativeCollapse: true }, output); input = '

    \u00A0

    '; output = '

    \u00A0

    '; - test_minify(assert, input, { collapseWhitespace: true }, output); - test_minify(assert, input, { + test_minify_sync(assert, input, { collapseWhitespace: true }, output); + test_minify_sync(assert, input, { collapseWhitespace: true, conservativeCollapse: true }, output); input = '

    \u00A0\u00A0 \u00A0

    '; output = '

    \u00A0\u00A0 \u00A0

    '; - test_minify(assert, input, { collapseWhitespace: true }, output); - test_minify(assert, input, { + test_minify_sync(assert, input, { collapseWhitespace: true }, output); + test_minify_sync(assert, input, { collapseWhitespace: true, conservativeCollapse: true }, output); input = '

    foo \u00A0\u00A0 \u00A0

    '; output = '

    foo \u00A0\u00A0 \u00A0

    '; - test_minify(assert, input, { collapseWhitespace: true }, output); - test_minify(assert, input, { + test_minify_sync(assert, input, { collapseWhitespace: true }, output); + test_minify_sync(assert, input, { collapseWhitespace: true, conservativeCollapse: true }, output); input = '

    \u00A0\u00A0 \u00A0 bar

    '; output = '

    \u00A0\u00A0 \u00A0 bar

    '; - test_minify(assert, input, { collapseWhitespace: true }, output); - test_minify(assert, input, { + test_minify_sync(assert, input, { collapseWhitespace: true }, output); + test_minify_sync(assert, input, { collapseWhitespace: true, conservativeCollapse: true }, output); input = '

    foo \u00A0\u00A0 \u00A0 bar

    '; output = '

    foo \u00A0\u00A0 \u00A0 bar

    '; - test_minify(assert, input, { collapseWhitespace: true }, output); - test_minify(assert, input, { + test_minify_sync(assert, input, { collapseWhitespace: true }, output); + test_minify_sync(assert, input, { collapseWhitespace: true, conservativeCollapse: true }, output); input = '

    \u00A0foo\u00A0\t

    '; output = '

    \u00A0foo\u00A0

    '; - test_minify(assert, input, { collapseWhitespace: true }, output); - test_minify(assert, input, { + test_minify_sync(assert, input, { collapseWhitespace: true }, output); + test_minify_sync(assert, input, { collapseWhitespace: true, conservativeCollapse: true }, output); @@ -2611,8 +2641,8 @@ QUnit.test('conservative collapse', function(assert) { input = '

    \u00A0\nfoo\u00A0\t

    '; output = '

    \u00A0 foo\u00A0

    '; - test_minify(assert, input, { collapseWhitespace: true }, output); - test_minify(assert, input, { + test_minify_sync(assert, input, { collapseWhitespace: true }, output); + test_minify_sync(assert, input, { collapseWhitespace: true, conservativeCollapse: true }, output); @@ -2620,16 +2650,16 @@ QUnit.test('conservative collapse', function(assert) { input = '

    \u00A0foo \u00A0\t

    '; output = '

    \u00A0foo \u00A0

    '; - test_minify(assert, input, { collapseWhitespace: true }, output); - test_minify(assert, input, { + test_minify_sync(assert, input, { collapseWhitespace: true }, output); + test_minify_sync(assert, input, { collapseWhitespace: true, conservativeCollapse: true }, output); input = '

    \u00A0\nfoo \u00A0\t

    '; output = '

    \u00A0 foo \u00A0

    '; - test_minify(assert, input, { collapseWhitespace: true }, output); - test_minify(assert, input, { + test_minify_sync(assert, input, { collapseWhitespace: true }, output); + test_minify_sync(assert, input, { collapseWhitespace: true, conservativeCollapse: true }, output); @@ -2662,11 +2692,11 @@ QUnit.test('collapse preseving a line break', function(assert) { '\n' + '\n' + '\n\n

    \ntest test test\n

    \n'; - test_minify(assert, input, { + test_minify_sync(assert, input, { collapseWhitespace: true, preserveLineBreaks: true }, output); - test_minify(assert, input, { + test_minify_sync(assert, input, { collapseWhitespace: true, conservativeCollapse: true, preserveLineBreaks: true @@ -2682,7 +2712,7 @@ QUnit.test('collapse preseving a line break', function(assert) { '\n' + '\n' + '\n\n

    \ntest test test\n

    \n'; - test_minify(assert, input, { + test_minify_sync(assert, input, { collapseWhitespace: true, conservativeCollapse: true, preserveLineBreaks: true, @@ -2691,19 +2721,19 @@ QUnit.test('collapse preseving a line break', function(assert) { input = '
    text \n text \n
    '; output = '
    text \ntext\n
    '; - test_minify(assert, input, { + test_minify_sync(assert, input, { collapseWhitespace: true, preserveLineBreaks: true }, output); input = '
    text \n
    '; output = '
    text\n
    '; - test_minify(assert, input, { + test_minify_sync(assert, input, { collapseWhitespace: true, preserveLineBreaks: true }, output); output = '
    text\n
    '; - test_minify(assert, input, { + test_minify_sync(assert, input, { collapseWhitespace: true, conservativeCollapse: true, preserveLineBreaks: true @@ -2711,12 +2741,12 @@ QUnit.test('collapse preseving a line break', function(assert) { input = '
    \ntext
    '; output = '
    \ntext
    '; - test_minify(assert, input, { + test_minify_sync(assert, input, { collapseWhitespace: true, preserveLineBreaks: true }, output); output = '
    \ntext
    '; - test_minify(assert, input, { + test_minify_sync(assert, input, { collapseWhitespace: true, conservativeCollapse: true, preserveLineBreaks: true @@ -2724,7 +2754,7 @@ QUnit.test('collapse preseving a line break', function(assert) { input = 'This is the start. <% ... %>\r\n<%= ... %>\r\n\r\n\r\nNo comment, but middle.\r\n\r\n\r\n\r\nHello, this is the end!'; output = 'This is the start. <% ... %>\n<%= ... %>\n\nNo comment, but middle.\n\n\n\nHello, this is the end!'; - test_minify(assert, input, { + test_minify_sync(assert, input, { removeComments: true, collapseWhitespace: true, preserveLineBreaks: true @@ -2735,24 +2765,24 @@ QUnit.test('collapse inline tag whitespace', function(assert) { var input, output; input = ' '; - test_minify(assert, input, { + test_minify_sync(assert, input, { collapseWhitespace: true }, input); output = ''; - test_minify(assert, input, { + test_minify_sync(assert, input, { collapseWhitespace: true, collapseInlineTagWhitespace: true }, output); input = '

    where R is the Rici tensor.

    '; output = '

    where R is the Rici tensor.

    '; - test_minify(assert, input, { + test_minify_sync(assert, input, { collapseWhitespace: true }, output); output = '

    whereRis the Rici tensor.

    '; - test_minify(assert, input, { + test_minify_sync(assert, input, { collapseWhitespace: true, collapseInlineTagWhitespace: true }, output); @@ -2762,34 +2792,34 @@ QUnit.test('ignore custom comments', function(assert) { var input, output; input = ''; - test_minify(assert, input, input); - test_minify(assert, input, { removeComments: true }, input); - test_minify(assert, input, { ignoreCustomComments: false }, input); - test_minify(assert, input, { + test_minify_sync(assert, input, input); + test_minify_sync(assert, input, { removeComments: true }, input); + test_minify_sync(assert, input, { ignoreCustomComments: false }, input); + test_minify_sync(assert, input, { removeComments: true, ignoreCustomComments: [] }, ''); - test_minify(assert, input, { + test_minify_sync(assert, input, { removeComments: true, ignoreCustomComments: false }, ''); input = 'test'; output = 'test'; - test_minify(assert, input, output); - test_minify(assert, input, { removeComments: true }, output); - test_minify(assert, input, { ignoreCustomComments: false }, output); - test_minify(assert, input, { + test_minify_sync(assert, input, output); + test_minify_sync(assert, input, { removeComments: true }, output); + test_minify_sync(assert, input, { ignoreCustomComments: false }, output); + test_minify_sync(assert, input, { removeComments: true, ignoreCustomComments: [] }, output); - test_minify(assert, input, { + test_minify_sync(assert, input, { removeComments: true, ignoreCustomComments: false }, output); input = '
  • test
  • '; - test_minify(assert, input, { + test_minify_sync(assert, input, { removeComments: true, // ignore knockout comments ignoreCustomComments: [ @@ -2799,7 +2829,7 @@ QUnit.test('ignore custom comments', function(assert) { }, input); input = ''; - test_minify(assert, input, { + test_minify_sync(assert, input, { removeComments: true, // ignore Apache SSI includes ignoreCustomComments: [ @@ -2811,7 +2841,7 @@ QUnit.test('ignore custom comments', function(assert) { QUnit.test('processScripts', function(assert) { var input = ''; var output = ''; - test_minify(assert, input, { + test_minify_sync(assert, input, { collapseWhitespace: true, removeComments: true, processScripts: ['text/ng-template'] @@ -2825,10 +2855,10 @@ QUnit.test('ignore', function(assert) { '
    \n test foo \n\n
    '; output = '
    \n test foo \n\n
    ' + '
    test foo
    '; - test_minify(assert, input, { collapseWhitespace: true }, output); + test_minify_sync(assert, input, { collapseWhitespace: true }, output); input = ''; - test_minify(assert, input, ''); + test_minify_sync(assert, input, ''); input = '

    .....

    ' + '@for( $i = 0 ; $i < $criterions->count() ; $i++ )' + @@ -2840,23 +2870,23 @@ QUnit.test('ignore', function(assert) { '

    {{ $criterions[$i]->value }}

    ' + '@endfor' + '

    ....

    '; - test_minify(assert, input, { removeComments: true }, output); + test_minify_sync(assert, input, { removeComments: true }, output); input = '

    bar

    '; output = '

    bar

    '; - test_minify(assert, input, output); + test_minify_sync(assert, input, output); input = '>'; output = '>'; - test_minify(assert, input, { ignoreCustomFragments: [/<\?php[\s\S]*?\?>/] }, output); + test_minify_sync(assert, input, { ignoreCustomFragments: [/<\?php[\s\S]*?\?>/] }, output); input = 'a\nb'; output = 'a b'; - test_minify(assert, input, { collapseWhitespace: true }, output); + test_minify_sync(assert, input, { collapseWhitespace: true }, output); input = '

    foo \n\tbar\n.

    '; output = '

    foo \n\tbar\n.

    '; - test_minify(assert, input, { collapseWhitespace: true }, output); + test_minify_sync(assert, input, { collapseWhitespace: true }, output); }); QUnit.test('meta viewport', function(assert) { @@ -2864,36 +2894,36 @@ QUnit.test('meta viewport', function(assert) { input = ''; output = ''; - test_minify(assert, input, output); + test_minify_sync(assert, input, output); input = ''; output = ''; - test_minify(assert, input, output); + test_minify_sync(assert, input, output); input = ''; output = ''; - test_minify(assert, input, output); + test_minify_sync(assert, input, output); input = ''; output = ''; - test_minify(assert, input, output); + test_minify_sync(assert, input, output); }); QUnit.test('downlevel-revealed conditional comments', function(assert) { var input = ''; - test_minify(assert, input, input); - test_minify(assert, input, { removeComments: true }, input); + test_minify_sync(assert, input, input); + test_minify_sync(assert, input, { removeComments: true }, input); }); QUnit.test('noscript', function(assert) { var input; input = ''; - test_minify(assert, input, ''); + test_minify_sync(assert, input, ''); input = ''; - test_minify(assert, input, { removeComments: true, collapseWhitespace: true, removeEmptyAttributes: true }, + test_minify_sync(assert, input, { removeComments: true, collapseWhitespace: true, removeEmptyAttributes: true }, ''); }); @@ -2902,57 +2932,57 @@ QUnit.test('max line length', function(assert) { var options = { maxLineLength: 25 }; input = '123456789012345678901234567890'; - test_minify(assert, input, options, input); + test_minify_sync(assert, input, options, input); input = '
    '; - test_minify(assert, input, options, '
    \n
    '); + test_minify_sync(assert, input, options, '
    \n
    '); input = ' hello world \n world hello '; - test_minify(assert, input, options, '\n hello world \n world hello \n'); + test_minify_sync(assert, input, options, '\n hello world \n world hello \n'); - test_minify(assert, '

    x

    ', '

    x

    '); - test_minify(assert, '

    x

    ', '

    x

    '); - test_minify(assert, '

    x

    ', '

    x

    '); - test_minify(assert, '

    xxx

    ', '

    xxx

    '); - test_minify(assert, '

    xxx

    ', '

    xxx

    '); + test_minify_sync(assert, '

    x

    ', '

    x

    '); + test_minify_sync(assert, '

    x

    ', '

    x

    '); + test_minify_sync(assert, '

    x

    ', '

    x

    '); + test_minify_sync(assert, '

    xxx

    ', '

    xxx

    '); + test_minify_sync(assert, '

    xxx

    ', '

    xxx

    '); input = '
    ' + 'i\'m 10 levels deep' + '
    '; - test_minify(assert, input, input); + test_minify_sync(assert, input, input); - test_minify(assert, '', options, ''); + test_minify_sync(assert, '', options, ''); input = ''; - test_minify(assert, '', options, input); - test_minify(assert, input, options, input); - test_minify(assert, '', options, ''); - - test_minify(assert, 'foo', options, 'foo\n'); - test_minify(assert, '

    x', options, '

    x

    '); - test_minify(assert, '

    x

    ', options, '

    x

    ', 'trailing quote should be ignored'); - test_minify(assert, '

    Click me

    ', options, '

    Click me\n

    '); + test_minify_sync(assert, '', options, input); + test_minify_sync(assert, input, options, input); + test_minify_sync(assert, '', options, ''); + + test_minify_sync(assert, 'foo', options, 'foo\n'); + test_minify_sync(assert, '

    x', options, '

    x

    '); + test_minify_sync(assert, '

    x

    ', options, '

    x

    ', 'trailing quote should be ignored'); + test_minify_sync(assert, '

    Click me

    ', options, '

    Click me\n

    '); input = ''; - test_minify(assert, '', options, input); - test_minify(assert, input, options, input); - test_minify(assert, '
    [fallback image]
    ', options, + test_minify_sync(assert, '', options, input); + test_minify_sync(assert, input, options, input); + test_minify_sync(assert, '
    [fallback image]
    ', options, '
    \n[fallback image]
    \n
    ' ); - test_minify(assert, '', options, '\n'); - test_minify(assert, '', options, '\n'); - test_minify(assert, '
    ', options, + test_minify_sync(assert, '', options, '\n'); + test_minify_sync(assert, '', options, '\n'); + test_minify_sync(assert, '
    ', options, '\n
    ' ); - test_minify(assert, '', options, + test_minify_sync(assert, '', options, '\n\n\n' ); - test_minify(assert, '[\']["]', options, '[\']["]'); - test_minify(assert, '
    hey
    ', options, '\n
    hey
    '); - test_minify(assert, ':) link', options, ':) \nlink'); - test_minify(assert, ':) \nlink', options, ':) \nlink'); - test_minify(assert, ':) \n\nlink', options, ':) \n\nlink'); + test_minify_sync(assert, '[\']["]', options, '[\']["]'); + test_minify_sync(assert, '
    hey
    ', options, '\n
    hey
    '); + test_minify_sync(assert, ':) link', options, ':) \nlink'); + test_minify_sync(assert, ':) \nlink', options, ':) \nlink'); + test_minify_sync(assert, ':) \n\nlink', options, ':) \n\nlink'); - test_minify(assert, 'ok', options, 'ok'); + test_minify_sync(assert, 'ok', options, 'ok'); }); QUnit.test('custom attribute collapse', function(assert) { @@ -2969,15 +2999,15 @@ QUnit.test('custom attribute collapse', function(assert) { '">foo'; output = '
    foo
    '; - test_minify(assert, input, input); - test_minify(assert, input, { customAttrCollapse: /data-bind/ }, output); + test_minify_sync(assert, input, input); + test_minify_sync(assert, input, { customAttrCollapse: /data-bind/ }, output); input = '
    bar
    '; output = '
    bar
    '; - test_minify(assert, input, { customAttrCollapse: /style/ }, output); + test_minify_sync(assert, input, { customAttrCollapse: /style/ }, output); input = '
    ' + '
    '; output = '
    '; - test_minify(assert, input, { customAttrCollapse: /ng-class/ }, output); + test_minify_sync(assert, input, { customAttrCollapse: /ng-class/ }, output); }); QUnit.test('custom attribute collapse with empty attribute value', function(assert) { var input = '
    '; var output = '
    '; - test_minify(assert, input, { customAttrCollapse: /.+/ }, output); + test_minify_sync(assert, input, { customAttrCollapse: /.+/ }, output); }); QUnit.test('custom attribute collapse with newlines, whitespace, and carriage returns', function(assert) { @@ -3004,7 +3034,7 @@ QUnit.test('custom attribute collapse with newlines, whitespace, and carriage re ' value2:false \n\r' + ' }">'; var output = '
    '; - test_minify(assert, input, { customAttrCollapse: /ng-class/ }, output); + test_minify_sync(assert, input, { customAttrCollapse: /ng-class/ }, output); }); QUnit.test('do not escape attribute value', function(assert) { @@ -3013,23 +3043,23 @@ QUnit.test('do not escape attribute value', function(assert) { input = '
    \n"' + '}\'>'; - test_minify(assert, input, input); - test_minify(assert, input, { preventAttributesEscaping: true }, input); + test_minify_sync(assert, input, input); + test_minify_sync(assert, input, { preventAttributesEscaping: true }, input); input = '
    '; - test_minify(assert, input, { preventAttributesEscaping: true }, input); + test_minify_sync(assert, input, { preventAttributesEscaping: true }, input); output = '
    '; - test_minify(assert, input, output); + test_minify_sync(assert, input, output); }); QUnit.test('quoteCharacter is single quote', function(assert) { - test_minify(assert, '
    foo
    ', { quoteCharacter: '\'' }, '
    foo
    '); - test_minify(assert, '
    foo
    ', { quoteCharacter: '\'' }, '
    foo
    '); + test_minify_sync(assert, '
    foo
    ', { quoteCharacter: '\'' }, '
    foo
    '); + test_minify_sync(assert, '
    foo
    ', { quoteCharacter: '\'' }, '
    foo
    '); }); QUnit.test('quoteCharacter is not single quote or double quote', function(assert) { - test_minify(assert, '
    foo
    ', { quoteCharacter: 'm' }, '
    foo
    '); - test_minify(assert, '
    foo
    ', { quoteCharacter: 'm' }, '
    foo
    '); + test_minify_sync(assert, '
    foo
    ', { quoteCharacter: 'm' }, '
    foo
    '); + test_minify_sync(assert, '
    foo
    ', { quoteCharacter: 'm' }, '
    foo
    '); }); QUnit.test('remove space between attributes', function(assert) { @@ -3043,27 +3073,27 @@ QUnit.test('remove space between attributes', function(assert) { input = ''; output = ''; - test_minify(assert, input, options, output); + test_minify_sync(assert, input, options, output); input = ''; output = ''; - test_minify(assert, input, options, output); + test_minify_sync(assert, input, options, output); input = ''; output = ''; - test_minify(assert, input, options, output); + test_minify_sync(assert, input, options, output); input = ''; output = ''; - test_minify(assert, input, options, output); + test_minify_sync(assert, input, options, output); input = ''; output = ''; - test_minify(assert, input, options, output); + test_minify_sync(assert, input, options, output); input = ''; output = ''; - test_minify(assert, input, options, output); + test_minify_sync(assert, input, options, output); }); QUnit.test('markups from Angular 2', function(assert) { @@ -3089,7 +3119,7 @@ QUnit.test('markups from Angular 2', function(assert) { ' \n' + ' \n' + ''; - test_minify(assert, input, { caseSensitive: true }, output); + test_minify_sync(assert, input, { caseSensitive: true }, output); output = '' + @@ -3100,7 +3130,7 @@ QUnit.test('markups from Angular 2', function(assert) { '' + '' + ''; - test_minify(assert, input, { + test_minify_sync(assert, input, { caseSensitive: true, collapseBooleanAttributes: true, collapseWhitespace: true, @@ -3120,51 +3150,51 @@ QUnit.test('auto-generated tags', function(assert) { var input, output; input = '

    '; - test_minify(assert, input, { includeAutoGeneratedTags: false }, input); + test_minify_sync(assert, input, { includeAutoGeneratedTags: false }, input); input = '

    x'; output = '

    x'; - test_minify(assert, input, { includeAutoGeneratedTags: false }, output); + test_minify_sync(assert, input, { includeAutoGeneratedTags: false }, output); output = '

    x

    '; - test_minify(assert, input, output); - test_minify(assert, input, { includeAutoGeneratedTags: true }, output); + test_minify_sync(assert, input, output); + test_minify_sync(assert, input, { includeAutoGeneratedTags: true }, output); input = '

    x'; output = '

    x'; - test_minify(assert, input, { includeAutoGeneratedTags: false }, output); + test_minify_sync(assert, input, { includeAutoGeneratedTags: false }, output); input = '

    '; output = '
    Well, look at me! I\'m a div!
    '; - test_minify(assert, input, { html5: false, includeAutoGeneratedTags: false }, output); - test_minify(assert, '

    x', { + test_minify_sync(assert, input, { html5: false, includeAutoGeneratedTags: false }, output); + test_minify_sync(assert, '

    x', { maxLineLength: 25, includeAutoGeneratedTags: false }, '

    x'); input = '

    foo'; - test_minify(assert, input, { includeAutoGeneratedTags: false }, input); - test_minify(assert, input, { + test_minify_sync(assert, input, { includeAutoGeneratedTags: false }, input); + test_minify_sync(assert, input, { includeAutoGeneratedTags: false, removeOptionalTags: true }, input); input = '

    '; - test_minify(assert, input, { includeAutoGeneratedTags: false }, input); + test_minify_sync(assert, input, { includeAutoGeneratedTags: false }, input); output = ''; - test_minify(assert, input, { + test_minify_sync(assert, input, { includeAutoGeneratedTags: false, removeOptionalTags: true }, output); input = ''; - test_minify(assert, input, { includeAutoGeneratedTags: false }, input); + test_minify_sync(assert, input, { includeAutoGeneratedTags: false }, input); output = ''; - test_minify(assert, input, { includeAutoGeneratedTags: true }, output); + test_minify_sync(assert, input, { includeAutoGeneratedTags: true }, output); input = ''; - test_minify(assert, input, { includeAutoGeneratedTags: false }, input); + test_minify_sync(assert, input, { includeAutoGeneratedTags: false }, input); output = ''; - test_minify(assert, input, { includeAutoGeneratedTags: true }, output); + test_minify_sync(assert, input, { includeAutoGeneratedTags: true }, output); }); QUnit.test('sort attributes', function(assert) { @@ -3173,26 +3203,26 @@ QUnit.test('sort attributes', function(assert) { input = '' + '' + ''; - test_minify(assert, input, input); - test_minify(assert, input, { sortAttributes: false }, input); + test_minify_sync(assert, input, input); + test_minify_sync(assert, input, { sortAttributes: false }, input); output = '' + '' + ''; - test_minify(assert, input, { sortAttributes: true }, output); + test_minify_sync(assert, input, { sortAttributes: true }, output); input = '' + '' + ''; - test_minify(assert, input, input); - test_minify(assert, input, { sortAttributes: false }, input); + test_minify_sync(assert, input, input); + test_minify_sync(assert, input, { sortAttributes: false }, input); output = '' + '' + ''; - test_minify(assert, input, { sortAttributes: true }, output); + test_minify_sync(assert, input, { sortAttributes: true }, output); output = '' + '' + ''; - test_minify(assert, input, { + test_minify_sync(assert, input, { processScripts: [ 'text/html' ], @@ -3205,11 +3235,11 @@ QUnit.test('sort attributes', function(assert) { output = '' + '' + ''; - test_minify(assert, input, { sortAttributes: true }, output); + test_minify_sync(assert, input, { sortAttributes: true }, output); output = '' + '' + ''; - test_minify(assert, input, { + test_minify_sync(assert, input, { removeStyleLinkTypeAttributes: true, sortAttributes: true }, output); @@ -3219,31 +3249,31 @@ QUnit.test('sort attributes', function(assert) { '
    ' + '' + ''; - test_minify(assert, input, input); - test_minify(assert, input, { sortAttributes: false }, input); + test_minify_sync(assert, input, input); + test_minify_sync(assert, input, { sortAttributes: false }, input); output = '' + '' + '' + '' + ''; - test_minify(assert, input, { sortAttributes: true }, output); + test_minify_sync(assert, input, { sortAttributes: true }, output); input = ' foo_bar>'; - test_minify(assert, input, { + test_minify_sync(assert, input, { ignoreCustomFragments: [/<#[\s\S]*?#>/] }, input); - test_minify(assert, input, { + test_minify_sync(assert, input, { ignoreCustomFragments: [/<#[\s\S]*?#>/], sortAttributes: false }, input); output = ' >'; - test_minify(assert, input, { + test_minify_sync(assert, input, { ignoreCustomFragments: [/<#[\s\S]*?#>/], sortAttributes: true }, output); input = ''; - test_minify(assert, input, { sortAttributes: true }, input); + test_minify_sync(assert, input, { sortAttributes: true }, input); }); QUnit.test('sort style classes', function(assert) { @@ -3254,46 +3284,46 @@ QUnit.test('sort style classes', function(assert) { '' + '' + ''; - test_minify(assert, input, input); - test_minify(assert, input, { sortClassName: false }, input); + test_minify_sync(assert, input, input); + test_minify_sync(assert, input, { sortClassName: false }, input); output = '' + '' + '' + '' + ''; - test_minify(assert, input, { sortClassName: true }, output); + test_minify_sync(assert, input, { sortClassName: true }, output); input = ''; output = ''; - test_minify(assert, input, output); - test_minify(assert, input, { sortClassName: false }, output); + test_minify_sync(assert, input, output); + test_minify_sync(assert, input, { sortClassName: false }, output); output = ''; - test_minify(assert, input, { sortClassName: true }, output); + test_minify_sync(assert, input, { sortClassName: true }, output); input = ''; - test_minify(assert, input, { + test_minify_sync(assert, input, { ignoreCustomFragments: [/<#[\s\S]*?#>/] }, input); - test_minify(assert, input, { + test_minify_sync(assert, input, { ignoreCustomFragments: [/<#[\s\S]*?#>/], sortClassName: false }, input); - test_minify(assert, input, { + test_minify_sync(assert, input, { ignoreCustomFragments: [/<#[\s\S]*?#>/], sortClassName: true }, input); input = ''; - test_minify(assert, input, { sortClassName: false }, input); - test_minify(assert, input, { sortClassName: true }, input); + test_minify_sync(assert, input, { sortClassName: false }, input); + test_minify_sync(assert, input, { sortClassName: true }, input); input = ''; - test_minify(assert, input, { sortClassName: false }, input); + test_minify_sync(assert, input, { sortClassName: false }, input); output = ''; - test_minify(assert, input, { sortClassName: true }, output); + test_minify_sync(assert, input, { sortClassName: true }, output); input = ''; - test_minify(assert, input, { + test_minify_sync(assert, input, { collapseWhitespace: true, ignoreCustomFragments: [/{{.*?}}/], removeAttributeQuotes: true, @@ -3301,7 +3331,7 @@ QUnit.test('sort style classes', function(assert) { }, input); input = ''; - test_minify(assert, input, { + test_minify_sync(assert, input, { collapseWhitespace: true, ignoreCustomFragments: [/{{.*?}}/], removeAttributeQuotes: true, @@ -3309,7 +3339,7 @@ QUnit.test('sort style classes', function(assert) { }, input); input = ''; - test_minify(assert, input, { + test_minify_sync(assert, input, { collapseWhitespace: true, ignoreCustomFragments: [/{{.*?}}/], removeAttributeQuotes: true, @@ -3317,7 +3347,7 @@ QUnit.test('sort style classes', function(assert) { }, input); input = ''; - test_minify(assert, input, { + test_minify_sync(assert, input, { collapseWhitespace: true, ignoreCustomFragments: [/{{.*?}}/], removeAttributeQuotes: true, @@ -3326,7 +3356,7 @@ QUnit.test('sort style classes', function(assert) { input = ''; output = ''; - test_minify(assert, input, { + test_minify_sync(assert, input, { collapseWhitespace: true, ignoreCustomFragments: [/{{.*?}}/], removeAttributeQuotes: true, @@ -3338,41 +3368,41 @@ QUnit.test('decode entity characters', function(assert) { var input, output; input = ''; - test_minify(assert, input, input); - test_minify(assert, input, { decodeEntities: false }, input); - test_minify(assert, input, { decodeEntities: true }, input); + test_minify_sync(assert, input, input); + test_minify_sync(assert, input, { decodeEntities: false }, input); + test_minify_sync(assert, input, { decodeEntities: true }, input); input = ''; - test_minify(assert, input, input); - test_minify(assert, input, { decodeEntities: false }, input); - test_minify(assert, input, { decodeEntities: true }, input); + test_minify_sync(assert, input, input); + test_minify_sync(assert, input, { decodeEntities: false }, input); + test_minify_sync(assert, input, { decodeEntities: true }, input); output = ''; - test_minify(assert, input, { decodeEntities: true, processScripts: ['text/html'] }, output); + test_minify_sync(assert, input, { decodeEntities: true, processScripts: ['text/html'] }, output); input = '
    foo$
    '; - test_minify(assert, input, input); - test_minify(assert, input, { decodeEntities: false }, input); + test_minify_sync(assert, input, input); + test_minify_sync(assert, input, { decodeEntities: false }, input); output = '
    foo$
    '; - test_minify(assert, input, { decodeEntities: true }, output); + test_minify_sync(assert, input, { decodeEntities: true }, output); output = '
    foo$
    '; - test_minify(assert, input, { minifyCSS: true }, output); - test_minify(assert, input, { decodeEntities: false, minifyCSS: true }, output); + test_minify_sync(assert, input, { minifyCSS: true }, output); + test_minify_sync(assert, input, { decodeEntities: false, minifyCSS: true }, output); output = '
    foo$
    '; - test_minify(assert, input, { decodeEntities: true, minifyCSS: true }, output); + test_minify_sync(assert, input, { decodeEntities: true, minifyCSS: true }, output); input = 'baz<moo>©'; - test_minify(assert, input, input); - test_minify(assert, input, { decodeEntities: false }, input); + test_minify_sync(assert, input, input); + test_minify_sync(assert, input, { decodeEntities: false }, input); output = 'baz<moo>\u00a9'; - test_minify(assert, input, { decodeEntities: true }, output); + test_minify_sync(assert, input, { decodeEntities: true }, output); input = '&
    &
    '; - test_minify(assert, input, input); - test_minify(assert, input, { collapseWhitespace: false, decodeEntities: false }, input); - test_minify(assert, input, { collapseWhitespace: true, decodeEntities: false }, input); + test_minify_sync(assert, input, input); + test_minify_sync(assert, input, { collapseWhitespace: false, decodeEntities: false }, input); + test_minify_sync(assert, input, { collapseWhitespace: true, decodeEntities: false }, input); output = '&
    &
    '; - test_minify(assert, input, { collapseWhitespace: false, decodeEntities: true }, output); - test_minify(assert, input, { collapseWhitespace: true, decodeEntities: true }, output); + test_minify_sync(assert, input, { collapseWhitespace: false, decodeEntities: true }, output); + test_minify_sync(assert, input, { collapseWhitespace: true, decodeEntities: true }, output); }); QUnit.test('tests from PHPTAL', function(assert) { @@ -3454,7 +3484,7 @@ QUnit.test('tests from PHPTAL', function(assert) { 'foo ' ]*/ ].forEach(function(tokens) { - test_minify(assert, tokens[1], { + test_minify_sync(assert, tokens[1], { collapseBooleanAttributes: true, collapseWhitespace: true, removeAttributeQuotes: true, @@ -3482,7 +3512,7 @@ QUnit.test('canCollapseWhitespace and canTrimWhitespace hooks', function(assert) var input = '
    foo bar
    '; var output = '
    foo bar
    '; - test_minify(assert, input, { + test_minify_sync(assert, input, { collapseWhitespace: true, canTrimWhitespace: canCollapseAndTrimWhitespace, canCollapseWhitespace: canCollapseAndTrimWhitespace @@ -3493,7 +3523,7 @@ QUnit.test('canCollapseWhitespace and canTrimWhitespace hooks', function(assert) input = '
    foo bar
    '; output = '
    foo bar
    '; - test_minify(assert, input, { + test_minify_sync(assert, input, { collapseWhitespace: true, canTrimWhitespace: canCollapseAndTrimWhitespace, canCollapseWhitespace: canCollapseAndTrimWhitespace @@ -3504,7 +3534,7 @@ QUnit.test('canCollapseWhitespace and canTrimWhitespace hooks', function(assert) input = '
    foo bar
    '; output = '
    foo bar
    '; - test_minify(assert, input, { + test_minify_sync(assert, input, { collapseWhitespace: true, canTrimWhitespace: canCollapseAndTrimWhitespace, canCollapseWhitespace: canCollapseAndTrimWhitespace From bf469226af295e43a8ef13f6e19f1084c1091d19 Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Fri, 20 Apr 2018 13:27:43 +1200 Subject: [PATCH 33/66] Removed placeholders as they are not necessary when everything will be a placeholder. --- src/htmlminifier.js | 140 +++++++++++--------------------------------- 1 file changed, 33 insertions(+), 107 deletions(-) diff --git a/src/htmlminifier.js b/src/htmlminifier.js index 6f53a789..2522e84d 100644 --- a/src/htmlminifier.js +++ b/src/htmlminifier.js @@ -856,16 +856,6 @@ function minify(value, options, partialMarkup, cb) { */ var asyncTasks = []; - /** - * A placeholder that can be inserted into the buffer in place of a string. - * - * Placeholder objects in the buffer will be removed by async tasks before - * completion of the `minify` function. - * - * @constructor - */ - function Placeholder() {} - /** * A group of AsyncTasks to execute in series. * @@ -1024,28 +1014,20 @@ function minify(value, options, partialMarkup, cb) { return options.canTrimWhitespace(tag, attrs, canTrimWhitespace); } - function removeStartTag(indexBound) { - if (typeof indexBound === 'undefined') { - indexBound = buffer.length; - } - - var index = indexBound - 1; + function removeStartTag() { + var index = buffer.length - 1; while (index > 0 && !/^<[^/!]/.test(buffer[index])) { index--; } - return buffer.splice(index, indexBound - index).length; + buffer.length = Math.max(0, index); } - function removeEndTag(indexBound) { - if (typeof indexBound === 'undefined') { - indexBound = buffer.length; - } - - var index = indexBound - 1; + function removeEndTag() { + var index = buffer.length - 1; while (index > 0 && !/^<\//.test(buffer[index])) { index--; } - return buffer.splice(index, indexBound - index).length; + buffer.length = Math.max(0, index); } // look for trailing whitespaces, bypass any inline tags @@ -1065,14 +1047,10 @@ function minify(value, options, partialMarkup, cb) { // look for trailing whitespaces from previously processed text // which may not be trimmed due to a following comment or an empty // element which has now been removed - function squashTrailingWhitespace(nextTag, indexBound) { - if (typeof indexBound === 'undefined') { - indexBound = buffer.length; - } - - var charsIndex = indexBound - 1; - if (indexBound > 1) { - var item = buffer[indexBound - 1]; + function squashTrailingWhitespace(nextTag) { + var charsIndex = buffer.length - 1; + if (buffer.length > 1) { + var item = buffer[buffer.length - 1]; if (/^(?: may be omitted if first thing inside is // may be omitted if first thing inside is if (htmlTag && canRemoveParentTag(optionalStartTag, data.tag)) { - insertionIndex -= removeStartTag(insertionIndex); + removeStartTag(); } optionalStartTag = ''; // end-data.tag-followed-by-start-data.tag omission rules if (htmlTag && canRemovePrecedingTag(optionalEndTag, data.tag)) { - insertionIndex -= removeEndTag(insertionIndex); + removeEndTag(); // cannot be omitted if preceding is omitted // cannot be omitted if preceding , or is omitted optional = !isStartTagMandatory(optionalEndTag, data.tag); @@ -1142,7 +1110,7 @@ function minify(value, options, partialMarkup, cb) { // set whitespace flags for nested tags (eg. within a
    )
                   if (options.collapseWhitespace) {
                     if (!stackNoTrimWhitespace.length) {
    -                  squashTrailingWhitespace(data.tag, insertionIndex);
    +                  squashTrailingWhitespace(data.tag);
                     }
                     if (!data.unary) {
                       if (!_canTrimWhitespace(data.tag, data.attrs) || stackNoTrimWhitespace.length) {
    @@ -1157,7 +1125,7 @@ function minify(value, options, partialMarkup, cb) {
                   var openTag = '<' + data.tag;
                   var hasUnarySlash = data.unarySlash && options.keepClosingSlash;
     
    -              buffer.splice(insertionIndex++, 0, openTag);
    +              buffer.push(openTag);
     
                   if (options.sortAttributes) {
                     options.sortAttributes(data.tag, data.attrs);
    @@ -1190,20 +1158,18 @@ function minify(value, options, partialMarkup, cb) {
                     // All attributes are now normalize.
     
                     if (parts.length > 0) {
    -                  buffer.splice.apply(buffer, [insertionIndex, 0, ' '].concat(parts));
    -                  insertionIndex += 1 + parts.length;
    +                  buffer.push(' ');
    +                  buffer.push.apply(buffer, parts);
                     }
                     // start tag must never be omitted if it has any attributes
                     else if (optional && optionalStartTags(data.tag)) {
                       optionalStartTag = data.tag;
                     }
     
    -                // Remove the last inserted element, modify it and put it back.
    -                var lastElem = buffer.splice(--insertionIndex, 1)[0];
    -                buffer.splice(insertionIndex++, 0, lastElem + (hasUnarySlash ? '/' : '') + '>');
    +                buffer.push(buffer.pop() + (hasUnarySlash ? '/' : '') + '>');
     
                     if (data.autoGenerated && !options.includeAutoGeneratedTags) {
    -                  insertionIndex -= removeStartTag(insertionIndex);
    +                  removeStartTag();
                       optionalStartTag = '';
                     }
     
    @@ -1219,18 +1185,8 @@ function minify(value, options, partialMarkup, cb) {
               );
             },
             end: function(tag, attrs, autoGenerated) {
    -          var placeholder = new Placeholder(); // Some unique reference.
    -          buffer.push(placeholder);
    -
               asyncTasks.push(
                 new AsyncTask(function(data, cb) {
    -              // The index of the placeholder may not be the same as where it
    -              // was originally inserted at; therefore we need to search for it.
    -              var insertionIndex = buffer.indexOf(placeholder);
    -
    -              // Remove the placeholder.
    -              buffer.splice(insertionIndex, 1);
    -
                   var lowerTag = data.tag.toLowerCase();
                   if (lowerTag === 'svg') {
                     options = Object.getPrototypeOf(options);
    @@ -1245,7 +1201,7 @@ function minify(value, options, partialMarkup, cb) {
                       }
                     }
                     else {
    -                  squashTrailingWhitespace('/' + data.tag, insertionIndex);
    +                  squashTrailingWhitespace('/' + data.tag);
                     }
                     if (stackNoCollapseWhitespace.length &&
                       data.tag === stackNoCollapseWhitespace[stackNoCollapseWhitespace.length - 1]) {
    @@ -1262,7 +1218,7 @@ function minify(value, options, partialMarkup, cb) {
                   if (options.removeOptionalTags) {
                     // ,  or  may be omitted if the element is empty
                     if (isElementEmpty && topLevelTags(optionalStartTag)) {
    -                  insertionIndex -= removeStartTag(insertionIndex);
    +                  removeStartTag();
                     }
                     optionalStartTag = '';
                     //  or  may be omitted if not followed by comment
    @@ -1270,14 +1226,14 @@ function minify(value, options, partialMarkup, cb) {
                     // 

    may be omitted if no more content in non- parent // except for or , end tags may be omitted if no more content in parent element if (htmlTags(data.tag) && optionalEndTag && !trailingTags(optionalEndTag) && (optionalEndTag !== 'p' || !pInlineTags(data.tag))) { - insertionIndex -= removeEndTag(insertionIndex); + removeEndTag(); } optionalEndTag = optionalEndTags(data.tag) ? data.tag : ''; } if (options.removeEmptyElements && isElementEmpty && canRemoveElement(data.tag, data.attrs)) { // remove last "element" from buffer - insertionIndex -= removeStartTag(insertionIndex); + removeStartTag(); optionalStartTag = ''; optionalEndTag = ''; } @@ -1286,7 +1242,7 @@ function minify(value, options, partialMarkup, cb) { optionalEndTag = ''; } else { - buffer.splice(insertionIndex, 0, ''); + buffer.push(''); } charsPrevTag = '/' + data.tag; if (!inlineTags(data.tag)) { @@ -1306,18 +1262,8 @@ function minify(value, options, partialMarkup, cb) { ); }, chars: function(text, prevTag, nextTag) { - var placeholder = new Placeholder(); // Some unique reference. - buffer.push(placeholder); - asyncTasks.push( new AsyncTask(function(data, cb) { - // The index of the placeholder may not be the same as where it - // was originally inserted at; therefore we need to search for it. - var insertionIndex = buffer.indexOf(placeholder); - - // Remove the placeholder. - buffer.splice(insertionIndex, 1); - var subtasks = []; data.prevTag = data.prevTag === '' ? 'comment' : data.prevTag; data.nextTag = data.nextTag === '' ? 'comment' : data.nextTag; @@ -1327,13 +1273,13 @@ function minify(value, options, partialMarkup, cb) { if (options.collapseWhitespace) { if (!stackNoTrimWhitespace.length) { if (data.prevTag === 'comment') { - var prevComment = buffer[insertionIndex - 1]; + var prevComment = buffer[buffer.length - 1]; if (prevComment.indexOf(uidIgnore) === -1) { if (!prevComment) { data.prevTag = charsPrevTag; } - if (insertionIndex > 1 && (!prevComment || !options.conservativeCollapse && / $/.test(currentChars))) { - var charsIndex = insertionIndex - 2; + if (buffer.length > 1 && (!prevComment || !options.conservativeCollapse && / $/.test(currentChars))) { + var charsIndex = buffer.length - 2; buffer[charsIndex] = buffer[charsIndex].replace(/\s+$/, function(trailingSpaces) { data.text = trailingSpaces + data.text; return ''; @@ -1344,7 +1290,7 @@ function minify(value, options, partialMarkup, cb) { if (data.prevTag) { if (data.prevTag === '/nobr' || data.prevTag === 'wbr') { if (/^\s/.test(data.text)) { - var tagIndex = insertionIndex - 1; + var tagIndex = buffer.length - 1; while (tagIndex > 0 && buffer[tagIndex].lastIndexOf('<' + data.prevTag) !== 0) { tagIndex--; } @@ -1362,7 +1308,7 @@ function minify(value, options, partialMarkup, cb) { data.text = collapseWhitespace(data.text, options, true, true); } if (!data.text && /\s$/.test(currentChars) && data.prevTag && data.prevTag.charAt(0) === '/') { - trimTrailingWhitespace(insertionIndex - 1, data.nextTag); + trimTrailingWhitespace(buffer.length - 1, data.nextTag); } } if (!stackNoCollapseWhitespace.length && data.nextTag !== 'html' && !(data.prevTag && data.nextTag)) { @@ -1417,13 +1363,13 @@ function minify(value, options, partialMarkup, cb) { // may be omitted if first thing inside is not comment // may be omitted if first thing inside is not space, comment, , , '; + input = styleInput + scriptInput; + + var styleOutput = ''; + var scriptOutput = ''; + + test_minify_async(assert, input, {}, input); + + output = styleOutput + scriptInput; + test_minify_async(assert, input, { minifyCSS: cssAsync }, output); + test_minify_async(assert, input, { minifyCSS: cssAsync, minifyJS: false }, output); + + output = styleInput + scriptOutput; + test_minify_async(assert, input, { minifyJS: jsAsync }, output); + test_minify_async(assert, input, { minifyCSS: false, minifyJS: jsAsync }, output); + + output = styleOutput + scriptOutput; + test_minify_async(assert, input, { minifyCSS: cssAsync, minifyJS: jsAsync }, output); + test_minify_async(assert, input, { minifyCSS: cssAsync, minifyJS: jsSync }, output); + test_minify_async(assert, input, { minifyCSS: cssSync, minifyJS: jsAsync }, output); +}); + +QUnit.test('minify error with callback', function(assert) { + var input = '<$unicorn>'; + + test_minify_async_error(assert, input, {}, 'Invalid tag name'); +}); + +QUnit.test('error in callback', function(assert) { + var input = ''; + var error = new Error(); + + function css() { + throw error; + } + + test_minify_async_error(assert, input, { minifyCSS: css }, error); +}); From 58ca98ec47a71e84d02c1a12fc1852771f920af6 Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Fri, 20 Apr 2018 18:35:20 +1200 Subject: [PATCH 43/66] Fixed up tests. --- tests/minifier.js | 137 ++++++++++++++++++++++------------------------ 1 file changed, 66 insertions(+), 71 deletions(-) diff --git a/tests/minifier.js b/tests/minifier.js index 54b981ab..c5b13087 100644 --- a/tests/minifier.js +++ b/tests/minifier.js @@ -6,6 +6,33 @@ if (typeof minify === 'undefined') { self.minify = require('html-minifier').minify; } +QUnit.test('`minifiy` exists', function(assert) { + assert.ok(minify); +}); + +/** + * Converts the options in the given object to use sync callbacks where possible. + * + * @param {Object} options + */ +function convertOptionsSyncCallbacks(options) { + if (options) { + if (typeof options.minifyJS === 'function') { + var minifyJS = options.minifyJS; + options.minifyJS = function(text, inline, callback) { + callback(minifyJS(text, inline)); + }; + } + if (typeof options.minifyCSS === 'function') { + var minifyCSS = options.minifyCSS; + options.minifyCSS = function(text, type, callback) { + callback(minifyCSS(text, type)); + }; + } + } + return options; +} + /** * Test the minify function synchronously, both with a callback and without. * @@ -33,40 +60,15 @@ function test_minify_sync(assert, input, options, output, description) { // Standard test. assert.equal(minify(input, options), output, descriptionPrefix + description); - // Callback setup. - if (options) { - // Convert `minifyJS` to use a callback. - if (typeof options.minifyJS === 'function') { - var minifyJS = options.minifyJS; - options.minifyJS = function(text, inline, callback) { - callback(minifyJS(text, inline)); - }; - } - // Convert `minifyCSS` to use a callback. - if (typeof options.minifyCSS === 'function') { - var minifyCSS = options.minifyCSS; - options.minifyCSS = function(text, type, callback) { - callback(minifyCSS(text, type)); - }; - } - } - descriptionPrefix = 'Synchronous Callback Test: '; var done = assert.async(); var callbackTestFinished = false; // Callback test. - assert.notOk(minify(input, options, function(error, result) { + assert.notOk(minify(input, convertOptionsSyncCallbacks(options), function(error, result) { if (!callbackTestFinished) { - // Error should be null - if (error !== null) { - if (error instanceof Error) { - assert.equal(error, null, descriptionPrefix + 'An error occurred - stack trace:\n' + error.stack); - } - else { - assert.ok(false, descriptionPrefix + '"' + error + '" was returned as an error.'); - } - } + assert.notOk(error, descriptionPrefix + 'An error occurred - stack trace:\n' + error.stack); + assert.equal(result, output, descriptionPrefix + description); callbackTestFinished = true; done(); @@ -86,11 +88,17 @@ function test_minify_sync(assert, input, options, output, description) { * * @param {QUnit.assert} assert * @param {string} input - * @param {Object} options + * @param {Object} [options] * @param {Error|Class|RegExp|Function} [errorMatcher] * @param {string} [description] */ function test_minify_sync_error(assert, input, options, errorMatcher, description) { + // Remove optional options parameter if it is not given. + if (typeof options === 'string') { + description = errorMatcher; + errorMatcher = options; + options = null; + } // Remove optional errorMatcher parameter if it is not given. if (typeof errorMatcher === 'string') { description = errorMatcher; @@ -105,24 +113,24 @@ function test_minify_sync_error(assert, input, options, errorMatcher, descriptio var descriptionPrefix = 'Synchronous Standard Test: '; // Standard test. - assert.throws(function() { minify(input, options); }, errorMatcher, descriptionPrefix + description); + assert.throws( + function() { + minify(input, options); + }, + errorMatcher, + descriptionPrefix + description + ); descriptionPrefix = 'Synchronous Callback Test: '; var done = assert.async(); var callbackTestFinished = false; // Callback test. - assert.notOk(minify(input, options, function(error, result) { + assert.notOk(minify(input, convertOptionsSyncCallbacks(options), function(error, result) { if (!callbackTestFinished) { - if (error === null) { - assert.ok(false, descriptionPrefix + 'An error should have occurred.'); - } - else if (error instanceof Error) { - assert.throws(function() { throw error; }, errorMatcher, descriptionPrefix + description); - } - else { - assert.ok(false, descriptionPrefix + '"' + error + '" was returned as an error.'); - } + assert.ok(error, descriptionPrefix + 'An error should have occurred.'); + assert.ok(error instanceof Error, descriptionPrefix + '"' + error + '" was returned as an error.'); + assert.throws(function() { throw error; }, errorMatcher, descriptionPrefix + description); assert.notOk(result); callbackTestFinished = true; done(); @@ -159,7 +167,7 @@ function test_minify_async(assert, input, options, output, description) { description = input; } - assert.timeout(100); + assert.timeout(10); var descriptionPrefix = 'Asynchronous Test: '; var done = assert.async(); @@ -199,7 +207,7 @@ function test_minify_async_error(assert, input, options, errorMatcher, descripti description = input; } - assert.timeout(100); + assert.timeout(10); var descriptionPrefix = 'Asynchronous Test: '; var done = assert.async(); @@ -218,10 +226,6 @@ function test_minify_async_error(assert, input, options, errorMatcher, descripti })); } -QUnit.test('`minifiy` exists', function(assert) { - assert.ok(minify); -}); - QUnit.test('parsing non-trivial markup', function(assert) { var input, output; @@ -273,7 +277,7 @@ QUnit.test('parsing non-trivial markup', function(assert) { test_minify_sync(assert, input, input); input = '<$unicorn>'; - test_minify_sync_error(assert, input, {}, 'Invalid tag name'); + test_minify_sync_error(assert, input, 'Invalid tag name'); input = ''; test_minify_sync(assert, input, input); @@ -303,12 +307,7 @@ QUnit.test('parsing non-trivial markup', function(assert) { // https://github.com/kangax/html-minifier/issues/507 input = ''; test_minify_sync(assert, input, input); - test_minify_sync_error( - assert, - '', - {}, - 'invalid attribute name' - ); + test_minify_sync_error(assert, '', 'invalid attribute name'); // https://github.com/kangax/html-minifier/issues/512 input = ''; test_minify_sync(assert, input, input); - test_minify_sync_error( - assert, - '' + - ' placeholder="YYYY-MM-DD"' + - ' date-range-picker' + - ' data-ng-model="vm.value"' + - ' data-ng-model-options="{ debounce: 1000 }"' + - ' data-ng-pattern="vm.options.format"' + - ' data-options="vm.datepickerOptions">', - {}, - 'HTML comment inside tag' - ); + input = '' + + ' placeholder="YYYY-MM-DD"' + + ' date-range-picker' + + ' data-ng-model="vm.value"' + + ' data-ng-model-options="{ debounce: 1000 }"' + + ' data-ng-pattern="vm.options.format"' + + ' data-options="vm.datepickerOptions">'; + test_minify_sync_error(assert, input, 'HTML comment inside tag'); input = '
    '; output = '
    '; @@ -3071,14 +3066,14 @@ QUnit.test('custom attribute collapse', function(assert) { input = '
    foo
    '; - output = '
    foo
    '; + output = '
    foo
    '; test_minify_sync(assert, input, input); test_minify_sync(assert, input, { customAttrCollapse: /data-bind/ }, output); @@ -3636,13 +3631,13 @@ QUnit.test('Async execution', function(assert) { function cssAsync(text, type, cb) { setTimeout(function() { cb(cssSync(text, type)); - }, 0); + }, 1); } function jsAsync(text, inline, cb) { setTimeout(function() { cb(jsSync(text, inline)); - }, 0); + }, 1); } var styleInput = ''; @@ -3671,7 +3666,7 @@ QUnit.test('Async execution', function(assert) { QUnit.test('minify error with callback', function(assert) { var input = '<$unicorn>'; - test_minify_async_error(assert, input, {}, 'Invalid tag name'); + test_minify_async_error(assert, input, 'Invalid tag name'); }); QUnit.test('error in callback', function(assert) { From 8e4351d7eb450b6fa2f8e8fcdc5d25b78e4e4a22 Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Fri, 20 Apr 2018 18:36:03 +1200 Subject: [PATCH 44/66] Added 'callback called multiple times' tests. --- tests/minifier.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tests/minifier.js b/tests/minifier.js index c5b13087..a3982aa3 100644 --- a/tests/minifier.js +++ b/tests/minifier.js @@ -3679,3 +3679,30 @@ QUnit.test('error in callback', function(assert) { test_minify_async_error(assert, input, { minifyCSS: css }, error); }); + +QUnit.test('callback called multiple times', function(assert) { + var input, done; + + function bad(cb) { + try { + cb(''); + cb(''); + assert.ok(false, 'An error should be thrown.'); + } + catch (error) { + assert.equal(error.message, 'Async completion has already occurred.'); + } + finally { + done(); + } + } + + done = assert.async(); + test_minify_async_error(assert, input, { minifyCSS: bad }); + + done = assert.async(); + test_minify_async_error(assert, input, { minifyJS: bad }); + + done = assert.async(); + test_minify_async_error(assert, input, { minifyCSS: bad, minifyJS: bad }); +}); From 5961a660e584fb7038cfe2dcfe132099a6eeb223 Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Mon, 23 Apr 2018 16:37:28 +1200 Subject: [PATCH 45/66] Fixed bad test 'callback called multiple times' and got it passing. --- src/htmlminifier.js | 10 ++++++++-- tests/minifier.js | 12 +++++++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/htmlminifier.js b/src/htmlminifier.js index 56c5a321..2a5fcee6 100644 --- a/src/htmlminifier.js +++ b/src/htmlminifier.js @@ -1320,7 +1320,10 @@ function minify(value, options, partialMarkup, cb) { var callbackCalled = false; function minifyJS_cb(result) { - if (!callbackCalled) { + if (callbackCalled) { + throw new Error('Async completion has already occurred.'); + } + else { callbackCalled = true; text = result; return cb(); @@ -1337,7 +1340,10 @@ function minify(value, options, partialMarkup, cb) { var callbackCalled = false; function minifyCSS_cb(result) { - if (!callbackCalled) { + if (callbackCalled) { + throw new Error('Async completion has already occurred.'); + } + else { callbackCalled = true; text = result; return cb(); diff --git a/tests/minifier.js b/tests/minifier.js index a3982aa3..2288da00 100644 --- a/tests/minifier.js +++ b/tests/minifier.js @@ -3683,7 +3683,7 @@ QUnit.test('error in callback', function(assert) { QUnit.test('callback called multiple times', function(assert) { var input, done; - function bad(cb) { + function bad(_, __, cb) { try { cb(''); cb(''); @@ -3697,12 +3697,14 @@ QUnit.test('callback called multiple times', function(assert) { } } - done = assert.async(); - test_minify_async_error(assert, input, { minifyCSS: bad }); + input = ''; done = assert.async(); - test_minify_async_error(assert, input, { minifyJS: bad }); + minify(input, { minifyCSS: bad }); done = assert.async(); - test_minify_async_error(assert, input, { minifyCSS: bad, minifyJS: bad }); + minify(input, { minifyJS: bad }); + + done = assert.async(2); + minify(input, { minifyCSS: bad, minifyJS: bad }); }); From adad66503ecd2f97327a9f80bd9d5d470ad6dd96 Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Mon, 23 Apr 2018 17:20:23 +1200 Subject: [PATCH 46/66] Fixed bug in tests causing them to throw errors. --- tests/minifier.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/minifier.js b/tests/minifier.js index 2288da00..32765534 100644 --- a/tests/minifier.js +++ b/tests/minifier.js @@ -67,9 +67,14 @@ function test_minify_sync(assert, input, options, output, description) { // Callback test. assert.notOk(minify(input, convertOptionsSyncCallbacks(options), function(error, result) { if (!callbackTestFinished) { - assert.notOk(error, descriptionPrefix + 'An error occurred - stack trace:\n' + error.stack); + var stackTrace = ''; + if (error && error instanceof Error) { + stackTrace = error.stack; + } + assert.notOk(error, descriptionPrefix + 'An error occurred - stack trace:\n' + stackTrace); assert.equal(result, output, descriptionPrefix + description); + callbackTestFinished = true; done(); } From f57abf3af7e4c783128cdf3e26697776814929c4 Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Mon, 23 Apr 2018 17:26:03 +1200 Subject: [PATCH 47/66] Fixed up tests. --- tests/minifier.js | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/tests/minifier.js b/tests/minifier.js index 32765534..b2bf4f85 100644 --- a/tests/minifier.js +++ b/tests/minifier.js @@ -72,7 +72,7 @@ function test_minify_sync(assert, input, options, output, description) { stackTrace = error.stack; } - assert.notOk(error, descriptionPrefix + 'An error occurred - stack trace:\n' + stackTrace); + assert.equal(error, null, descriptionPrefix + 'An error occurred - stack trace:\n' + stackTrace); assert.equal(result, output, descriptionPrefix + description); callbackTestFinished = true; @@ -177,16 +177,14 @@ function test_minify_async(assert, input, options, output, description) { var done = assert.async(); assert.notOk(minify(input, options, function(error, result) { - // Error should be null - if (error !== null) { - if (error instanceof Error) { - assert.equal(error, null, descriptionPrefix + 'An error occurred - stack trace:\n' + error.stack); - } - else { - assert.ok(false, descriptionPrefix + '"' + error + '" was returned as an error.'); - } + var stackTrace = ''; + if (error && error instanceof Error) { + stackTrace = error.stack; } + + assert.equal(error, null, descriptionPrefix + 'An error occurred - stack trace:\n' + stackTrace); assert.equal(result, output, descriptionPrefix + description); + done(); })); } @@ -217,15 +215,9 @@ function test_minify_async_error(assert, input, options, errorMatcher, descripti var done = assert.async(); assert.notOk(minify(input, options, function(error, result) { - if (error === null) { - assert.ok(false, descriptionPrefix + 'An error should have occurred.'); - } - else if (error instanceof Error) { - assert.throws(function() { throw error; }, errorMatcher, descriptionPrefix + description); - } - else { - assert.ok(false, descriptionPrefix + '"' + error + '" was returned as an error.'); - } + assert.ok(error, descriptionPrefix + 'An error should have occurred.'); + assert.ok(error instanceof Error, descriptionPrefix + '"' + error + '" was returned as an error.'); + assert.throws(function() { throw error; }, errorMatcher, descriptionPrefix + description); assert.notOk(result); done(); })); From 587da3848ceaf002b63e968dc55620d9eb310eae Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Mon, 23 Apr 2018 17:27:44 +1200 Subject: [PATCH 48/66] Fixed up jsdoc. --- src/htmlminifier.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/htmlminifier.js b/src/htmlminifier.js index 2a5fcee6..5afa1230 100644 --- a/src/htmlminifier.js +++ b/src/htmlminifier.js @@ -877,7 +877,7 @@ function minify(value, options, partialMarkup, cb) { * * @constructor * - * @param {Function>} task + * @param {Function>} task */ function Task(task) { this.task = task; From 9addaf62bab54b8960e0bdad74676f940f95cfbf Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Mon, 23 Apr 2018 17:34:17 +1200 Subject: [PATCH 49/66] Increased timout. --- tests/minifier.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/minifier.js b/tests/minifier.js index b2bf4f85..18113010 100644 --- a/tests/minifier.js +++ b/tests/minifier.js @@ -172,7 +172,7 @@ function test_minify_async(assert, input, options, output, description) { description = input; } - assert.timeout(10); + assert.timeout(100); var descriptionPrefix = 'Asynchronous Test: '; var done = assert.async(); @@ -210,7 +210,7 @@ function test_minify_async_error(assert, input, options, errorMatcher, descripti description = input; } - assert.timeout(10); + assert.timeout(100); var descriptionPrefix = 'Asynchronous Test: '; var done = assert.async(); From 99d8546500dcefe275efa762ba45afb0d0c22420 Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Mon, 23 Apr 2018 22:15:48 +1200 Subject: [PATCH 50/66] Made the test_minify_async_error consistent with test_minify_sync_error --- tests/minifier.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/minifier.js b/tests/minifier.js index 18113010..6f7634be 100644 --- a/tests/minifier.js +++ b/tests/minifier.js @@ -104,6 +104,7 @@ function test_minify_sync_error(assert, input, options, errorMatcher, descriptio errorMatcher = options; options = null; } + // Remove optional errorMatcher parameter if it is not given. if (typeof errorMatcher === 'string') { description = errorMatcher; @@ -194,11 +195,18 @@ function test_minify_async(assert, input, options, output, description) { * * @param {QUnit.assert} assert * @param {string} input - * @param {Object} options + * @param {Object} [options] * @param {Error|Class|RegExp|Function} [errorMatcher] * @param {string} [description] */ function test_minify_async_error(assert, input, options, errorMatcher, description) { + // Remove optional options parameter if it is not given. + if (typeof options === 'string') { + description = errorMatcher; + errorMatcher = options; + options = null; + } + // Remove optional errorMatcher parameter if it is not given. if (typeof errorMatcher === 'string') { description = errorMatcher; From 3552c4e3e2ed3e95b6107406c7ac1bbd34a63bc3 Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Mon, 23 Apr 2018 23:10:33 +1200 Subject: [PATCH 51/66] Fixed up jsdoc types. --- src/htmlminifier.js | 13 +++++++++---- tests/minifier.js | 12 ++++++------ 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/htmlminifier.js b/src/htmlminifier.js index 5afa1230..42ab0ae0 100644 --- a/src/htmlminifier.js +++ b/src/htmlminifier.js @@ -1,5 +1,10 @@ 'use strict'; +/** + * A callback that tasks an error and a result. + * @typedef {function([?Error], [string]):void} Callback + */ + var CleanCSS = require('clean-css'); var decode = require('he').decode; var HTMLParser = require('./htmlparser').HTMLParser; @@ -842,7 +847,7 @@ function createSortFns(value, options, uidIgnore, uidAttr, cb) { * @param {string} value * @param {Object} options * @param {boolean} partialMarkup - * @param {Function} cb + * @param {Callback} cb */ function minify(value, options, partialMarkup, cb) { if (options.collapseWhitespace) { @@ -877,7 +882,7 @@ function minify(value, options, partialMarkup, cb) { * * @constructor * - * @param {Function>} task + * @param {function(Callback)} task */ function Task(task) { this.task = task; @@ -886,7 +891,7 @@ function minify(value, options, partialMarkup, cb) { /** * Execute this task. * - * @param {Function} cb + * @param {Callback} cb */ Task.prototype.exec = function(cb) { this.task(cb); @@ -906,7 +911,7 @@ function minify(value, options, partialMarkup, cb) { /** * Run all tasks in this group in series. * - * @param {Function} cb + * @param {Callback} cb */ TaskGroup.prototype.exec = function(cb) { /** diff --git a/tests/minifier.js b/tests/minifier.js index 6f7634be..bbe26ba6 100644 --- a/tests/minifier.js +++ b/tests/minifier.js @@ -36,7 +36,7 @@ function convertOptionsSyncCallbacks(options) { /** * Test the minify function synchronously, both with a callback and without. * - * @param {QUnit.assert} assert + * @param {Assert} assert * @param {string} input * @param {Object} [options] * @param {string} output @@ -91,10 +91,10 @@ function test_minify_sync(assert, input, options, output, description) { /** * Test the minify function synchronously for an expected error, both with a callback and without. * - * @param {QUnit.assert} assert + * @param {Assert} assert * @param {string} input * @param {Object} [options] - * @param {Error|Class|RegExp|Function} [errorMatcher] + * @param {Error|function(new:Error)|RegExp|function(boolean)} [errorMatcher] * @param {string} [description] */ function test_minify_sync_error(assert, input, options, errorMatcher, description) { @@ -154,7 +154,7 @@ function test_minify_sync_error(assert, input, options, errorMatcher, descriptio /** * Test the minify function asynchronously. * - * @param {QUnit.assert} assert + * @param {Assert} assert * @param {string} input * @param {Object} [options] * @param {string} output @@ -193,10 +193,10 @@ function test_minify_async(assert, input, options, output, description) { /** * Test the minify function asynchronously for an expected error. * - * @param {QUnit.assert} assert + * @param {Assert} assert * @param {string} input * @param {Object} [options] - * @param {Error|Class|RegExp|Function} [errorMatcher] + * @param {Error|function(new:Error)|RegExp|function(boolean)} [errorMatcher] * @param {string} [description] */ function test_minify_async_error(assert, input, options, errorMatcher, description) { From 31edf01dbb1bc19a711861eafa253923d3e39a9e Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Tue, 24 Apr 2018 16:53:02 +1200 Subject: [PATCH 52/66] Merged async and sync test functions togetehr. --- tests/minifier.js | 2353 ++++++++++++++++++++++----------------------- 1 file changed, 1174 insertions(+), 1179 deletions(-) diff --git a/tests/minifier.js b/tests/minifier.js index bbe26ba6..dcdad2d2 100644 --- a/tests/minifier.js +++ b/tests/minifier.js @@ -1,318 +1,317 @@ /* global minify */ 'use strict'; -QUnit.config.autostart = false; -if (typeof minify === 'undefined') { - self.minify = require('html-minifier').minify; -} - -QUnit.test('`minifiy` exists', function(assert) { - assert.ok(minify); -}); - /** - * Converts the options in the given object to use sync callbacks where possible. + * Converts the options in the given object to use callbacks where possible. * - * @param {Object} options + * @param {?Object} options + * @param {boolean} [async=false] + * @returns {Object} */ -function convertOptionsSyncCallbacks(options) { +function convertOptionsCallbacks(options, async) { + var convertedOptions = {}; + if (options) { + for (var i in options) { + convertedOptions[i] = options[i]; + } + if (typeof options.minifyJS === 'function') { - var minifyJS = options.minifyJS; - options.minifyJS = function(text, inline, callback) { - callback(minifyJS(text, inline)); + convertedOptions.minifyJS = function(text, inline, cb) { + function runMinifyJS() { + var result = options.minifyJS(text, inline, cb); + if (typeof result !== 'undefined') { + cb(result); + } + } + + if (async) { + setTimeout(function() { + runMinifyJS(); + }, 1); + } + else { + runMinifyJS(); + } }; } if (typeof options.minifyCSS === 'function') { - var minifyCSS = options.minifyCSS; - options.minifyCSS = function(text, type, callback) { - callback(minifyCSS(text, type)); + convertedOptions.minifyCSS = function(text, type, cb) { + function runMinifyCSS() { + var result = options.minifyCSS(text, type, cb); + if (typeof result !== 'undefined') { + cb(result); + } + } + + if (async) { + setTimeout(function() { + runMinifyCSS(); + }, 1); + } + else { + runMinifyCSS(); + } }; } } - return options; + + return convertedOptions; } /** - * Test the minify function synchronously, both with a callback and without. + * Test the minify function. * * @param {Assert} assert * @param {string} input - * @param {Object} [options] * @param {string} output - * @param {string} [description] + * @param {Object} [inputOptions] + * @param {string} [description=input] + * @param {boolean} [asyncOnly=false] */ -function test_minify_sync(assert, input, options, output, description) { - // Remove optional options parameter if it is not given. - if (typeof options === 'string') { - description = output; - output = options; - options = null; - } - - // Set default description as input. - if (typeof description === 'undefined') { +function test_minify(assert, input, output, inputOptions, description, asyncOnly) { + // Set default description. + if (description === null || typeof description === 'undefined') { description = input; } - var descriptionPrefix = 'Synchronous Standard Test: '; + // Set default asyncOnly. + if (asyncOnly === null || typeof asyncOnly === 'undefined') { + asyncOnly = false; + } // Standard test. - assert.equal(minify(input, options), output, descriptionPrefix + description); + if (!asyncOnly) { + var descriptionPrefix = 'Standard Test: '; + assert.equal(minify(input, inputOptions), output, descriptionPrefix + description); + } - descriptionPrefix = 'Synchronous Callback Test: '; - var done = assert.async(); - var callbackTestFinished = false; + // Callback tests. + var callbackTests = []; + + if (!asyncOnly) { + // Sync callback test. + callbackTests.push({ + options: convertOptionsCallbacks(inputOptions, false), + async: false, + done: assert.async(), + descriptionPrefix: 'Synchronous Callback Test: ' + }); + } - // Callback test. - assert.notOk(minify(input, convertOptionsSyncCallbacks(options), function(error, result) { - if (!callbackTestFinished) { - var stackTrace = ''; - if (error && error instanceof Error) { - stackTrace = error.stack; - } + // Async callback test. + callbackTests.push({ + options: asyncOnly ? inputOptions : convertOptionsCallbacks(inputOptions, true), + async: true, + done: assert.async(), + descriptionPrefix: 'Asynchronous Callback Test: ' + }); - assert.equal(error, null, descriptionPrefix + 'An error occurred - stack trace:\n' + stackTrace); - assert.equal(result, output, descriptionPrefix + description); + // Run callback tests. + assert.timeout(100); + callbackTests.forEach(function(test) { + var callbackTestFinished = false; + assert.notOk(minify(input, test.options, function(error, result) { + if (!callbackTestFinished) { + var stackTrace = ''; + if (error && error instanceof Error) { + stackTrace = error.stack; + } + + assert.equal(error, null, test.descriptionPrefix + 'An error occurred - stack trace:\n' + stackTrace); + assert.equal(result, output, test.descriptionPrefix + description); + + callbackTestFinished = true; + test.done(); + } + })); + // If callback test didn't finish synchronously. + if (!callbackTestFinished && !test.async) { + assert.ok(false, test.descriptionPrefix + 'Didn\'t finish synchronously.'); callbackTestFinished = true; - done(); + test.done(); } - })); - - // If callback test didn't finish synchronously. - if (!callbackTestFinished) { - assert.ok(false, descriptionPrefix + 'Didn\'t finish synchronously.'); - callbackTestFinished = true; - done(); - } + }); } /** - * Test the minify function synchronously for an expected error, both with a callback and without. + * Test the minify function for an expected error. * * @param {Assert} assert * @param {string} input * @param {Object} [options] * @param {Error|function(new:Error)|RegExp|function(boolean)} [errorMatcher] - * @param {string} [description] + * @param {string} [description=input] + * @param {boolean} [asyncOnly=false] */ -function test_minify_sync_error(assert, input, options, errorMatcher, description) { - // Remove optional options parameter if it is not given. - if (typeof options === 'string') { - description = errorMatcher; - errorMatcher = options; - options = null; - } - - // Remove optional errorMatcher parameter if it is not given. - if (typeof errorMatcher === 'string') { - description = errorMatcher; - errorMatcher = null; - } - - // Set default description as input. - if (typeof description === 'undefined') { +function test_minify_error(assert, input, inputOptions, errorMatcher, description, asyncOnly) { + // Set default description. + if (description === null || typeof description === 'undefined') { description = input; } - var descriptionPrefix = 'Synchronous Standard Test: '; + // Set default asyncOnly. + if (asyncOnly === null || typeof asyncOnly === 'undefined') { + asyncOnly = false; + } // Standard test. + var descriptionPrefix = 'Standard Test: '; assert.throws( function() { - minify(input, options); + minify(input, inputOptions); }, errorMatcher, descriptionPrefix + description ); - descriptionPrefix = 'Synchronous Callback Test: '; - var done = assert.async(); - var callbackTestFinished = false; - - // Callback test. - assert.notOk(minify(input, convertOptionsSyncCallbacks(options), function(error, result) { - if (!callbackTestFinished) { - assert.ok(error, descriptionPrefix + 'An error should have occurred.'); - assert.ok(error instanceof Error, descriptionPrefix + '"' + error + '" was returned as an error.'); - assert.throws(function() { throw error; }, errorMatcher, descriptionPrefix + description); - assert.notOk(result); - callbackTestFinished = true; - done(); - } - })); - - // If callback test didn't finish synchronously. - if (!callbackTestFinished) { - assert.ok(false, descriptionPrefix + 'Didn\'t finish synchronously.'); - callbackTestFinished = true; - done(); - } -} - -/** - * Test the minify function asynchronously. - * - * @param {Assert} assert - * @param {string} input - * @param {Object} [options] - * @param {string} output - * @param {string} [description] - */ -function test_minify_async(assert, input, options, output, description) { - // Remove optional options parameter if it is not given. - if (typeof options === 'string') { - description = output; - output = options; - options = null; + // Callback tests. + var callbackTests = []; + + if (!asyncOnly) { + // Sync callback test. + callbackTests.push({ + options: convertOptionsCallbacks(inputOptions, false), + async: false, + done: assert.async(), + descriptionPrefix: 'Synchronous Callback Test: ' + }); } - // Set default description as input. - if (typeof description === 'undefined') { - description = input; - } - - assert.timeout(100); - var descriptionPrefix = 'Asynchronous Test: '; - var done = assert.async(); + // Async callback test. + callbackTests.push({ + options: asyncOnly ? inputOptions : convertOptionsCallbacks(inputOptions, true), + async: true, + done: assert.async(), + descriptionPrefix: 'Asynchronous Callback Test: ' + }); - assert.notOk(minify(input, options, function(error, result) { - var stackTrace = ''; - if (error && error instanceof Error) { - stackTrace = error.stack; + // Run callback tests. + callbackTests.forEach(function(test) { + var callbackTestFinished = false; + try { + assert.timeout(100); + assert.notOk(minify(input, test.options, function(error, result) { + if (!callbackTestFinished) { + assert.ok(error, descriptionPrefix + 'An error should have occurred.'); + assert.ok(error instanceof Error, descriptionPrefix + '"' + error + '" was returned as an error.'); + assert.throws(function() { throw error; }, errorMatcher, descriptionPrefix + description); + assert.notOk(result); + + callbackTestFinished = true; + test.done(); + } + })); + + // If callback test didn't finish synchronously. + if (!callbackTestFinished && !test.async) { + assert.ok(false, test.descriptionPrefix + 'Didn\'t finish synchronously.'); + callbackTestFinished = true; + test.done(); + } } - - assert.equal(error, null, descriptionPrefix + 'An error occurred - stack trace:\n' + stackTrace); - assert.equal(result, output, descriptionPrefix + description); - - done(); - })); + catch (error) { + callbackTestFinished = true; + if (error && error instanceof Error) { + assert.ok(false, test.descriptionPrefix + 'threw an error - stack trace:\n' + error.stack); + } + else { + assert.ok(false, test.descriptionPrefix + 'threw an error - "' + error + '"'); + } + } + }); } -/** - * Test the minify function asynchronously for an expected error. - * - * @param {Assert} assert - * @param {string} input - * @param {Object} [options] - * @param {Error|function(new:Error)|RegExp|function(boolean)} [errorMatcher] - * @param {string} [description] - */ -function test_minify_async_error(assert, input, options, errorMatcher, description) { - // Remove optional options parameter if it is not given. - if (typeof options === 'string') { - description = errorMatcher; - errorMatcher = options; - options = null; - } - - // Remove optional errorMatcher parameter if it is not given. - if (typeof errorMatcher === 'string') { - description = errorMatcher; - errorMatcher = null; - } - - // Set default description as input. - if (typeof description === 'undefined') { - description = input; - } - - assert.timeout(100); - var descriptionPrefix = 'Asynchronous Test: '; - var done = assert.async(); - - assert.notOk(minify(input, options, function(error, result) { - assert.ok(error, descriptionPrefix + 'An error should have occurred.'); - assert.ok(error instanceof Error, descriptionPrefix + '"' + error + '" was returned as an error.'); - assert.throws(function() { throw error; }, errorMatcher, descriptionPrefix + description); - assert.notOk(result); - done(); - })); +QUnit.config.autostart = false; +if (typeof minify === 'undefined') { + self.minify = require('html-minifier').minify; } +QUnit.test('`minifiy` exists', function(assert) { + assert.ok(minify); +}); + QUnit.test('parsing non-trivial markup', function(assert) { var input, output; - test_minify_sync(assert, '', ''); - test_minify_sync(assert, '

    ', '

    '); - test_minify_sync(assert, '
    ', '
    '); - test_minify_sync(assert, '
    x
    ', '
    x
    '); - test_minify_sync(assert, '

    x

    ', '

    x

    '); - test_minify_sync(assert, '

    x

    ', '

    x

    '); - test_minify_sync(assert, '

    x

    ', '

    x

    '); - test_minify_sync(assert, '

    xxx

    ', '

    xxx

    '); - test_minify_sync(assert, '

    xxx

    ', '

    xxx

    '); - test_minify_sync(assert, '

    xxx

    ', '

    xxx

    '); + test_minify(assert, '', ''); + test_minify(assert, '

    ', '

    '); + test_minify(assert, '
    ', '
    '); + test_minify(assert, '
    x
    ', '
    x
    '); + test_minify(assert, '

    x

    ', '

    x

    '); + test_minify(assert, '

    x

    ', '

    x

    '); + test_minify(assert, '

    x

    ', '

    x

    '); + test_minify(assert, '

    xxx

    ', '

    xxx

    '); + test_minify(assert, '

    xxx

    ', '

    xxx

    '); + test_minify(assert, '

    xxx

    ', '

    xxx

    '); input = '
    ' + 'i\'m 10 levels deep' + '
    '; - test_minify_sync(assert, input, input); + test_minify(assert, input, input); - test_minify_sync(assert, '', ''); - test_minify_sync(assert, '', ''); - test_minify_sync(assert, '', ''); + test_minify(assert, '', ''); + test_minify(assert, '', ''); + test_minify(assert, '', ''); - test_minify_sync(assert, 'foo', 'foo'); - test_minify_sync(assert, '

    x', '

    x

    '); - test_minify_sync(assert, '

    x

    ', '

    x

    ', 'trailing quote should be ignored'); - test_minify_sync(assert, '

    Click me

    ', '

    Click me

    '); - test_minify_sync(assert, '', ''); - test_minify_sync(assert, '
    [fallback image]
    ', - '
    [fallback image]
    ' - ); + test_minify(assert, 'foo', 'foo'); + test_minify(assert, '

    x', '

    x

    '); + test_minify(assert, '

    x

    ', '

    x

    ', 'trailing quote should be ignored'); + test_minify(assert, '

    Click me

    ', '

    Click me

    '); + test_minify(assert, '', ''); + test_minify(assert, '
    [fallback image]
    ', '
    [fallback image]
    '); - test_minify_sync(assert, '', ''); - test_minify_sync(assert, '', ''); - test_minify_sync(assert, '
    ', - '
    ' - ); + test_minify(assert, '', ''); + test_minify(assert, '', ''); + test_minify(assert, '
    ', '
    '); // will cause test to time-out if fail input = '

    For more information, read this Stack Overflow answer.

    '; output = '

    For more information, read this Stack Overflow answer.

    '; - test_minify_sync(assert, input, output); + test_minify(assert, input, output); input = ''; - test_minify_sync(assert, input, input); + test_minify(assert, input, input); input = ''; - test_minify_sync(assert, input, input); + test_minify(assert, input, input); input = '<$unicorn>'; - test_minify_sync_error(assert, input, 'Invalid tag name'); + assert.throws(function() { + minify(input); + }, 'Invalid tag name'); input = ''; - test_minify_sync(assert, input, input); + test_minify(assert, input, input); // https://github.com/kangax/html-minifier/issues/41 - test_minify_sync(assert, '', - '' - ); + test_minify(assert, '', ''); // https://github.com/kangax/html-minifier/issues/40 - test_minify_sync(assert, '[\']["]', '[\']["]'); + test_minify(assert, '[\']["]', '[\']["]'); // https://github.com/kangax/html-minifier/issues/21 - test_minify_sync(assert, '
    hey
    ', '
    hey
    '); + test_minify(assert, '
    hey
    ', '
    hey
    '); // https://github.com/kangax/html-minifier/issues/17 - test_minify_sync(assert, ':) link', ':) link'); + test_minify(assert, ':) link', ':) link'); // https://github.com/kangax/html-minifier/issues/169 - test_minify_sync(assert, 'ok', 'ok'); + test_minify(assert, 'ok', 'ok'); - test_minify_sync(assert, '', ''); + test_minify(assert, '', ''); // https://github.com/kangax/html-minifier/issues/229 - test_minify_sync(assert, '
    Hello :)
    ', '
    Hello :)
    '); + test_minify(assert, '
    Hello :)
    ', '
    Hello :)
    '); // https://github.com/kangax/html-minifier/issues/507 input = ''; - test_minify_sync(assert, input, input); - test_minify_sync_error(assert, '', 'invalid attribute name'); + test_minify(assert, input, input); + assert.throws(function() { + minify(''); + }, 'invalid attribute name'); // https://github.com/kangax/html-minifier/issues/512 input = ''; - test_minify_sync(assert, input, input); - input = '' + - ' placeholder="YYYY-MM-DD"' + - ' date-range-picker' + - ' data-ng-model="vm.value"' + - ' data-ng-model-options="{ debounce: 1000 }"' + - ' data-ng-pattern="vm.options.format"' + - ' data-options="vm.datepickerOptions">'; - test_minify_sync_error(assert, input, 'HTML comment inside tag'); + test_minify(assert, input, input); + assert.throws(function() { + minify( + '' + + ' placeholder="YYYY-MM-DD"' + + ' date-range-picker' + + ' data-ng-model="vm.value"' + + ' data-ng-model-options="{ debounce: 1000 }"' + + ' data-ng-pattern="vm.options.format"' + + ' data-options="vm.datepickerOptions">' + ); + }, 'HTML comment inside tag'); input = '
    '; output = '
    '; - test_minify_sync(assert, input, output); + test_minify(assert, input, output); output = '
    '; - test_minify_sync(assert, input, { + test_minify(assert, input, output, { decodeEntities: true, removeTagWhitespace: true, - }, output); + }); output = '
    '; - test_minify_sync(assert, input, { + test_minify(assert, input, output, { decodeEntities: true, removeAttributeQuotes: true - }, output); - test_minify_sync(assert, input, { + }); + test_minify(assert, input, output, { decodeEntities: true, removeAttributeQuotes: true, removeTagWhitespace: true, - }, output); + }); }); QUnit.test('options', function(assert) { var input = '

    blahblah 2blah 3

    '; - test_minify_sync(assert, input, input); - test_minify_sync(assert, input, {}, input); + test_minify(assert, input, input); + test_minify(assert, input, input, {}); }); QUnit.test('case normalization', function(assert) { - test_minify_sync(assert, '

    foo

    ', '

    foo

    '); - test_minify_sync(assert, '
    boo
    ', '
    boo
    '); - test_minify_sync(assert, '
    boo
    ', '
    boo
    '); - test_minify_sync(assert, '
    boo
    ', '
    boo
    '); - test_minify_sync(assert, '
    boo
    ', '
    boo
    '); - test_minify_sync(assert, '
    boo
    ', '
    boo
    '); + test_minify(assert, '

    foo

    ', '

    foo

    '); + test_minify(assert, '
    boo
    ', '
    boo
    '); + test_minify(assert, '
    boo
    ', '
    boo
    '); + test_minify(assert, '
    boo
    ', '
    boo
    '); + test_minify(assert, '
    boo
    ', '
    boo
    '); + test_minify(assert, '
    boo
    ', '
    boo
    '); }); QUnit.test('space normalization between attributes', function(assert) { - test_minify_sync(assert, '

    foo

    ', '

    foo

    '); - test_minify_sync(assert, '', ''); - test_minify_sync(assert, '

    foo

    ', '

    foo

    '); - test_minify_sync(assert, '

    foo

    ', '

    foo

    '); - test_minify_sync(assert, '', ''); - test_minify_sync(assert, '', ''); + test_minify(assert, '

    foo

    ', '

    foo

    '); + test_minify(assert, '', ''); + test_minify(assert, '

    foo

    ', '

    foo

    '); + test_minify(assert, '

    foo

    ', '

    foo

    '); + test_minify(assert, '', ''); + test_minify(assert, '', ''); }); QUnit.test('space normalization around text', function(assert) { var input, output; input = '

    blah

    \n\n\n '; - test_minify_sync(assert, input, input); + test_minify(assert, input, input); output = '

    blah

    '; - test_minify_sync(assert, input, { collapseWhitespace: true }, output); + test_minify(assert, input, output, { collapseWhitespace: true }); output = '

    blah

    '; - test_minify_sync(assert, input, { + test_minify(assert, input, output, { collapseWhitespace: true, conservativeCollapse: true - }, output); + }); output = '

    blah

    \n'; - test_minify_sync(assert, input, { + test_minify(assert, input, output, { collapseWhitespace: true, preserveLineBreaks: true - }, output); + }); output = '

    blah

    \n'; - test_minify_sync(assert, input, { + test_minify(assert, input, output, { collapseWhitespace: true, conservativeCollapse: true, preserveLineBreaks: true - }, output); + }); [ 'a', 'abbr', 'acronym', 'b', 'big', 'del', 'em', 'font', 'i', 'ins', 'kbd', 'mark', 's', 'samp', 'small', 'span', 'strike', 'strong', 'sub', 'sup', 'time', 'tt', 'u', 'var' ].forEach(function(el) { - test_minify_sync(assert, 'foo <' + el + '>baz bar', { collapseWhitespace: true }, 'foo <' + el + '>baz bar'); - test_minify_sync(assert, 'foo<' + el + '>bazbar', { collapseWhitespace: true }, 'foo<' + el + '>bazbar'); - test_minify_sync(assert, 'foo <' + el + '>bazbar', { collapseWhitespace: true }, 'foo <' + el + '>bazbar'); - test_minify_sync(assert, 'foo<' + el + '>baz bar', { collapseWhitespace: true }, 'foo<' + el + '>baz bar'); - test_minify_sync(assert, 'foo <' + el + '> baz bar', { collapseWhitespace: true }, 'foo <' + el + '>baz bar'); - test_minify_sync(assert, 'foo<' + el + '> baz bar', { collapseWhitespace: true }, 'foo<' + el + '> baz bar'); - test_minify_sync(assert, 'foo <' + el + '> baz bar', { collapseWhitespace: true }, 'foo <' + el + '>baz bar'); - test_minify_sync(assert, 'foo<' + el + '> baz bar', { collapseWhitespace: true }, 'foo<' + el + '> baz bar'); - test_minify_sync(assert, '
    foo <' + el + '>baz bar
    ', { collapseWhitespace: true }, '
    foo <' + el + '>baz bar
    '); - test_minify_sync(assert, '
    foo<' + el + '>bazbar
    ', { collapseWhitespace: true }, '
    foo<' + el + '>bazbar
    '); - test_minify_sync(assert, '
    foo <' + el + '>bazbar
    ', { collapseWhitespace: true }, '
    foo <' + el + '>bazbar
    '); - test_minify_sync(assert, '
    foo<' + el + '>baz bar
    ', { collapseWhitespace: true }, '
    foo<' + el + '>baz bar
    '); - test_minify_sync(assert, '
    foo <' + el + '> baz bar
    ', { collapseWhitespace: true }, '
    foo <' + el + '>baz bar
    '); - test_minify_sync(assert, '
    foo<' + el + '> baz bar
    ', { collapseWhitespace: true }, '
    foo<' + el + '> baz bar
    '); - test_minify_sync(assert, '
    foo <' + el + '> baz bar
    ', { collapseWhitespace: true }, '
    foo <' + el + '>baz bar
    '); - test_minify_sync(assert, '
    foo<' + el + '> baz bar
    ', { collapseWhitespace: true }, '
    foo<' + el + '> baz bar
    '); + test_minify(assert, 'foo <' + el + '>baz bar', 'foo <' + el + '>baz bar', { collapseWhitespace: true }); + test_minify(assert, 'foo<' + el + '>bazbar', 'foo<' + el + '>bazbar', { collapseWhitespace: true }); + test_minify(assert, 'foo <' + el + '>bazbar', 'foo <' + el + '>bazbar', { collapseWhitespace: true }); + test_minify(assert, 'foo<' + el + '>baz bar', 'foo<' + el + '>baz bar', { collapseWhitespace: true }); + test_minify(assert, 'foo <' + el + '> baz bar', 'foo <' + el + '>baz bar', { collapseWhitespace: true }); + test_minify(assert, 'foo<' + el + '> baz bar', 'foo<' + el + '> baz bar', { collapseWhitespace: true }); + test_minify(assert, 'foo <' + el + '> baz bar', 'foo <' + el + '>baz bar', { collapseWhitespace: true }); + test_minify(assert, 'foo<' + el + '> baz bar', 'foo<' + el + '> baz bar', { collapseWhitespace: true }); + test_minify(assert, '
    foo <' + el + '>baz bar
    ', '
    foo <' + el + '>baz bar
    ', { collapseWhitespace: true }); + test_minify(assert, '
    foo<' + el + '>bazbar
    ', '
    foo<' + el + '>bazbar
    ', { collapseWhitespace: true }); + test_minify(assert, '
    foo <' + el + '>bazbar
    ', '
    foo <' + el + '>bazbar
    ', { collapseWhitespace: true }); + test_minify(assert, '
    foo<' + el + '>baz bar
    ', '
    foo<' + el + '>baz bar
    ', { collapseWhitespace: true }); + test_minify(assert, '
    foo <' + el + '> baz bar
    ', '
    foo <' + el + '>baz bar
    ', { collapseWhitespace: true }); + test_minify(assert, '
    foo<' + el + '> baz bar
    ', '
    foo<' + el + '> baz bar
    ', { collapseWhitespace: true }); + test_minify(assert, '
    foo <' + el + '> baz bar
    ', '
    foo <' + el + '>baz bar
    ', { collapseWhitespace: true }); + test_minify(assert, '
    foo<' + el + '> baz bar
    ', '
    foo<' + el + '> baz bar
    ', { collapseWhitespace: true }); }); // Don't trim whitespace around element, but do trim within [ 'bdi', 'bdo', 'button', 'cite', 'code', 'dfn', 'math', 'q', 'rt', 'rtc', 'ruby', 'svg' ].forEach(function(el) { - test_minify_sync(assert, 'foo <' + el + '>baz bar', { collapseWhitespace: true }, 'foo <' + el + '>baz bar'); - test_minify_sync(assert, 'foo<' + el + '>bazbar', { collapseWhitespace: true }, 'foo<' + el + '>bazbar'); - test_minify_sync(assert, 'foo <' + el + '>bazbar', { collapseWhitespace: true }, 'foo <' + el + '>bazbar'); - test_minify_sync(assert, 'foo<' + el + '>baz bar', { collapseWhitespace: true }, 'foo<' + el + '>baz bar'); - test_minify_sync(assert, 'foo <' + el + '> baz bar', { collapseWhitespace: true }, 'foo <' + el + '>baz bar'); - test_minify_sync(assert, 'foo<' + el + '> baz bar', { collapseWhitespace: true }, 'foo<' + el + '>bazbar'); - test_minify_sync(assert, 'foo <' + el + '> baz bar', { collapseWhitespace: true }, 'foo <' + el + '>bazbar'); - test_minify_sync(assert, 'foo<' + el + '> baz bar', { collapseWhitespace: true }, 'foo<' + el + '>baz bar'); - test_minify_sync(assert, '
    foo <' + el + '>baz bar
    ', { collapseWhitespace: true }, '
    foo <' + el + '>baz bar
    '); - test_minify_sync(assert, '
    foo<' + el + '>bazbar
    ', { collapseWhitespace: true }, '
    foo<' + el + '>bazbar
    '); - test_minify_sync(assert, '
    foo <' + el + '>bazbar
    ', { collapseWhitespace: true }, '
    foo <' + el + '>bazbar
    '); - test_minify_sync(assert, '
    foo<' + el + '>baz bar
    ', { collapseWhitespace: true }, '
    foo<' + el + '>baz bar
    '); - test_minify_sync(assert, '
    foo <' + el + '> baz bar
    ', { collapseWhitespace: true }, '
    foo <' + el + '>baz bar
    '); - test_minify_sync(assert, '
    foo<' + el + '> baz bar
    ', { collapseWhitespace: true }, '
    foo<' + el + '>bazbar
    '); - test_minify_sync(assert, '
    foo <' + el + '> baz bar
    ', { collapseWhitespace: true }, '
    foo <' + el + '>bazbar
    '); - test_minify_sync(assert, '
    foo<' + el + '> baz bar
    ', { collapseWhitespace: true }, '
    foo<' + el + '>baz bar
    '); + test_minify(assert, 'foo <' + el + '>baz bar', 'foo <' + el + '>baz bar', { collapseWhitespace: true }); + test_minify(assert, 'foo<' + el + '>bazbar', 'foo<' + el + '>bazbar', { collapseWhitespace: true }); + test_minify(assert, 'foo <' + el + '>bazbar', 'foo <' + el + '>bazbar', { collapseWhitespace: true }); + test_minify(assert, 'foo<' + el + '>baz bar', 'foo<' + el + '>baz bar', { collapseWhitespace: true }); + test_minify(assert, 'foo <' + el + '> baz bar', 'foo <' + el + '>baz bar', { collapseWhitespace: true }); + test_minify(assert, 'foo<' + el + '> baz bar', 'foo<' + el + '>bazbar', { collapseWhitespace: true }); + test_minify(assert, 'foo <' + el + '> baz bar', 'foo <' + el + '>bazbar', { collapseWhitespace: true }); + test_minify(assert, 'foo<' + el + '> baz bar', 'foo<' + el + '>baz bar', { collapseWhitespace: true }); + test_minify(assert, '
    foo <' + el + '>baz bar
    ', '
    foo <' + el + '>baz bar
    ', { collapseWhitespace: true }); + test_minify(assert, '
    foo<' + el + '>bazbar
    ', '
    foo<' + el + '>bazbar
    ', { collapseWhitespace: true }); + test_minify(assert, '
    foo <' + el + '>bazbar
    ', '
    foo <' + el + '>bazbar
    ', { collapseWhitespace: true }); + test_minify(assert, '
    foo<' + el + '>baz bar
    ', '
    foo<' + el + '>baz bar
    ', { collapseWhitespace: true }); + test_minify(assert, '
    foo <' + el + '> baz bar
    ', '
    foo <' + el + '>baz bar
    ', { collapseWhitespace: true }); + test_minify(assert, '
    foo<' + el + '> baz bar
    ', '
    foo<' + el + '>bazbar
    ', { collapseWhitespace: true }); + test_minify(assert, '
    foo <' + el + '> baz bar
    ', '
    foo <' + el + '>bazbar
    ', { collapseWhitespace: true }); + test_minify(assert, '
    foo<' + el + '> baz bar
    ', '
    foo<' + el + '>baz bar
    ', { collapseWhitespace: true }); }); [ [' foo ', 'foo'], @@ -466,39 +468,39 @@ QUnit.test('space normalization around text', function(assert) { ['a b c', 'a b c'], ['a b c', 'a b c'] ].forEach(function(inputs) { - test_minify_sync(assert, inputs[0], { + test_minify(assert, inputs[0], inputs[0], { collapseWhitespace: true, conservativeCollapse: true - }, inputs[0], inputs[0]); - test_minify_sync(assert, inputs[0], { collapseWhitespace: true }, inputs[1], inputs[0]); + }, inputs[0]); + test_minify(assert, inputs[0], inputs[1], { collapseWhitespace: true }, inputs[0]); var input = '
    ' + inputs[0] + '
    '; - test_minify_sync(assert, input, { + test_minify(assert, input, input, { collapseWhitespace: true, conservativeCollapse: true - }, input, input); + }, input); var output = '
    ' + inputs[1] + '
    '; - test_minify_sync(assert, input, { collapseWhitespace: true }, output, input); - }); - test_minify_sync(assert, '

    foo bar

    ', { collapseWhitespace: true }, '

    foo bar

    '); - test_minify_sync(assert, '

    foobar

    ', { collapseWhitespace: true }, '

    foobar

    '); - test_minify_sync(assert, '

    foo bar

    ', { collapseWhitespace: true }, '

    foo bar

    '); - test_minify_sync(assert, '

    foo bar

    ', { collapseWhitespace: true }, '

    foo bar

    '); - test_minify_sync(assert, '

    foo bar

    ', { collapseWhitespace: true }, '

    foo bar

    '); - test_minify_sync(assert, '

    foobar

    ', { collapseWhitespace: true }, '

    foobar

    '); - test_minify_sync(assert, '

    foo bar

    ', { collapseWhitespace: true }, '

    foo bar

    '); - test_minify_sync(assert, '

    foo bar

    ', { collapseWhitespace: true }, '

    foo bar

    '); - test_minify_sync(assert, '

    foo bar

    ', { collapseWhitespace: true }, '

    foo bar

    '); - test_minify_sync(assert, '

    foobar

    ', { collapseWhitespace: true }, '

    foobar

    '); - test_minify_sync(assert, '

    foo bar

    ', { collapseWhitespace: true }, '

    foo bar

    '); - test_minify_sync(assert, '

    foo bar

    ', { collapseWhitespace: true }, '

    foo bar

    '); - test_minify_sync(assert, '

    foo bar

    ', { collapseWhitespace: true }, '

    foo bar

    '); - test_minify_sync(assert, '

    foo bar

    ', { collapseWhitespace: true }, '

    foo bar

    '); - test_minify_sync(assert, '

    foo bar

    ', { collapseWhitespace: true }, '

    foo bar

    '); - test_minify_sync(assert, '
    Empty not
    ', { collapseWhitespace: true }, '
    Empty not
    '); - test_minify_sync(assert, '
    a c
    ', { + test_minify(assert, input, output, { collapseWhitespace: true }, input); + }); + test_minify(assert, '

    foo bar

    ', '

    foo bar

    ', { collapseWhitespace: true }); + test_minify(assert, '

    foobar

    ', '

    foobar

    ', { collapseWhitespace: true }); + test_minify(assert, '

    foo bar

    ', '

    foo bar

    ', { collapseWhitespace: true }); + test_minify(assert, '

    foo bar

    ', '

    foo bar

    ', { collapseWhitespace: true }); + test_minify(assert, '

    foo bar

    ', '

    foo bar

    ', { collapseWhitespace: true }); + test_minify(assert, '

    foobar

    ', '

    foobar

    ', { collapseWhitespace: true }); + test_minify(assert, '

    foo bar

    ', '

    foo bar

    ', { collapseWhitespace: true }); + test_minify(assert, '

    foo bar

    ', '

    foo bar

    ', { collapseWhitespace: true }); + test_minify(assert, '

    foo bar

    ', '

    foo bar

    ', { collapseWhitespace: true }); + test_minify(assert, '

    foobar

    ', '

    foobar

    ', { collapseWhitespace: true }); + test_minify(assert, '

    foo bar

    ', '

    foo bar

    ', { collapseWhitespace: true }); + test_minify(assert, '

    foo bar

    ', '

    foo bar

    ', { collapseWhitespace: true }); + test_minify(assert, '

    foo bar

    ', '

    foo bar

    ', { collapseWhitespace: true }); + test_minify(assert, '

    foo bar

    ', '

    foo bar

    ', { collapseWhitespace: true }); + test_minify(assert, '

    foo bar

    ', '

    foo bar

    ', { collapseWhitespace: true }); + test_minify(assert, '
    Empty not
    ', '
    Empty not
    ', { collapseWhitespace: true }); + test_minify(assert, '
    a c
    ', '
    a c
    ', { collapseWhitespace: true, removeComments: true - }, '
    a c
    '); + }); [ ' a c ', ' a c ', @@ -510,64 +512,64 @@ QUnit.test('space normalization around text', function(assert) { ' a c ', ' a c ' ].forEach(function(input) { - test_minify_sync(assert, input, { + test_minify(assert, input, input, { collapseWhitespace: true, conservativeCollapse: true - }, input, input); - test_minify_sync(assert, input, { + }, input); + test_minify(assert, input, 'a c', { collapseWhitespace: true, removeComments: true - }, 'a c', input); - test_minify_sync(assert, input, { + }, input); + test_minify(assert, input, ' a c ', { collapseWhitespace: true, conservativeCollapse: true, removeComments: true - }, ' a c ', input); + }, input); input = '

    ' + input + '

    '; - test_minify_sync(assert, input, { + test_minify(assert, input, input, { collapseWhitespace: true, conservativeCollapse: true - }, input, input); - test_minify_sync(assert, input, { + }, input); + test_minify(assert, input, '

    a c

    ', { collapseWhitespace: true, removeComments: true - }, '

    a c

    ', input); - test_minify_sync(assert, input, { + }, input); + test_minify(assert, input, '

    a c

    ', { collapseWhitespace: true, conservativeCollapse: true, removeComments: true - }, '

    a c

    ', input); + }, input); }); input = '
  • foo
  • '; output = '
  • foo
  • '; - test_minify_sync(assert, input, { collapseWhitespace: true }, output); + test_minify(assert, input, output, { collapseWhitespace: true }); input = '
  • foo
  • '; - test_minify_sync(assert, input, { collapseWhitespace: true }, output); + test_minify(assert, input, output, { collapseWhitespace: true }); input = '
  • foo
  • '; - test_minify_sync(assert, input, { collapseWhitespace: true }, output); + test_minify(assert, input, output, { collapseWhitespace: true }); input = '
  • foo
  • '; - test_minify_sync(assert, input, { collapseWhitespace: true }, output); + test_minify(assert, input, output, { collapseWhitespace: true }); input = '
  • foo
  • '; - test_minify_sync(assert, input, { collapseWhitespace: true }, output); + test_minify(assert, input, output, { collapseWhitespace: true }); input = ''; output = ''; - test_minify_sync(assert, input, { collapseWhitespace: true }, output); + test_minify(assert, input, output, { collapseWhitespace: true }); input = ' '; output = ''; - test_minify_sync(assert, input, { collapseWhitespace: true }, output); + test_minify(assert, input, output, { collapseWhitespace: true }); input = ' '; output = ''; - test_minify_sync(assert, input, { collapseWhitespace: true }, output); + test_minify(assert, input, output, { collapseWhitespace: true }); input = '

    foo\u00A0bar\nbaz \u00A0\nmoo\t

    '; output = '

    foo\u00A0bar baz \u00A0 moo

    '; - test_minify_sync(assert, input, { collapseWhitespace: true }, output); + test_minify(assert, input, output, { collapseWhitespace: true }); input = '\n' + '\n' + ' bar \n' + '\n' + '\n'; output = ' bar '; - test_minify_sync(assert, input, { collapseWhitespace: true }, output); + test_minify(assert, input, output, { collapseWhitespace: true }); input = '
    \n' +
               'foo\n' +
               '
    \n' + @@ -575,130 +577,130 @@ QUnit.test('space normalization around text', function(assert) { '
    \n' + 'baz\n'; output = '
    \nfoo\n
    \nbar\n
    baz'; - test_minify_sync(assert, input, { collapseWhitespace: true }, output); + test_minify(assert, input, output, { collapseWhitespace: true }); }); QUnit.test('types of whitespace that should always be preserved', function(assert) { // Hair space: var input = '
    \u200afo\u200ao\u200a
    '; - test_minify_sync(assert, input, { collapseWhitespace: true }, input); + test_minify(assert, input, input, { collapseWhitespace: true }); // Hair space passed as HTML entity: var inputWithEntities = '
     fo o 
    '; - test_minify_sync(assert, inputWithEntities, { collapseWhitespace: true }, inputWithEntities); + test_minify(assert, inputWithEntities, inputWithEntities, { collapseWhitespace: true }); // Hair space passed as HTML entity, in decodeEntities:true mode: - test_minify_sync(assert, inputWithEntities, { collapseWhitespace: true, decodeEntities: true }, input); + test_minify(assert, inputWithEntities, input, { collapseWhitespace: true, decodeEntities: true }); // Non-breaking space: input = '
    \xa0fo\xa0o\xa0
    '; - test_minify_sync(assert, input, { collapseWhitespace: true }, input); + test_minify(assert, input, input, { collapseWhitespace: true }); // Non-breaking space passed as HTML entity: inputWithEntities = '
     fo o 
    '; - test_minify_sync(assert, inputWithEntities, { collapseWhitespace: true }, inputWithEntities); + test_minify(assert, inputWithEntities, inputWithEntities, { collapseWhitespace: true }); // Non-breaking space passed as HTML entity, in decodeEntities:true mode: - test_minify_sync(assert, inputWithEntities, { collapseWhitespace: true, decodeEntities: true }, input); + test_minify(assert, inputWithEntities, input, { collapseWhitespace: true, decodeEntities: true }); // Do not remove hair space when preserving line breaks between tags: input = '

    \u200a\n

    \n'; - test_minify_sync(assert, input, { collapseWhitespace: true, preserveLineBreaks: true }, input); + test_minify(assert, input, input, { collapseWhitespace: true, preserveLineBreaks: true }); // Preserve hair space in attributes: input = '

    '; - test_minify_sync(assert, input, { collapseWhitespace: true }, input); + test_minify(assert, input, input, { collapseWhitespace: true }); // Preserve hair space in class names when deduplicating and reordering: input = ''; - test_minify_sync(assert, input, { sortClassName: false }, input); - test_minify_sync(assert, input, { sortClassName: true }, input); + test_minify(assert, input, input, { sortClassName: false }); + test_minify(assert, input, input, { sortClassName: true }); }); QUnit.test('doctype normalization', function(assert) { var input; input = ''; - test_minify_sync(assert, input, { useShortDoctype: true }, ''); + test_minify(assert, input, '', { useShortDoctype: true }); input = ''; - test_minify_sync(assert, input, { useShortDoctype: true }, input); + test_minify(assert, input, input, { useShortDoctype: true }); input = ''; - test_minify_sync(assert, input, { useShortDoctype: false }, input); + test_minify(assert, input, input, { useShortDoctype: false }); }); QUnit.test('removing comments', function(assert) { var input; input = ''; - test_minify_sync(assert, input, { removeComments: true }, ''); + test_minify(assert, input, '', { removeComments: true }); input = '
    baz
    '; - test_minify_sync(assert, input, { removeComments: true }, '
    baz
    '); - test_minify_sync(assert, input, { removeComments: false }, input); + test_minify(assert, input, '
    baz
    ', { removeComments: true }); + test_minify(assert, input, input, { removeComments: false }); input = '

    foo

    '; - test_minify_sync(assert, input, { removeComments: true }, input); + test_minify(assert, input, input, { removeComments: true }); input = ''; - test_minify_sync(assert, input, { removeComments: true }, input); + test_minify(assert, input, input, { removeComments: true }); input = ''; - test_minify_sync(assert, input, { removeComments: true }, ''); + test_minify(assert, input, '', { removeComments: true }); }); QUnit.test('ignoring comments', function(assert) { var input, output; input = ''; - test_minify_sync(assert, input, { removeComments: true }, input); - test_minify_sync(assert, input, { removeComments: false }, input); + test_minify(assert, input, input, { removeComments: true }); + test_minify(assert, input, input, { removeComments: false }); input = '
    baz
    '; - test_minify_sync(assert, input, { removeComments: true }, input); - test_minify_sync(assert, input, { removeComments: false }, input); + test_minify(assert, input, input, { removeComments: true }); + test_minify(assert, input, input, { removeComments: false }); input = '
    baz
    '; - test_minify_sync(assert, input, { removeComments: true }, '
    baz
    '); - test_minify_sync(assert, input, { removeComments: false }, input); + test_minify(assert, input, '
    baz
    ', { removeComments: true }); + test_minify(assert, input, input, { removeComments: false }); input = ''; - test_minify_sync(assert, input, { removeComments: true }, ''); - test_minify_sync(assert, input, { removeComments: false }, input); + test_minify(assert, input, '', { removeComments: true }); + test_minify(assert, input, input, { removeComments: false }); input = '
    \n\n \t
    \n\n

    \n\n \n\n

    \n\n
    '; output = '

    '; - test_minify_sync(assert, input, { removeComments: true }, input); - test_minify_sync(assert, input, { removeComments: true, collapseWhitespace: true }, output); - test_minify_sync(assert, input, { removeComments: false }, input); - test_minify_sync(assert, input, { removeComments: false, collapseWhitespace: true }, output); + test_minify(assert, input, input, { removeComments: true }); + test_minify(assert, input, output, { removeComments: true, collapseWhitespace: true }); + test_minify(assert, input, input, { removeComments: false }); + test_minify(assert, input, output, { removeComments: false, collapseWhitespace: true }); input = '

    foo

    '; - test_minify_sync(assert, input, { removeComments: true }, input); + test_minify(assert, input, input, { removeComments: true }); }); QUnit.test('conditional comments', function(assert) { var input, output; input = 'test'; - test_minify_sync(assert, input, { removeComments: true }, input); + test_minify(assert, input, input, { removeComments: true }); input = ''; - test_minify_sync(assert, input, { removeComments: true }, input); + test_minify(assert, input, input, { removeComments: true }); input = 'test'; - test_minify_sync(assert, input, { removeComments: true }, input); + test_minify(assert, input, input, { removeComments: true }); input = 'test'; - test_minify_sync(assert, input, { removeComments: true }, input); + test_minify(assert, input, input, { removeComments: true }); input = ''; - test_minify_sync(assert, input, { removeComments: true }, input); + test_minify(assert, input, input, { removeComments: true }); input = ''; - test_minify_sync(assert, input, { removeComments: true }, input); + test_minify(assert, input, input, { removeComments: true }); input = '\n' + ' \n' + @@ -716,22 +718,22 @@ QUnit.test('conditional comments', function(assert) { ' alert("ie8!");\n' + ' \n' + ' '; - test_minify_sync(assert, input, { + test_minify(assert, input, output, { minifyJS: true, removeComments: true, collapseWhitespace: true, removeOptionalTags: true, removeScriptTypeAttributes: true - }, output); + }); output = ''; - test_minify_sync(assert, input, { + test_minify(assert, input, output, { minifyJS: true, removeComments: true, collapseWhitespace: true, removeOptionalTags: true, removeScriptTypeAttributes: true, processConditionalComments: true - }, output); + }); input = '\n' + '\n' + @@ -759,15 +761,15 @@ QUnit.test('conditional comments', function(assert) { '' + '' + 'Document'; - test_minify_sync(assert, input, { + test_minify(assert, input, output, { removeComments: true, collapseWhitespace: true - }, output); - test_minify_sync(assert, input, { + }); + test_minify(assert, input, output, { removeComments: true, collapseWhitespace: true, processConditionalComments: true - }, output); + }); }); QUnit.test('collapsing space in conditional comments', function(assert) { @@ -776,215 +778,215 @@ QUnit.test('collapsing space in conditional comments', function(assert) { input = ''; - test_minify_sync(assert, input, { removeComments: true }, input); - test_minify_sync(assert, input, { removeComments: true, collapseWhitespace: true }, input); + test_minify(assert, input, input, { removeComments: true }); + test_minify(assert, input, input, { removeComments: true, collapseWhitespace: true }); output = ''; - test_minify_sync(assert, input, { removeComments: true, processConditionalComments: true }, output); + test_minify(assert, input, output, { removeComments: true, processConditionalComments: true }); output = ''; - test_minify_sync(assert, input, { + test_minify(assert, input, output, { removeComments: true, collapseWhitespace: true, processConditionalComments: true - }, output); + }); input = ''; - test_minify_sync(assert, input, { removeComments: true }, input); - test_minify_sync(assert, input, { removeComments: true, collapseWhitespace: true }, input); + test_minify(assert, input, input, { removeComments: true }); + test_minify(assert, input, input, { removeComments: true, collapseWhitespace: true }); output = ''; - test_minify_sync(assert, input, { + test_minify(assert, input, output, { removeComments: true, collapseWhitespace: true, processConditionalComments: true - }, output); + }); }); QUnit.test('remove comments from scripts', function(assert) { var input, output; input = ''; - test_minify_sync(assert, input, input); + test_minify(assert, input, input); output = ''; - test_minify_sync(assert, input, { minifyJS: true }, output); + test_minify(assert, input, output, { minifyJS: true }); input = ''; - test_minify_sync(assert, input, input); + test_minify(assert, input, input); output = ''; - test_minify_sync(assert, input, { minifyJS: true }, output); + test_minify(assert, input, output, { minifyJS: true }); input = ''; - test_minify_sync(assert, input, input); + test_minify(assert, input, input); output = ''; - test_minify_sync(assert, input, { minifyJS: true }, output); + test_minify(assert, input, output, { minifyJS: true }); input = ''; - test_minify_sync(assert, input, input); - test_minify_sync(assert, input, { minifyJS: true }, input); + test_minify(assert, input, input); + test_minify(assert, input, input, { minifyJS: true }); input = ''; - test_minify_sync(assert, input, input); - test_minify_sync(assert, input, { minifyJS: true }, input); + test_minify(assert, input, input); + test_minify(assert, input, input, { minifyJS: true }); input = ''; - test_minify_sync(assert, input, input); + test_minify(assert, input, input); output = ''; - test_minify_sync(assert, input, { minifyJS: true }, output); + test_minify(assert, input, output, { minifyJS: true }); input = ''; - test_minify_sync(assert, input, input); - test_minify_sync(assert, input, { minifyJS: true }, input); + test_minify(assert, input, input); + test_minify(assert, input, input, { minifyJS: true }); input = ''; - test_minify_sync(assert, input, input); + test_minify(assert, input, input); output = ''; - test_minify_sync(assert, input, { minifyJS: true }, output); + test_minify(assert, input, output, { minifyJS: true }); input = ''; - test_minify_sync(assert, input, input); + test_minify(assert, input, input); output = ''; - test_minify_sync(assert, input, { minifyJS: true }, output); + test_minify(assert, input, output, { minifyJS: true }); input = ''; - test_minify_sync(assert, input, input); - test_minify_sync(assert, input, { minifyJS: true }, input); + test_minify(assert, input, input); + test_minify(assert, input, input, { minifyJS: true }); }); QUnit.test('remove comments from styles', function(assert) { var input, output; input = ''; - test_minify_sync(assert, input, input); + test_minify(assert, input, input); output = ''; - test_minify_sync(assert, input, { minifyCSS: true }, output); + test_minify(assert, input, output, { minifyCSS: true }); input = ''; - test_minify_sync(assert, input, input); + test_minify(assert, input, input); output = ''; - test_minify_sync(assert, input, { minifyCSS: true }, output); + test_minify(assert, input, output, { minifyCSS: true }); input = ''; - test_minify_sync(assert, input, input); + test_minify(assert, input, input); output = ''; - test_minify_sync(assert, input, { minifyCSS: true }, output); + test_minify(assert, input, output, { minifyCSS: true }); input = ''; - test_minify_sync(assert, input, input); + test_minify(assert, input, input); output = ''; - test_minify_sync(assert, input, { minifyCSS: true }, output); + test_minify(assert, input, output, { minifyCSS: true }); input = ''; - test_minify_sync(assert, input, input); + test_minify(assert, input, input); output = ''; - test_minify_sync(assert, input, { minifyCSS: true }, output); + test_minify(assert, input, output, { minifyCSS: true }); input = ''; - test_minify_sync(assert, input, input); + test_minify(assert, input, input); output = ''; - test_minify_sync(assert, input, { minifyCSS: true }, output); + test_minify(assert, input, output, { minifyCSS: true }); input = ''; - test_minify_sync(assert, input, input); + test_minify(assert, input, input); output = ''; - test_minify_sync(assert, input, { minifyCSS: true }, output); + test_minify(assert, input, output, { minifyCSS: true }); input = ''; - test_minify_sync(assert, input, input); + test_minify(assert, input, input); output = ''; - test_minify_sync(assert, input, { minifyCSS: true }, output); + test_minify(assert, input, output, { minifyCSS: true }); input = ''; - test_minify_sync(assert, input, input); - test_minify_sync(assert, input, { minifyCSS: true }, input); + test_minify(assert, input, input); + test_minify(assert, input, input, { minifyCSS: true }); }); QUnit.test('remove CDATA sections from scripts/styles', function(assert) { var input, output; input = ''; - test_minify_sync(assert, input, input); - test_minify_sync(assert, input, { minifyJS: true }, input); + test_minify(assert, input, input); + test_minify(assert, input, input, { minifyJS: true }); input = ''; - test_minify_sync(assert, input, input); - test_minify_sync(assert, input, { minifyJS: true }, input); + test_minify(assert, input, input); + test_minify(assert, input, input, { minifyJS: true }); input = ''; - test_minify_sync(assert, input, input); - test_minify_sync(assert, input, { minifyJS: true }, input); + test_minify(assert, input, input); + test_minify(assert, input, input, { minifyJS: true }); input = ''; - test_minify_sync(assert, input, input); - test_minify_sync(assert, input, { minifyJS: true }, input); + test_minify(assert, input, input); + test_minify(assert, input, input, { minifyJS: true }); input = ''; - test_minify_sync(assert, input, input); - test_minify_sync(assert, input, { minifyJS: true }, input); + test_minify(assert, input, input); + test_minify(assert, input, input, { minifyJS: true }); input = ''; - test_minify_sync(assert, input, input); + test_minify(assert, input, input); output = ''; - test_minify_sync(assert, input, { minifyJS: true }, output); + test_minify(assert, input, output, { minifyJS: true }); input = ''; - test_minify_sync(assert, input, input); + test_minify(assert, input, input); output = ''; - test_minify_sync(assert, input, { minifyJS: true }, output); + test_minify(assert, input, output, { minifyJS: true }); input = ''; - test_minify_sync(assert, input, input); + test_minify(assert, input, input); output = ''; - test_minify_sync(assert, input, { minifyJS: true }, output); + test_minify(assert, input, output, { minifyJS: true }); input = ''; - test_minify_sync(assert, input, input); + test_minify(assert, input, input); output = ''; - test_minify_sync(assert, input, { minifyJS: true }, output); + test_minify(assert, input, output, { minifyJS: true }); input = ''; - test_minify_sync(assert, input, input); + test_minify(assert, input, input); output = ''; - test_minify_sync(assert, input, { minifyCSS: true }, output); + test_minify(assert, input, output, { minifyCSS: true }); input = ''; - test_minify_sync(assert, input, input); + test_minify(assert, input, input); output = ''; - test_minify_sync(assert, input, { minifyCSS: true }, output); + test_minify(assert, input, output, { minifyCSS: true }); input = ''; - test_minify_sync(assert, input, input); + test_minify(assert, input, input); output = ''; - test_minify_sync(assert, input, { minifyCSS: true }, output); + test_minify(assert, input, output, { minifyCSS: true }); input = ''; - test_minify_sync(assert, input, input); + test_minify(assert, input, input); output = ''; - test_minify_sync(assert, input, { minifyCSS: true }, output); + test_minify(assert, input, output, { minifyCSS: true }); input = ''; - test_minify_sync(assert, input, input); + test_minify(assert, input, input); output = ''; - test_minify_sync(assert, input, { minifyCSS: true }, output); + test_minify(assert, input, output, { minifyCSS: true }); input = ''; - test_minify_sync(assert, input, input); + test_minify(assert, input, input); output = ''; - test_minify_sync(assert, input, { minifyCSS: true }, output); + test_minify(assert, input, output, { minifyCSS: true }); input = ''; - test_minify_sync(assert, input, input); + test_minify(assert, input, input); output = ''; - test_minify_sync(assert, input, { minifyCSS: true }, output); + test_minify(assert, input, output, { minifyCSS: true }); input = ''; - test_minify_sync(assert, input, input); - test_minify_sync(assert, input, { minifyCSS: true }, input); + test_minify(assert, input, input); + test_minify(assert, input, input, { minifyCSS: true }); }); QUnit.test('custom processors', function(assert) { @@ -995,125 +997,125 @@ QUnit.test('custom processors', function(assert) { } input = ''; - test_minify_sync(assert, input, input); - test_minify_sync(assert, input, { minifyCSS: null }, input); - test_minify_sync(assert, input, { minifyCSS: false }, input); + test_minify(assert, input, input); + test_minify(assert, input, input, { minifyCSS: null }); + test_minify(assert, input, input, { minifyCSS: false }); output = ''; - test_minify_sync(assert, input, { minifyCSS: css }, output); + test_minify(assert, input, output, { minifyCSS: css }); input = '

    '; - test_minify_sync(assert, input, input); - test_minify_sync(assert, input, { minifyCSS: null }, input); - test_minify_sync(assert, input, { minifyCSS: false }, input); + test_minify(assert, input, input); + test_minify(assert, input, input, { minifyCSS: null }); + test_minify(assert, input, input, { minifyCSS: false }); output = '

    '; - test_minify_sync(assert, input, { minifyCSS: css }, output); + test_minify(assert, input, output, { minifyCSS: css }); input = ''; - test_minify_sync(assert, input, input); - test_minify_sync(assert, input, { minifyCSS: null }, input); - test_minify_sync(assert, input, { minifyCSS: false }, input); + test_minify(assert, input, input); + test_minify(assert, input, input, { minifyCSS: null }); + test_minify(assert, input, input, { minifyCSS: false }); output = ''; - test_minify_sync(assert, input, { minifyCSS: css }, output); + test_minify(assert, input, output, { minifyCSS: css }); input = ''; - test_minify_sync(assert, input, input); - test_minify_sync(assert, input, { minifyCSS: null }, input); - test_minify_sync(assert, input, { minifyCSS: false }, input); + test_minify(assert, input, input); + test_minify(assert, input, input, { minifyCSS: null }); + test_minify(assert, input, input, { minifyCSS: false }); output = ''; - test_minify_sync(assert, input, { minifyCSS: css }, output); + test_minify(assert, input, output, { minifyCSS: css }); function js(text, inline) { return inline ? 'Inline JS' : 'Normal JS'; } input = ''; - test_minify_sync(assert, input, input); - test_minify_sync(assert, input, { minifyJS: null }, input); - test_minify_sync(assert, input, { minifyJS: false }, input); + test_minify(assert, input, input); + test_minify(assert, input, input, { minifyJS: null }); + test_minify(assert, input, input, { minifyJS: false }); output = ''; - test_minify_sync(assert, input, { minifyJS: js }, output); + test_minify(assert, input, output, { minifyJS: js }); input = '

    '; - test_minify_sync(assert, input, input); - test_minify_sync(assert, input, { minifyJS: null }, input); - test_minify_sync(assert, input, { minifyJS: false }, input); + test_minify(assert, input, input); + test_minify(assert, input, input, { minifyJS: null }); + test_minify(assert, input, input, { minifyJS: false }); output = '

    '; - test_minify_sync(assert, input, { minifyJS: js }, output); + test_minify(assert, input, output, { minifyJS: js }); function url() { return 'URL'; } input = 'bar'; - test_minify_sync(assert, input, input); - test_minify_sync(assert, input, { minifyURLs: null }, input); - test_minify_sync(assert, input, { minifyURLs: false }, input); + test_minify(assert, input, input); + test_minify(assert, input, input, { minifyURLs: null }); + test_minify(assert, input, input, { minifyURLs: false }); output = 'bar'; - test_minify_sync(assert, input, { minifyURLs: url }, output); + test_minify(assert, input, output, { minifyURLs: url }); input = ''; - test_minify_sync(assert, input, input); - test_minify_sync(assert, input, { minifyURLs: null }, input); - test_minify_sync(assert, input, { minifyURLs: false }, input); - test_minify_sync(assert, input, { minifyURLs: url }, input); + test_minify(assert, input, input); + test_minify(assert, input, input, { minifyURLs: null }); + test_minify(assert, input, input, { minifyURLs: false }); + test_minify(assert, input, input, { minifyURLs: url }); output = ''; - test_minify_sync(assert, input, { minifyCSS: true, minifyURLs: url }, output); + test_minify(assert, input, output, { minifyCSS: true, minifyURLs: url }); }); QUnit.test('empty attributes', function(assert) { var input; input = '

    x

    '; - test_minify_sync(assert, input, { removeEmptyAttributes: true }, '

    x

    '); + test_minify(assert, input, '

    x

    ', { removeEmptyAttributes: true }); input = '

    x

    '; - test_minify_sync(assert, input, { removeEmptyAttributes: true }, '

    x

    '); + test_minify(assert, input, '

    x

    ', { removeEmptyAttributes: true }); input = ''; - test_minify_sync(assert, input, { removeEmptyAttributes: true }, ''); + test_minify(assert, input, '', { removeEmptyAttributes: true }); input = ''; - test_minify_sync(assert, input, { removeEmptyAttributes: true }, ''); + test_minify(assert, input, '', { removeEmptyAttributes: true }); input = ''; - test_minify_sync(assert, input, { removeEmptyAttributes: true }, ''); + test_minify(assert, input, '', { removeEmptyAttributes: true }); // preserve unrecognized attribute // remove recognized attrs with unspecified values input = '
    '; - test_minify_sync(assert, input, { removeEmptyAttributes: true }, '
    '); + test_minify(assert, input, '
    ', { removeEmptyAttributes: true }); // additional remove attributes input = ''; - test_minify_sync(assert, input, { removeEmptyAttributes: function(attrName, tag) { return tag === 'img' && attrName === 'src'; } }, ''); + test_minify(assert, input, '', { removeEmptyAttributes: function(attrName, tag) { return tag === 'img' && attrName === 'src'; } }); }); QUnit.test('cleaning class/style attributes', function(assert) { var input, output; input = '

    foo bar baz

    '; - test_minify_sync(assert, input, '

    foo bar baz

    '); + test_minify(assert, input, '

    foo bar baz

    '); input = '

    foo bar baz

    '; - test_minify_sync(assert, input, '

    foo bar baz

    '); - test_minify_sync(assert, input, { removeAttributeQuotes: true }, '

    foo bar baz

    '); + test_minify(assert, input, '

    foo bar baz

    '); + test_minify(assert, input, '

    foo bar baz

    ', { removeAttributeQuotes: true }); input = '

    foo bar baz

    '; output = '

    foo bar baz

    '; - test_minify_sync(assert, input, output); + test_minify(assert, input, output); input = '

    foo bar baz

    '; output = '

    foo bar baz

    '; - test_minify_sync(assert, input, output); + test_minify(assert, input, output); input = '

    '; output = '

    '; - test_minify_sync(assert, input, output); + test_minify(assert, input, output); input = '

    '; output = '

    '; - test_minify_sync(assert, input, output); + test_minify(assert, input, output); }); QUnit.test('cleaning URI-based attributes', function(assert) { @@ -1121,41 +1123,41 @@ QUnit.test('cleaning URI-based attributes', function(assert) { input = 'x'; output = 'x'; - test_minify_sync(assert, input, output); + test_minify(assert, input, output); input = 'x'; output = 'x'; - test_minify_sync(assert, input, output); + test_minify(assert, input, output); input = ''; output = ''; - test_minify_sync(assert, input, output); + test_minify(assert, input, output); input = ''; output = ''; - test_minify_sync(assert, input, output); + test_minify(assert, input, output); input = '
    '; output = '
    '; - test_minify_sync(assert, input, output); + test_minify(assert, input, output); input = '

    foobar

    '; output = '

    foobar

    '; - test_minify_sync(assert, input, output); + test_minify(assert, input, output); input = ''; output = ''; - test_minify_sync(assert, input, output); + test_minify(assert, input, output); input = ''; output = ''; - test_minify_sync(assert, input, output); + test_minify(assert, input, output); input = 'foo'; - test_minify_sync(assert, input, input); + test_minify(assert, input, input); input = '
    blah
    '; - test_minify_sync(assert, input, input); + test_minify(assert, input, input); }); QUnit.test('cleaning Number-based attributes', function(assert) { @@ -1163,27 +1165,27 @@ QUnit.test('cleaning Number-based attributes', function(assert) { input = 'x'; output = 'x'; - test_minify_sync(assert, input, output); + test_minify(assert, input, output); input = ''; output = ''; - test_minify_sync(assert, input, output); + test_minify(assert, input, output); input = ''; output = ''; - test_minify_sync(assert, input, output); + test_minify(assert, input, output); input = ''; output = ''; - test_minify_sync(assert, input, output); + test_minify(assert, input, output); input = ''; output = ''; - test_minify_sync(assert, input, output); + test_minify(assert, input, output); input = 'x'; output = 'x'; - test_minify_sync(assert, input, output); + test_minify(assert, input, output); }); QUnit.test('cleaning other attributes', function(assert) { @@ -1191,50 +1193,50 @@ QUnit.test('cleaning other attributes', function(assert) { input = 'blah'; output = 'blah'; - test_minify_sync(assert, input, output); + test_minify(assert, input, output); input = '

    x'; output = '

    x

    '; - test_minify_sync(assert, input, output); + test_minify(assert, input, output); }); QUnit.test('removing redundant attributes (<form method="get" ...>)', function(assert) { var input; input = '
    hello world
    '; - test_minify_sync(assert, input, { removeRedundantAttributes: true }, '
    hello world
    '); + test_minify(assert, input, '
    hello world
    ', { removeRedundantAttributes: true }); input = '
    hello world
    '; - test_minify_sync(assert, input, { removeRedundantAttributes: true }, '
    hello world
    '); + test_minify(assert, input, '
    hello world
    ', { removeRedundantAttributes: true }); }); QUnit.test('removing redundant attributes (<input type="text" ...>)', function(assert) { var input; input = ''; - test_minify_sync(assert, input, { removeRedundantAttributes: true }, ''); + test_minify(assert, input, '', { removeRedundantAttributes: true }); input = ''; - test_minify_sync(assert, input, { removeRedundantAttributes: true }, ''); + test_minify(assert, input, '', { removeRedundantAttributes: true }); input = ''; - test_minify_sync(assert, input, { removeRedundantAttributes: true }, ''); + test_minify(assert, input, '', { removeRedundantAttributes: true }); }); QUnit.test('removing redundant attributes (<a name="..." id="..." ...>)', function(assert) { var input; input = 'blah'; - test_minify_sync(assert, input, { removeRedundantAttributes: true }, 'blah'); + test_minify(assert, input, 'blah', { removeRedundantAttributes: true }); input = ''; - test_minify_sync(assert, input, { removeRedundantAttributes: true }, input); + test_minify(assert, input, input, { removeRedundantAttributes: true }); input = 'blah'; - test_minify_sync(assert, input, { removeRedundantAttributes: true }, input); + test_minify(assert, input, input, { removeRedundantAttributes: true }); input = 'blah'; - test_minify_sync(assert, input, { removeRedundantAttributes: true }, 'blah'); + test_minify(assert, input, 'blah', { removeRedundantAttributes: true }); }); QUnit.test('removing redundant attributes (<script src="..." charset="...">)', function(assert) { @@ -1242,125 +1244,125 @@ QUnit.test('removing redundant attributes (<script src="..." charset="...">)' input = ''; output = ''; - test_minify_sync(assert, input, { removeRedundantAttributes: true }, output); + test_minify(assert, input, output, { removeRedundantAttributes: true }); input = ''; - test_minify_sync(assert, input, { removeRedundantAttributes: true }, input); + test_minify(assert, input, input, { removeRedundantAttributes: true }); input = ''; output = ''; - test_minify_sync(assert, input, { removeRedundantAttributes: true }, output); + test_minify(assert, input, output, { removeRedundantAttributes: true }); }); QUnit.test('removing redundant attributes (<... language="javascript" ...>)', function(assert) { var input; input = ''; - test_minify_sync(assert, input, { removeRedundantAttributes: true }, ''); + test_minify(assert, input, '', { removeRedundantAttributes: true }); input = ''; - test_minify_sync(assert, input, { removeRedundantAttributes: true }, ''); + test_minify(assert, input, '', { removeRedundantAttributes: true }); }); QUnit.test('removing redundant attributes (<area shape="rect" ...>)', function(assert) { var input = ''; var output = ''; - test_minify_sync(assert, input, { removeRedundantAttributes: true }, output); + test_minify(assert, input, output, { removeRedundantAttributes: true }); }); QUnit.test('removing redundant attributes (<... = "javascript: ..." ...>)', function(assert) { var input; input = '

    x

    '; - test_minify_sync(assert, input, '

    x

    '); + test_minify(assert, input, '

    x

    '); input = '

    x

    '; - test_minify_sync(assert, input, { removeAttributeQuotes: true }, '

    x

    '); + test_minify(assert, input, '

    x

    ', { removeAttributeQuotes: true }); input = '

    x

    '; - test_minify_sync(assert, input, '

    x

    '); + test_minify(assert, input, '

    x

    '); input = '

    x

    '; - test_minify_sync(assert, input, input); + test_minify(assert, input, input); }); QUnit.test('removing javascript type attributes', function(assert) { var input, output; input = ''; - test_minify_sync(assert, input, { removeScriptTypeAttributes: false }, input); + test_minify(assert, input, input, { removeScriptTypeAttributes: false }); output = ''; - test_minify_sync(assert, input, { removeScriptTypeAttributes: true }, output); + test_minify(assert, input, output, { removeScriptTypeAttributes: true }); input = ''; - test_minify_sync(assert, input, { removeScriptTypeAttributes: false }, input); + test_minify(assert, input, input, { removeScriptTypeAttributes: false }); output = ''; - test_minify_sync(assert, input, { removeScriptTypeAttributes: true }, output); + test_minify(assert, input, output, { removeScriptTypeAttributes: true }); input = ''; output = ''; - test_minify_sync(assert, input, { removeScriptTypeAttributes: true }, output); + test_minify(assert, input, output, { removeScriptTypeAttributes: true }); input = ''; output = ''; - test_minify_sync(assert, input, { removeScriptTypeAttributes: true }, output); + test_minify(assert, input, output, { removeScriptTypeAttributes: true }); input = ''; output = ''; - test_minify_sync(assert, input, { removeScriptTypeAttributes: true }, output); + test_minify(assert, input, output, { removeScriptTypeAttributes: true }); }); QUnit.test('removing type="text/css" attributes', function(assert) { var input, output; input = ''; - test_minify_sync(assert, input, { removeStyleLinkTypeAttributes: false }, input); + test_minify(assert, input, input, { removeStyleLinkTypeAttributes: false }); output = ''; - test_minify_sync(assert, input, { removeStyleLinkTypeAttributes: true }, output); + test_minify(assert, input, output, { removeStyleLinkTypeAttributes: true }); input = ''; - test_minify_sync(assert, input, { removeStyleLinkTypeAttributes: false }, input); + test_minify(assert, input, input, { removeStyleLinkTypeAttributes: false }); output = ''; - test_minify_sync(assert, input, { removeStyleLinkTypeAttributes: true }, output); + test_minify(assert, input, output, { removeStyleLinkTypeAttributes: true }); input = ''; output = ''; - test_minify_sync(assert, input, { removeStyleLinkTypeAttributes: true }, output); + test_minify(assert, input, output, { removeStyleLinkTypeAttributes: true }); input = ''; - test_minify_sync(assert, input, { removeStyleLinkTypeAttributes: true }, input); + test_minify(assert, input, input, { removeStyleLinkTypeAttributes: true }); input = ''; output = ''; - test_minify_sync(assert, input, { removeStyleLinkTypeAttributes: true }, output); + test_minify(assert, input, output, { removeStyleLinkTypeAttributes: true }); input = ''; - test_minify_sync(assert, input, { removeStyleLinkTypeAttributes: true }, input); + test_minify(assert, input, input, { removeStyleLinkTypeAttributes: true }); }); QUnit.test('removing attribute quotes', function(assert) { var input; input = '

    foo

    '; - test_minify_sync(assert, input, { removeAttributeQuotes: true }, '

    foo

    '); + test_minify(assert, input, '

    foo

    ', { removeAttributeQuotes: true }); input = ''; - test_minify_sync(assert, input, { removeAttributeQuotes: true }, ''); + test_minify(assert, input, '', { removeAttributeQuotes: true }); input = 'x'; - test_minify_sync(assert, input, { removeAttributeQuotes: true }, 'x'); + test_minify(assert, input, 'x', { removeAttributeQuotes: true }); input = '\nfoo\n\n'; - test_minify_sync(assert, input, { removeAttributeQuotes: true }, '\nfoo\n\n'); + test_minify(assert, input, '\nfoo\n\n', { removeAttributeQuotes: true }); input = '\nfoo\n\n'; - test_minify_sync(assert, input, { removeAttributeQuotes: true }, '\nfoo\n\n'); + test_minify(assert, input, '\nfoo\n\n', { removeAttributeQuotes: true }); input = '\nfoo\n\n'; - test_minify_sync(assert, input, { removeAttributeQuotes: true, removeEmptyAttributes: true }, '\nfoo\n\n'); + test_minify(assert, input, '\nfoo\n\n', { removeAttributeQuotes: true, removeEmptyAttributes: true }); input = '

    '; - test_minify_sync(assert, input, { removeAttributeQuotes: true }, '

    '); + test_minify(assert, input, '

    ', { removeAttributeQuotes: true }); }); QUnit.test('preserving custom attribute-wrapping markup', function(assert) { @@ -1372,10 +1374,10 @@ QUnit.test('preserving custom attribute-wrapping markup', function(assert) { }; input = ''; - test_minify_sync(assert, input, customAttrOptions, input); + test_minify(assert, input, input, customAttrOptions); input = ''; - test_minify_sync(assert, input, customAttrOptions, input); + test_minify(assert, input, input, customAttrOptions); // With multiple rules customAttrOptions = { @@ -1386,16 +1388,16 @@ QUnit.test('preserving custom attribute-wrapping markup', function(assert) { }; input = ''; - test_minify_sync(assert, input, customAttrOptions, input); + test_minify(assert, input, input, customAttrOptions); input = ''; - test_minify_sync(assert, input, customAttrOptions, input); + test_minify(assert, input, input, customAttrOptions); input = ''; - test_minify_sync(assert, input, customAttrOptions, input); + test_minify(assert, input, input, customAttrOptions); input = ''; - test_minify_sync(assert, input, customAttrOptions, input); + test_minify(assert, input, input, customAttrOptions); // With multiple rules and richer options customAttrOptions = { @@ -1408,13 +1410,13 @@ QUnit.test('preserving custom attribute-wrapping markup', function(assert) { }; input = ''; - test_minify_sync(assert, input, customAttrOptions, ''); + test_minify(assert, input, '', customAttrOptions); input = ''; - test_minify_sync(assert, input, customAttrOptions, ''); + test_minify(assert, input, '', customAttrOptions); customAttrOptions.keepClosingSlash = true; - test_minify_sync(assert, input, customAttrOptions, ''); + test_minify(assert, input, '', customAttrOptions); }); QUnit.test('preserving custom attribute-joining markup', function(assert) { @@ -1424,9 +1426,9 @@ QUnit.test('preserving custom attribute-joining markup', function(assert) { customAttrAssign: [polymerConditionalAttributeJoin] }; input = '
    '; - test_minify_sync(assert, input, customAttrOptions, input); + test_minify(assert, input, input, customAttrOptions); input = '
    '; - test_minify_sync(assert, input, customAttrOptions, input); + test_minify(assert, input, input, customAttrOptions); }); QUnit.test('collapsing whitespace', function(assert) { @@ -1434,37 +1436,37 @@ QUnit.test('collapsing whitespace', function(assert) { input = ''; output = ''; - test_minify_sync(assert, input, { collapseWhitespace: true }, output); + test_minify(assert, input, output, { collapseWhitespace: true }); input = '

    foo

    bar

    \n\n \n\t\t
    baz
    '; output = '

    foo

    bar

    baz
    '; - test_minify_sync(assert, input, { collapseWhitespace: true }, output); + test_minify(assert, input, output, { collapseWhitespace: true }); input = '

    foo bar

    '; output = '

    foo bar

    '; - test_minify_sync(assert, input, { collapseWhitespace: true }, output); + test_minify(assert, input, output, { collapseWhitespace: true }); input = '

    foo\nbar

    '; output = '

    foo bar

    '; - test_minify_sync(assert, input, { collapseWhitespace: true }, output); + test_minify(assert, input, output, { collapseWhitespace: true }); input = '

    foo blah 22 bar

    '; output = '

    foo blah 22 bar

    '; - test_minify_sync(assert, input, { collapseWhitespace: true }, output); + test_minify(assert, input, output, { collapseWhitespace: true }); input = ''; output = ''; - test_minify_sync(assert, input, { collapseWhitespace: true }, output); + test_minify(assert, input, output, { collapseWhitespace: true }); input = '
    '; output = '
    '; - test_minify_sync(assert, input, { collapseWhitespace: true }, output); + test_minify(assert, input, output, { collapseWhitespace: true }); input = '
     $foo = "baz"; 
    '; output = '
     $foo = "baz"; 
    '; - test_minify_sync(assert, input, { collapseWhitespace: true }, output); + test_minify(assert, input, output, { collapseWhitespace: true }); output = '
    $foo = "baz";
    '; - test_minify_sync(assert, input, { collapseWhitespace: true, caseSensitive: true }, output); + test_minify(assert, input, output, { collapseWhitespace: true, caseSensitive: true }); input = '\r\n\r\n\r\n' + '\r\n\r\n\r\n' + @@ -1482,153 +1484,153 @@ QUnit.test('collapsing whitespace', function(assert) { '' + '
           \r\nxxxx
    x Hello billy ' + '
    ';
    -  test_minify_sync(assert, input, { collapseWhitespace: true }, output);
    +  test_minify(assert, input, output, { collapseWhitespace: true });
     
       input = '
       hello     world 
    '; output = '
       hello     world 
    '; - test_minify_sync(assert, input, { collapseWhitespace: true }, output); + test_minify(assert, input, output, { collapseWhitespace: true }); input = '
       hello     world 
    '; output = '
       hello     world 
    '; - test_minify_sync(assert, input, { collapseWhitespace: true }, output); + test_minify(assert, input, output, { collapseWhitespace: true }); input = ''; output = ''; - test_minify_sync(assert, input, { collapseWhitespace: true }, output); + test_minify(assert, input, output, { collapseWhitespace: true }); input = ''; output = ''; - test_minify_sync(assert, input, { collapseWhitespace: true }, output); + test_minify(assert, input, output, { collapseWhitespace: true }); }); QUnit.test('removing empty elements', function(assert) { var input, output; - test_minify_sync(assert, '

    x

    ', { removeEmptyElements: true }, '

    x

    '); - test_minify_sync(assert, '

    ', { removeEmptyElements: true }, ''); + test_minify(assert, '

    x

    ', '

    x

    ', { removeEmptyElements: true }); + test_minify(assert, '

    ', '', { removeEmptyElements: true }); input = '

    foobar

    '; output = '

    foobar

    '; - test_minify_sync(assert, input, { removeEmptyElements: true }, output); + test_minify(assert, input, output, { removeEmptyElements: true }); input = ''; output = ''; - test_minify_sync(assert, input, { removeEmptyElements: true }, output); + test_minify(assert, input, output, { removeEmptyElements: true }); input = ''; output = ''; - test_minify_sync(assert, input, { removeEmptyElements: true }, output); + test_minify(assert, input, output, { removeEmptyElements: true }); input = ''; - test_minify_sync(assert, input, { removeEmptyElements: true }, input); + test_minify(assert, input, input, { removeEmptyElements: true }); input = ''; - test_minify_sync(assert, input, { removeEmptyElements: true }, input); + test_minify(assert, input, input, { removeEmptyElements: true }); input = ''; output = ''; - test_minify_sync(assert, input, { removeEmptyElements: true }, output); + test_minify(assert, input, output, { removeEmptyElements: true }); input = ''; - test_minify_sync(assert, input, { removeEmptyElements: true }, input); + test_minify(assert, input, input, { removeEmptyElements: true }); input = ''; output = ''; - test_minify_sync(assert, input, { removeEmptyElements: true }, output); + test_minify(assert, input, output, { removeEmptyElements: true }); input = ''; - test_minify_sync(assert, input, { removeEmptyElements: true }, input); + test_minify(assert, input, input, { removeEmptyElements: true }); input = ''; output = ''; - test_minify_sync(assert, input, { removeEmptyElements: true }, output); + test_minify(assert, input, output, { removeEmptyElements: true }); input = ''; - test_minify_sync(assert, input, { removeEmptyElements: true }, input); + test_minify(assert, input, input, { removeEmptyElements: true }); input = ''; output = ''; - test_minify_sync(assert, input, { removeEmptyElements: true }, output); + test_minify(assert, input, output, { removeEmptyElements: true }); input = ''; - test_minify_sync(assert, input, { removeEmptyElements: true }, input); + test_minify(assert, input, input, { removeEmptyElements: true }); input = ''; - test_minify_sync(assert, input, { removeEmptyElements: true }, input); + test_minify(assert, input, input, { removeEmptyElements: true }); input = '
    helloworld
    '; - test_minify_sync(assert, input, { removeEmptyElements: true }, input); + test_minify(assert, input, input, { removeEmptyElements: true }); input = '

    x

    '; output = '

    x

    '; - test_minify_sync(assert, input, { removeEmptyElements: true }, output); + test_minify(assert, input, output, { removeEmptyElements: true }); input = '
    x
    y
    blah
    foo
    z
    '; output = '
    x
    y
    blah
    foo
    z
    '; - test_minify_sync(assert, input, { removeEmptyElements: true }, output); + test_minify(assert, input, output, { removeEmptyElements: true }); input = ''; - test_minify_sync(assert, input, { removeEmptyElements: true }, input); + test_minify(assert, input, input, { removeEmptyElements: true }); input = '

    '; output = ''; - test_minify_sync(assert, input, { removeEmptyElements: true }, output); + test_minify(assert, input, output, { removeEmptyElements: true }); input = ''; - test_minify_sync(assert, input, { removeEmptyElements: true }, input); + test_minify(assert, input, input, { removeEmptyElements: true }); input = ''; - test_minify_sync(assert, input, { removeEmptyElements: true }, ''); + test_minify(assert, input, '', { removeEmptyElements: true }); input = '
    after
    '; output = '
    after
    '; - test_minify_sync(assert, input, { removeEmptyElements: true }, output); + test_minify(assert, input, output, { removeEmptyElements: true }); output = '
    after
    '; - test_minify_sync(assert, input, { collapseWhitespace: true, removeEmptyElements: true }, output); + test_minify(assert, input, output, { collapseWhitespace: true, removeEmptyElements: true }); input = '
    before
    '; output = '
    before
    '; - test_minify_sync(assert, input, { removeEmptyElements: true }, output); + test_minify(assert, input, output, { removeEmptyElements: true }); output = '
    before
    '; - test_minify_sync(assert, input, { collapseWhitespace: true, removeEmptyElements: true }, output); + test_minify(assert, input, output, { collapseWhitespace: true, removeEmptyElements: true }); input = '
    both
    '; output = '
    both
    '; - test_minify_sync(assert, input, { removeEmptyElements: true }, output); + test_minify(assert, input, output, { removeEmptyElements: true }); output = '
    both
    '; - test_minify_sync(assert, input, { collapseWhitespace: true, removeEmptyElements: true }, output); + test_minify(assert, input, output, { collapseWhitespace: true, removeEmptyElements: true }); input = '
    unary
    '; output = '
    unary
    '; - test_minify_sync(assert, input, { removeEmptyElements: true }, output); + test_minify(assert, input, output, { removeEmptyElements: true }); output = '
    unary
    '; - test_minify_sync(assert, input, { collapseWhitespace: true, removeEmptyElements: true }, output); + test_minify(assert, input, output, { collapseWhitespace: true, removeEmptyElements: true }); input = '
    Empty
    '; - test_minify_sync(assert, input, { removeEmptyElements: true }, input); + test_minify(assert, input, input, { removeEmptyElements: true }); output = '
    Empty
    '; - test_minify_sync(assert, input, { collapseWhitespace: true, removeEmptyElements: true }, output); + test_minify(assert, input, output, { collapseWhitespace: true, removeEmptyElements: true }); }); QUnit.test('collapsing boolean attributes', function(assert) { var input, output; input = ''; - test_minify_sync(assert, input, { collapseBooleanAttributes: true }, ''); + test_minify(assert, input, '', { collapseBooleanAttributes: true }); input = ''; - test_minify_sync(assert, input, { collapseBooleanAttributes: true }, ''); + test_minify(assert, input, '', { collapseBooleanAttributes: true }); input = ''; - test_minify_sync(assert, input, { collapseBooleanAttributes: true }, ''); + test_minify(assert, input, '', { collapseBooleanAttributes: true }); input = ''; - test_minify_sync(assert, input, { collapseBooleanAttributes: true }, ''); + test_minify(assert, input, '', { collapseBooleanAttributes: true }); input = ''; - test_minify_sync(assert, input, { collapseBooleanAttributes: true }, ''); + test_minify(assert, input, '', { collapseBooleanAttributes: true }); input = ''; - test_minify_sync(assert, input, { collapseBooleanAttributes: true }, ''); + test_minify(assert, input, '', { collapseBooleanAttributes: true }); input = ''; - test_minify_sync(assert, input, { collapseBooleanAttributes: true }, output); + test_minify(assert, input, output, { collapseBooleanAttributes: true }); output = ''; - test_minify_sync(assert, input, { collapseBooleanAttributes: true, caseSensitive: true }, output); + test_minify(assert, input, output, { collapseBooleanAttributes: true, caseSensitive: true }); }); QUnit.test('collapsing enumerated attributes', function(assert) { - test_minify_sync(assert, '
    ', { collapseBooleanAttributes: true }, '
    '); - test_minify_sync(assert, '
    ', { collapseBooleanAttributes: true }, '
    '); - test_minify_sync(assert, '
    ', { collapseBooleanAttributes: true }, '
    '); - test_minify_sync(assert, '
    ', { collapseBooleanAttributes: true }, '
    '); - test_minify_sync(assert, '
    ', { collapseBooleanAttributes: true }, '
    '); - test_minify_sync(assert, '
    ', { collapseBooleanAttributes: true }, '
    '); - test_minify_sync(assert, '
    ', { collapseBooleanAttributes: true }, '
    '); - test_minify_sync(assert, '
    ', { collapseBooleanAttributes: true }, '
    '); - test_minify_sync(assert, '
    ', { collapseBooleanAttributes: true }, '
    '); - test_minify_sync(assert, '
    ', { collapseBooleanAttributes: true }, '
    '); - test_minify_sync(assert, '
    ', { collapseBooleanAttributes: true }, '
    '); + test_minify(assert, '
    ', '
    ', { collapseBooleanAttributes: true }); + test_minify(assert, '
    ', '
    ', { collapseBooleanAttributes: true }); + test_minify(assert, '
    ', '
    ', { collapseBooleanAttributes: true }); + test_minify(assert, '
    ', '
    ', { collapseBooleanAttributes: true }); + test_minify(assert, '
    ', '
    ', { collapseBooleanAttributes: true }); + test_minify(assert, '
    ', '
    ', { collapseBooleanAttributes: true }); + test_minify(assert, '
    ', '
    ', { collapseBooleanAttributes: true }); + test_minify(assert, '
    ', '
    ', { collapseBooleanAttributes: true }); + test_minify(assert, '
    ', '
    ', { collapseBooleanAttributes: true }); + test_minify(assert, '
    ', '
    ', { collapseBooleanAttributes: true }); + test_minify(assert, '
    ', '
    ', { collapseBooleanAttributes: true }); }); QUnit.test('keeping trailing slashes in tags', function(assert) { - test_minify_sync(assert, '', { keepClosingSlash: true }, ''); + test_minify(assert, '', '', { keepClosingSlash: true }); // https://github.com/kangax/html-minifier/issues/233 - test_minify_sync(assert, '', { keepClosingSlash: true, removeAttributeQuotes: true }, ''); - test_minify_sync(assert, '', { keepClosingSlash: true, removeAttributeQuotes: true, removeEmptyAttributes: true }, ''); - test_minify_sync(assert, '', { keepClosingSlash: true, removeAttributeQuotes: true }, ''); + test_minify(assert, '', '', { keepClosingSlash: true, removeAttributeQuotes: true }); + test_minify(assert, '', '', { keepClosingSlash: true, removeAttributeQuotes: true, removeEmptyAttributes: true }); + test_minify(assert, '', '', { keepClosingSlash: true, removeAttributeQuotes: true }); }); QUnit.test('removing optional tags', function(assert) { var input, output; input = '

    foo'; - test_minify_sync(assert, input, { removeOptionalTags: true }, input); + test_minify(assert, input, input, { removeOptionalTags: true }); input = '

    '; output = '

    '; - test_minify_sync(assert, input, { removeOptionalTags: true }, output); + test_minify(assert, input, output, { removeOptionalTags: true }); input = ''; output = ''; - test_minify_sync(assert, input, { removeOptionalTags: true }, output); - test_minify_sync(assert, input, { removeOptionalTags: true, removeEmptyElements: true }, output); + test_minify(assert, input, output, { removeOptionalTags: true }); + test_minify(assert, input, output, { removeOptionalTags: true, removeEmptyElements: true }); input = ''; output = ''; - test_minify_sync(assert, input, { removeOptionalTags: true }, output); - test_minify_sync(assert, input, { removeOptionalTags: true, removeEmptyElements: true }, output); + test_minify(assert, input, output, { removeOptionalTags: true }); + test_minify(assert, input, output, { removeOptionalTags: true, removeEmptyElements: true }); input = ' '; output = ' '; - test_minify_sync(assert, input, { removeOptionalTags: true }, output); + test_minify(assert, input, output, { removeOptionalTags: true }); output = ''; - test_minify_sync(assert, input, { collapseWhitespace: true, removeOptionalTags: true }, output); + test_minify(assert, input, output, { collapseWhitespace: true, removeOptionalTags: true }); input = ' '; output = ' '; - test_minify_sync(assert, input, { removeOptionalTags: true }, output); + test_minify(assert, input, output, { removeOptionalTags: true }); output = ''; - test_minify_sync(assert, input, { collapseWhitespace: true, removeOptionalTags: true }, output); + test_minify(assert, input, output, { collapseWhitespace: true, removeOptionalTags: true }); input = ' '; output = ' '; - test_minify_sync(assert, input, { removeOptionalTags: true }, output); + test_minify(assert, input, output, { removeOptionalTags: true }); output = ''; - test_minify_sync(assert, input, { collapseWhitespace: true, removeOptionalTags: true }, output); + test_minify(assert, input, output, { collapseWhitespace: true, removeOptionalTags: true }); input = ' '; output = ' '; - test_minify_sync(assert, input, { removeOptionalTags: true }, output); + test_minify(assert, input, output, { removeOptionalTags: true }); output = ''; - test_minify_sync(assert, input, { collapseWhitespace: true, removeOptionalTags: true }, output); + test_minify(assert, input, output, { collapseWhitespace: true, removeOptionalTags: true }); input = ' '; output = ' '; - test_minify_sync(assert, input, { removeOptionalTags: true }, output); + test_minify(assert, input, output, { removeOptionalTags: true }); output = ''; - test_minify_sync(assert, input, { collapseWhitespace: true, removeOptionalTags: true }, output); + test_minify(assert, input, output, { collapseWhitespace: true, removeOptionalTags: true }); input = ' '; output = ' '; - test_minify_sync(assert, input, { removeOptionalTags: true }, output); + test_minify(assert, input, output, { removeOptionalTags: true }); output = ''; - test_minify_sync(assert, input, { collapseWhitespace: true, removeOptionalTags: true }, output); + test_minify(assert, input, output, { collapseWhitespace: true, removeOptionalTags: true }); input = ' '; output = ' '; - test_minify_sync(assert, input, { removeOptionalTags: true }, output); + test_minify(assert, input, output, { removeOptionalTags: true }); output = ''; - test_minify_sync(assert, input, { collapseWhitespace: true, removeOptionalTags: true }, output); + test_minify(assert, input, output, { collapseWhitespace: true, removeOptionalTags: true }); input = ' '; output = ' '; - test_minify_sync(assert, input, { removeOptionalTags: true }, output); + test_minify(assert, input, output, { removeOptionalTags: true }); output = ''; - test_minify_sync(assert, input, { collapseWhitespace: true, removeOptionalTags: true }, output); + test_minify(assert, input, output, { collapseWhitespace: true, removeOptionalTags: true }); input = 'hello

    foobar

    '; - test_minify_sync(assert, input, input); + test_minify(assert, input, input); output = 'hello

    foobar'; - test_minify_sync(assert, input, { removeOptionalTags: true }, output); + test_minify(assert, input, output, { removeOptionalTags: true }); input = 'hello

    foobar

    '; output = 'hello

    foobar'; - test_minify_sync(assert, input, { removeOptionalTags: true }, output); + test_minify(assert, input, output, { removeOptionalTags: true }); output = 'hello

    foobar'; - test_minify_sync(assert, input, { removeOptionalTags: true, removeEmptyAttributes: true }, output); + test_minify(assert, input, output, { removeOptionalTags: true, removeEmptyAttributes: true }); input = 'a

    '; output = 'a
    '; - test_minify_sync(assert, input, { removeOptionalTags: true }, output); + test_minify(assert, input, output, { removeOptionalTags: true }); input = 'Blah

    This is some text in a div

    Followed by some details

    This is some more text in a div

    '; output = 'Blah

    This is some text in a div

    Followed by some details

    This is some more text in a div

    '; - test_minify_sync(assert, input, { removeOptionalTags: true }, output); + test_minify(assert, input, output, { removeOptionalTags: true }); input = 'Blah'; output = 'Blah'; - test_minify_sync(assert, input, { removeOptionalTags: true }, output); + test_minify(assert, input, output, { removeOptionalTags: true }); input = '

    Configure

    '; - test_minify_sync(assert, input, { removeOptionalTags: true }, input); + test_minify(assert, input, input, { removeOptionalTags: true }); }); QUnit.test('removing optional tags in tables', function(assert) { @@ -1773,22 +1775,22 @@ QUnit.test('removing optional tags in tables', function(assert) { 'boomooloo ' + 'baz quxboo' + ''; - test_minify_sync(assert, input, input); + test_minify(assert, input, input); output = '' + ' ' + ' ' + '
    foobar baz
    boomooloo
    baz quxboo' + '
    '; - test_minify_sync(assert, input, { removeOptionalTags: true }, output); + test_minify(assert, input, output, { removeOptionalTags: true }); output = '' + '
    foobarbaz' + '
    boomooloo' + '
    bazquxboo' + '
    '; - test_minify_sync(assert, input, { collapseWhitespace: true, removeOptionalTags: true }, output); - test_minify_sync(assert, output, { collapseWhitespace: true, removeOptionalTags: true }, output); + test_minify(assert, input, output, { collapseWhitespace: true, removeOptionalTags: true }); + test_minify(assert, output, output, { collapseWhitespace: true, removeOptionalTags: true }); input = '' + '' + @@ -1797,7 +1799,7 @@ QUnit.test('removing optional tags in tables', function(assert) { '' + '' + '
    foo
    barbazqux
    '; - test_minify_sync(assert, input, input); + test_minify(assert, input, input); output = '' + '' + @@ -1806,23 +1808,23 @@ QUnit.test('removing optional tags in tables', function(assert) { '' + '
    foo
    barbazqux' + '
    '; - test_minify_sync(assert, input, { removeOptionalTags: true }, output); - test_minify_sync(assert, output, { removeOptionalTags: true }, output); + test_minify(assert, input, output, { removeOptionalTags: true }); + test_minify(assert, output, output, { removeOptionalTags: true }); output = '' + '' + '
    foo' + '
    barbazqux' + '
    '; - test_minify_sync(assert, input, { removeComments: true, removeOptionalTags: true }, output); + test_minify(assert, input, output, { removeComments: true, removeOptionalTags: true }); input = '' + '' + '
    '; - test_minify_sync(assert, input, input); + test_minify(assert, input, input); output = '
    '; - test_minify_sync(assert, input, { removeOptionalTags: true }, output); + test_minify(assert, input, output, { removeOptionalTags: true }); }); QUnit.test('removing optional tags in options', function(assert) { @@ -1830,17 +1832,17 @@ QUnit.test('removing optional tags in options', function(assert) { input = ''; output = ''; - test_minify_sync(assert, input, { removeOptionalTags: true }, output); + test_minify(assert, input, output, { removeOptionalTags: true }); input = ''; - test_minify_sync(assert, input, { removeOptionalTags: true }, input); + test_minify(assert, input, input, { removeOptionalTags: true }); output = ''; - test_minify_sync(assert, input, { removeOptionalTags: true, collapseWhitespace: true }, output); + test_minify(assert, input, output, { removeOptionalTags: true, collapseWhitespace: true }); output = ''; - test_minify_sync(assert, input, { removeOptionalTags: true, collapseWhitespace: true, conservativeCollapse: true }, output); + test_minify(assert, input, output, { removeOptionalTags: true, collapseWhitespace: true, conservativeCollapse: true }); // example from htmldog.com input = ''; - test_minify_sync(assert, input, { removeOptionalTags: true }, output); + test_minify(assert, input, output, { removeOptionalTags: true }); }); QUnit.test('custom components', function(assert) { var input = 'Oh, my.'; var output = 'Oh, my.'; - test_minify_sync(assert, input, output); + test_minify(assert, input, output); }); QUnit.test('HTML4: anchor with inline elements', function(assert) { var input = 'Well, look at me! I\'m a span!'; - test_minify_sync(assert, input, { html5: false }, input); + test_minify(assert, input, input, { html5: false }); }); QUnit.test('HTML5: anchor with inline elements', function(assert) { var input = 'Well, look at me! I\'m a span!'; - test_minify_sync(assert, input, { html5: true }, input); + test_minify(assert, input, input, { html5: true }); }); QUnit.test('HTML4: anchor with block elements', function(assert) { var input = '
    Well, look at me! I\'m a div!
    '; var output = '
    Well, look at me! I\'m a div!
    '; - test_minify_sync(assert, input, { html5: false }, output); + test_minify(assert, input, output, { html5: false }); }); QUnit.test('HTML5: anchor with block elements', function(assert) { var input = '
    Well, look at me! I\'m a div!
    '; var output = '
    Well, look at me! I\'m a div!
    '; - test_minify_sync(assert, input, { html5: true }, output); + test_minify(assert, input, output, { html5: true }); }); QUnit.test('HTML5: enabled by default', function(assert) { var input = '
    Well, look at me! I\'m a div!
    '; - test_minify_sync(assert, input, { html5: true }, minify(input)); + test_minify(assert, input, minify(input), { html5: true }); }); QUnit.test('phrasing content', function(assert) { @@ -1900,12 +1902,12 @@ QUnit.test('phrasing content', function(assert) { input = '

    a

    b
    '; output = '

    a

    b
    '; - test_minify_sync(assert, input, { html5: true }, output); + test_minify(assert, input, output, { html5: true }); output = '

    a

    b

    '; - test_minify_sync(assert, input, { html5: false }, output); + test_minify(assert, input, output, { html5: false }); input = ''; - test_minify_sync(assert, input, { html5: true }, input); + test_minify(assert, input, input, { html5: true }); }); // https://github.com/kangax/html-minifier/issues/888 @@ -1914,29 +1916,29 @@ QUnit.test('ul/ol should be phrasing content', function(assert) { input = '

    a

    • item
    '; output = '

    a

    • item
    '; - test_minify_sync(assert, input, { html5: true }, output); + test_minify(assert, input, output, { html5: true }); output = '

    a

    • item
    '; - test_minify_sync(assert, input, { html5: true, removeOptionalTags: true }, output); + test_minify(assert, input, output, { html5: true, removeOptionalTags: true }); output = '

    a

    • item

    '; - test_minify_sync(assert, input, { html5: false }, output); + test_minify(assert, input, output, { html5: false }); input = '

    a

    1. item

    '; output = '

    a

    1. item

    '; - test_minify_sync(assert, input, { html5: true }, output); + test_minify(assert, input, output, { html5: true }); output = '

    a

    1. item

    '; - test_minify_sync(assert, input, { html5: true, removeOptionalTags: true }, output); + test_minify(assert, input, output, { html5: true, removeOptionalTags: true }); output = '

    a

    1. item
    '; - test_minify_sync(assert, input, { html5: true, removeEmptyElements: true }, output); + test_minify(assert, input, output, { html5: true, removeEmptyElements: true }); }); QUnit.test('phrasing content with Web Components', function(assert) { var input = ''; var output = ''; - test_minify_sync(assert, input, { html5: true }, output); + test_minify(assert, input, output, { html5: true }); }); // https://github.com/kangax/html-minifier/issues/10 @@ -1946,52 +1948,52 @@ QUnit.test('Ignore custom fragments', function(assert) { input = 'This is the start. <% ... %>\r\n<%= ... %>\r\n\r\n\r\nNo comment, but middle.\r\n{{ ... }}\r\n\r\n\r\nHello, this is the end!'; output = 'This is the start. <% ... %> <%= ... %> No comment, but middle. {{ ... }} Hello, this is the end!'; - test_minify_sync(assert, input, {}, input); - test_minify_sync(assert, input, { removeComments: true, collapseWhitespace: true }, output); - test_minify_sync(assert, input, { + test_minify(assert, input, input, {}); + test_minify(assert, input, output, { removeComments: true, collapseWhitespace: true }); + test_minify(assert, input, output, { removeComments: true, collapseWhitespace: true, ignoreCustomFragments: reFragments - }, output); + }); output = 'This is the start. <% ... %>\n<%= ... %>\n\nNo comment, but middle. {{ ... }}\n\n\nHello, this is the end!'; - test_minify_sync(assert, input, { + test_minify(assert, input, output, { removeComments: true, collapseWhitespace: true, preserveLineBreaks: true - }, output); + }); output = 'This is the start. <% ... %>\n<%= ... %>\n\nNo comment, but middle.\n{{ ... }}\n\n\nHello, this is the end!'; - test_minify_sync(assert, input, { + test_minify(assert, input, output, { removeComments: true, collapseWhitespace: true, preserveLineBreaks: true, ignoreCustomFragments: reFragments - }, output); + }); input = '{{ if foo? }}\r\n
    \r\n ...\r\n
    \r\n{{ end \n}}'; output = '{{ if foo? }}
    ...
    {{ end }}'; - test_minify_sync(assert, input, {}, input); - test_minify_sync(assert, input, { collapseWhitespace: true }, output); - test_minify_sync(assert, input, { collapseWhitespace: true, ignoreCustomFragments: [] }, output); + test_minify(assert, input, input, {}); + test_minify(assert, input, output, { collapseWhitespace: true }); + test_minify(assert, input, output, { collapseWhitespace: true, ignoreCustomFragments: [] }); output = '{{ if foo? }}
    ...
    {{ end \n}}'; - test_minify_sync(assert, input, { collapseWhitespace: true, ignoreCustomFragments: reFragments }, output); + test_minify(assert, input, output, { collapseWhitespace: true, ignoreCustomFragments: reFragments }); output = '{{ if foo? }}\n
    \n...\n
    \n{{ end \n}}'; - test_minify_sync(assert, input, { + test_minify(assert, input, output, { collapseWhitespace: true, preserveLineBreaks: true, ignoreCustomFragments: reFragments - }, output); + }); input = ''; - test_minify_sync(assert, input, {}, input); - test_minify_sync(assert, input, { ignoreCustomFragments: reFragments }, input); + test_minify(assert, input, input, {}); + test_minify(assert, input, input, { ignoreCustomFragments: reFragments }); input = ''; output = ''; - test_minify_sync(assert, input, { ignoreCustomFragments: [/\{%[^%]*?%\}/g] }, output); + test_minify(assert, input, output, { ignoreCustomFragments: [/\{%[^%]*?%\}/g] }); input = '' + '{{ form.name.label_tag }}' + @@ -2003,13 +2005,13 @@ QUnit.test('Ignore custom fragments', function(assert) { '{% endfor %}' + '{% endif %}' + '

    '; - test_minify_sync(assert, input, { + test_minify(assert, input, input, { ignoreCustomFragments: [ /\{%[\s\S]*?%\}/g, /\{\{[\s\S]*?\}\}/g ], quoteCharacter: '\'' - }, input); + }); output = '

    ' + '{{ form.name.label_tag }}' + '{{ form.name }}' + @@ -2020,151 +2022,151 @@ QUnit.test('Ignore custom fragments', function(assert) { '{% endfor %}' + '{% endif %}' + '

    '; - test_minify_sync(assert, input, { + test_minify(assert, input, output, { ignoreCustomFragments: [ /\{%[\s\S]*?%\}/g, /\{\{[\s\S]*?\}\}/g ], quoteCharacter: '\'', collapseWhitespace: true - }, output); + }); input = '>Legal Notices'; - test_minify_sync(assert, input, { + test_minify(assert, input, input, { ignoreCustomFragments: [ /<\?php[\s\S]*?\?>/g ] - }, input); + }); input = '>'; - test_minify_sync(assert, input, { + test_minify(assert, input, input, { ignoreCustomFragments: [ /<%=[\s\S]*?%>/g ] - }, input); + }); input = ''; - test_minify_sync(assert, input, { + test_minify(assert, input, input, { ignoreCustomFragments: [ /\{\{[\s\S]*?\}\}/g ], caseSensitive: true - }, input); + }); input = ''; - test_minify_sync(assert, input, { + test_minify(assert, input, input, { ignoreCustomFragments: [ /\{%[^%]*?%\}/g ] - }, input); + }); // trimCustomFragments withOUT collapseWhitespace, does // not break the "{% foo %} {% bar %}" test - test_minify_sync(assert, input, { + test_minify(assert, input, input, { ignoreCustomFragments: [ /\{%[^%]*?%\}/g ], trimCustomFragments: true - }, input); + }); // trimCustomFragments WITH collapseWhitespace, changes output output = ''; - test_minify_sync(assert, input, { + test_minify(assert, input, output, { ignoreCustomFragments: [ /\{%[^%]*?%\}/g ], collapseWhitespace: true, trimCustomFragments: true - }, output); + }); input = ''; - test_minify_sync(assert, input, input); - test_minify_sync(assert, input, { + test_minify(assert, input, input); + test_minify(assert, input, input, { collapseWhitespace: true - }, input); + }); input = '
    '; - test_minify_sync(assert, input, input); - test_minify_sync(assert, input, { + test_minify(assert, input, input); + test_minify(assert, input, input, { collapseWhitespace: true - }, input); + }); input = '{{if a}}
    b
    {{/if}}'; - test_minify_sync(assert, input, input); + test_minify(assert, input, input); output = '{{if a}}
    b
    {{/if}}'; - test_minify_sync(assert, input, { + test_minify(assert, input, output, { removeComments: true, ignoreCustomFragments: [ /\{\{.*?\}\}/g ] - }, output); + }); // https://github.com/kangax/html-minifier/issues/722 input = ' bar'; - test_minify_sync(assert, input, input); - test_minify_sync(assert, input, { + test_minify(assert, input, input); + test_minify(assert, input, input, { collapseWhitespace: true - }, input); + }); output = 'bar'; - test_minify_sync(assert, input, { + test_minify(assert, input, output, { collapseWhitespace: true, trimCustomFragments: true - }, output); + }); input = ' bar'; - test_minify_sync(assert, input, input); + test_minify(assert, input, input); output = ' bar'; - test_minify_sync(assert, input, { + test_minify(assert, input, output, { collapseWhitespace: true - }, output); + }); output = 'bar'; - test_minify_sync(assert, input, { + test_minify(assert, input, output, { collapseWhitespace: true, trimCustomFragments: true - }, output); + }); input = 'foo baz'; - test_minify_sync(assert, input, input); - test_minify_sync(assert, input, { + test_minify(assert, input, input); + test_minify(assert, input, input, { collapseWhitespace: true - }, input); + }); output = 'foobaz'; - test_minify_sync(assert, input, { + test_minify(assert, input, output, { collapseWhitespace: true, trimCustomFragments: true - }, output); + }); input = 'foo foo'; - test_minify_sync(assert, input, input); - test_minify_sync(assert, input, { + test_minify(assert, input, input); + test_minify(assert, input, input, { collapseWhitespace: true - }, input); + }); output = 'foofoo'; - test_minify_sync(assert, input, { + test_minify(assert, input, output, { collapseWhitespace: true, trimCustomFragments: true - }, output); + }); input = 'foo baz moo loo'; - test_minify_sync(assert, input, { + test_minify(assert, input, input, { collapseWhitespace: true, ignoreCustomFragments: [ /<(WC@[\s\S]*?)>(.*?)<\/\1>/ ] - }, input); + }); output = 'foobaz mooloo'; - test_minify_sync(assert, input, { + test_minify(assert, input, output, { collapseWhitespace: true - }, output); + }); input = ''; - test_minify_sync(assert, input, input); - test_minify_sync(assert, input, { removeAttributeQuotes: true }, input); + test_minify(assert, input, input); + test_minify(assert, input, input, { removeAttributeQuotes: true }); input = '
    \nfoo\n\nbaz\n
    '; - test_minify_sync(assert, input, input); - test_minify_sync(assert, input, { collapseWhitespace: true }, input); + test_minify(assert, input, input); + test_minify(assert, input, input, { collapseWhitespace: true }); }); QUnit.test('bootstrap\'s span > button > span', function(assert) { @@ -2174,15 +2176,15 @@ QUnit.test('bootstrap\'s span > button > span', function(assert) { '\n ' + ''; var output = ''; - test_minify_sync(assert, input, { collapseWhitespace: true, removeAttributeQuotes: true }, output); + test_minify(assert, input, output, { collapseWhitespace: true, removeAttributeQuotes: true }); }); QUnit.test('caseSensitive', function(assert) { var input = '
    '; var caseSensitiveOutput = '
    '; var caseInSensitiveOutput = '
    '; - test_minify_sync(assert, input, caseInSensitiveOutput); - test_minify_sync(assert, input, { caseSensitive: true }, caseSensitiveOutput); + test_minify(assert, input, caseInSensitiveOutput); + test_minify(assert, input, caseSensitiveOutput, { caseSensitive: true }); }); QUnit.test('source & track', function(assert) { @@ -2192,8 +2194,8 @@ QUnit.test('source & track', function(assert) { '' + '' + ''; - test_minify_sync(assert, input, input); - test_minify_sync(assert, input, { removeOptionalTags: true }, input); + test_minify(assert, input, input); + test_minify(assert, input, input, { removeOptionalTags: true }); }); QUnit.test('mixed html and svg', function(assert) { @@ -2218,18 +2220,18 @@ QUnit.test('mixed html and svg', function(assert) { '' + ''; // Should preserve case-sensitivity and closing slashes within svg tags - test_minify_sync(assert, input, { collapseWhitespace: true }, output); + test_minify(assert, input, output, { collapseWhitespace: true }); }); QUnit.test('nested quotes', function(assert) { var input, output; input = '
    '; - test_minify_sync(assert, input, input); - test_minify_sync(assert, input, { quoteCharacter: '\'' }, input); + test_minify(assert, input, input); + test_minify(assert, input, input, { quoteCharacter: '\'' }); output = '
    '; - test_minify_sync(assert, input, { quoteCharacter: '"' }, output); + test_minify(assert, input, output, { quoteCharacter: '"' }); }); QUnit.test('script minification', function(assert) { @@ -2237,32 +2239,32 @@ QUnit.test('script minification', function(assert) { input = '(function(){ var foo = 1; var bar = 2; alert(foo + " " + bar); })()'; - test_minify_sync(assert, input, { minifyJS: true }, input); + test_minify(assert, input, input, { minifyJS: true }); input = ''; output = ''; - test_minify_sync(assert, input, { minifyJS: true }, output); + test_minify(assert, input, output, { minifyJS: true }); input = ''; output = ''; - test_minify_sync(assert, input, { minifyJS: true }, output); + test_minify(assert, input, output, { minifyJS: true }); input = ''; output = ''; - test_minify_sync(assert, input, { minifyJS: true }, output); + test_minify(assert, input, output, { minifyJS: true }); input = ''; output = ''; - test_minify_sync(assert, input, { minifyJS: true }, output); + test_minify(assert, input, output, { minifyJS: true }); input = ''; output = ''; - test_minify_sync(assert, input, { minifyJS: { mangle: false } }, output); + test_minify(assert, input, output, { minifyJS: { mangle: false } }); input = ''; output = ''; - test_minify_sync(assert, input, { minifyJS: true }, output); + test_minify(assert, input, output, { minifyJS: true }); }); QUnit.test('minification of scripts with different mimetypes', function(assert) { @@ -2283,268 +2285,268 @@ QUnit.test('minification of scripts with different mimetypes', function(assert) input = ''; output = ''; - test_minify_sync(assert, input, { minifyJS: true }, output); + test_minify(assert, input, output, { minifyJS: true }); input = ''; output = ''; - test_minify_sync(assert, input, { minifyJS: true }, output); + test_minify(assert, input, output, { minifyJS: true }); input = ''; output = ''; - test_minify_sync(assert, input, { minifyJS: true }, output); + test_minify(assert, input, output, { minifyJS: true }); input = ''; output = ''; - test_minify_sync(assert, input, { minifyJS: true }, output); + test_minify(assert, input, output, { minifyJS: true }); input = ''; output = ''; - test_minify_sync(assert, input, { minifyJS: true }, output); + test_minify(assert, input, output, { minifyJS: true }); input = ''; - test_minify_sync(assert, input, { minifyJS: true }, input); + test_minify(assert, input, input, { minifyJS: true }); input = ''; - test_minify_sync(assert, input, { minifyJS: true }, input); + test_minify(assert, input, input, { minifyJS: true }); }); QUnit.test('minification of scripts with custom fragments', function(assert) { var input, output; input = ''; - test_minify_sync(assert, input, { minifyJS: true }, input); - test_minify_sync(assert, input, { collapseWhitespace: true, minifyJS: true }, input); - test_minify_sync(assert, input, { + test_minify(assert, input, input, { minifyJS: true }); + test_minify(assert, input, input, { collapseWhitespace: true, minifyJS: true }); + test_minify(assert, input, input, { collapseWhitespace: true, minifyJS: true, preserveLineBreaks: true - }, input); + }); input = ''; - test_minify_sync(assert, input, { minifyJS: true }, input); + test_minify(assert, input, input, { minifyJS: true }); output = ''; - test_minify_sync(assert, input, { collapseWhitespace: true, minifyJS: true }, output); - test_minify_sync(assert, input, { + test_minify(assert, input, output, { collapseWhitespace: true, minifyJS: true }); + test_minify(assert, input, input, { collapseWhitespace: true, minifyJS: true, preserveLineBreaks: true - }, input); + }); input = ''; - test_minify_sync(assert, input, { minifyJS: true }, input); + test_minify(assert, input, input, { minifyJS: true }); output = ''; - test_minify_sync(assert, input, { collapseWhitespace: true, minifyJS: true }, output); - test_minify_sync(assert, input, { + test_minify(assert, input, output, { collapseWhitespace: true, minifyJS: true }); + test_minify(assert, input, input, { collapseWhitespace: true, minifyJS: true, preserveLineBreaks: true - }, input); + }); input = ''; - test_minify_sync(assert, input, { minifyJS: true }, input); + test_minify(assert, input, input, { minifyJS: true }); output = ''; - test_minify_sync(assert, input, { collapseWhitespace: true, minifyJS: true }, output); - test_minify_sync(assert, input, { + test_minify(assert, input, output, { collapseWhitespace: true, minifyJS: true }); + test_minify(assert, input, input, { collapseWhitespace: true, minifyJS: true, preserveLineBreaks: true - }, input); + }); input = ''; output = ''; - test_minify_sync(assert, input, { minifyJS: true }, output); - test_minify_sync(assert, input, { collapseWhitespace: true, minifyJS: true }, output); - test_minify_sync(assert, input, { + test_minify(assert, input, output, { minifyJS: true }); + test_minify(assert, input, output, { collapseWhitespace: true, minifyJS: true }); + test_minify(assert, input, output, { collapseWhitespace: true, minifyJS: true, preserveLineBreaks: true - }, output); + }); input = ''; output = ''; - test_minify_sync(assert, input, { minifyJS: true }, output); + test_minify(assert, input, output, { minifyJS: true }); output = ''; - test_minify_sync(assert, input, { collapseWhitespace: true, minifyJS: true }, output); + test_minify(assert, input, output, { collapseWhitespace: true, minifyJS: true }); output = ''; - test_minify_sync(assert, input, { + test_minify(assert, input, output, { collapseWhitespace: true, minifyJS: true, preserveLineBreaks: true - }, output); + }); input = ''; output = ''; - test_minify_sync(assert, input, { minifyJS: true }, output); - test_minify_sync(assert, input, { collapseWhitespace: true, minifyJS: true }, output); - test_minify_sync(assert, input, { + test_minify(assert, input, output, { minifyJS: true }); + test_minify(assert, input, output, { collapseWhitespace: true, minifyJS: true }); + test_minify(assert, input, output, { collapseWhitespace: true, minifyJS: true, preserveLineBreaks: true - }, output); + }); input = ''; output = ''; - test_minify_sync(assert, input, { minifyJS: true }, output); + test_minify(assert, input, output, { minifyJS: true }); output = ''; - test_minify_sync(assert, input, { collapseWhitespace: true, minifyJS: true }, output); + test_minify(assert, input, output, { collapseWhitespace: true, minifyJS: true }); output = ''; - test_minify_sync(assert, input, { + test_minify(assert, input, output, { collapseWhitespace: true, minifyJS: true, preserveLineBreaks: true - }, output); + }); input = ''; output = ''; - test_minify_sync(assert, input, { minifyJS: true }, output); + test_minify(assert, input, output, { minifyJS: true }); output = ''; - test_minify_sync(assert, input, { collapseWhitespace: true, minifyJS: true }, output); + test_minify(assert, input, output, { collapseWhitespace: true, minifyJS: true }); input = ''; output = ''; - test_minify_sync(assert, input, { minifyJS: true }, output); - test_minify_sync(assert, input, { collapseWhitespace: true, minifyJS: true }, output); + test_minify(assert, input, output, { minifyJS: true }); + test_minify(assert, input, output, { collapseWhitespace: true, minifyJS: true }); }); QUnit.test('event minification', function(assert) { var input, output; input = '
    '; - test_minify_sync(assert, input, { minifyJS: true }, input); + test_minify(assert, input, input, { minifyJS: true }); input = '
    '; output = '
    '; - test_minify_sync(assert, input, { minifyJS: true }, output); + test_minify(assert, input, output, { minifyJS: true }); input = 'test'; output = 'test'; - test_minify_sync(assert, input, { minifyJS: true }, output); + test_minify(assert, input, output, { minifyJS: true }); input = ' foobar'; output = ' foobar'; - test_minify_sync(assert, input, { minifyJS: { mangle: false } }, output); - test_minify_sync(assert, input, { minifyJS: { mangle: false }, quoteCharacter: '\'' }, output); + test_minify(assert, input, output, { minifyJS: { mangle: false } }); + test_minify(assert, input, output, { minifyJS: { mangle: false }, quoteCharacter: '\'' }); input = ' foobar'; output = ' foobar'; - test_minify_sync(assert, input, { minifyJS: { mangle: false }, quoteCharacter: '"' }, output); + test_minify(assert, input, output, { minifyJS: { mangle: false }, quoteCharacter: '"' }); input = ''; output = ''; - test_minify_sync(assert, input, { minifyJS: true }, output); - test_minify_sync(assert, input, { minifyJS: true, quoteCharacter: '\'' }, output); + test_minify(assert, input, output, { minifyJS: true }); + test_minify(assert, input, output, { minifyJS: true, quoteCharacter: '\'' }); input = ''; output = ''; - test_minify_sync(assert, input, { minifyJS: true, quoteCharacter: '"' }, output); + test_minify(assert, input, output, { minifyJS: true, quoteCharacter: '"' }); input = ''; output = ''; - test_minify_sync(assert, input, { minifyJS: true }, output); + test_minify(assert, input, output, { minifyJS: true }); input = ''; output = ''; - test_minify_sync(assert, input, { minifyJS: true }, output); - test_minify_sync(assert, input, { minifyJS: true, customEventAttributes: [] }, input); + test_minify(assert, input, output, { minifyJS: true }); + test_minify(assert, input, input, { minifyJS: true, customEventAttributes: [] }); output = ''; - test_minify_sync(assert, input, { minifyJS: true, customEventAttributes: [/^ng-/] }, output); + test_minify(assert, input, output, { minifyJS: true, customEventAttributes: [/^ng-/] }); output = ''; - test_minify_sync(assert, input, { minifyJS: true, customEventAttributes: [/^on/, /^ng-/] }, output); + test_minify(assert, input, output, { minifyJS: true, customEventAttributes: [/^on/, /^ng-/] }); input = '
    '; - test_minify_sync(assert, input, { minifyJS: true }, input); + test_minify(assert, input, input, { minifyJS: true }); input = '
    '; output = '
    '; - test_minify_sync(assert, input, { minifyJS: true }, output); + test_minify(assert, input, output, { minifyJS: true }); input = '
    '; output = '
    ")\'>
    '; - test_minify_sync(assert, input, { minifyJS: true }, output); + test_minify(assert, input, output, { minifyJS: true }); }); QUnit.test('escaping closing script tag', function(assert) { var input = ''; var output = ''; - test_minify_sync(assert, input, { minifyJS: true }, output); + test_minify(assert, input, output, { minifyJS: true }); }); QUnit.test('style minification', function(assert) { var input, output; input = 'div#foo { background-color: red; color: white }'; - test_minify_sync(assert, input, { minifyCSS: true }, input); + test_minify(assert, input, input, { minifyCSS: true }); input = ''; output = ''; - test_minify_sync(assert, input, input); - test_minify_sync(assert, input, { minifyCSS: true }, output); + test_minify(assert, input, input); + test_minify(assert, input, output, { minifyCSS: true }); input = ''; output = ''; - test_minify_sync(assert, input, { minifyCSS: true }, output); + test_minify(assert, input, output, { minifyCSS: true }); input = '
    '; - test_minify_sync(assert, input, input); + test_minify(assert, input, input); output = '
    '; - test_minify_sync(assert, input, { minifyCSS: true }, output); - test_minify_sync(assert, input, { + test_minify(assert, input, output, { minifyCSS: true }); + test_minify(assert, input, output, { collapseWhitespace: true, minifyCSS: true - }, output); + }); input = '
    '; - test_minify_sync(assert, input, input); + test_minify(assert, input, input); output = '
    '; - test_minify_sync(assert, input, { minifyCSS: true }, output); - test_minify_sync(assert, input, { + test_minify(assert, input, output, { minifyCSS: true }); + test_minify(assert, input, output, { collapseWhitespace: true, minifyCSS: true - }, output); + }); input = ''; - test_minify_sync(assert, input, input); + test_minify(assert, input, input); output = ''; - test_minify_sync(assert, input, { minifyCSS: true }, output); - test_minify_sync(assert, input, { + test_minify(assert, input, output, { minifyCSS: true }); + test_minify(assert, input, output, { collapseWhitespace: true, minifyCSS: true - }, output); + }); input = ''; - test_minify_sync(assert, input, input); + test_minify(assert, input, input); output = ''; - test_minify_sync(assert, input, { minifyCSS: true }, output); - test_minify_sync(assert, input, { + test_minify(assert, input, output, { minifyCSS: true }); + test_minify(assert, input, output, { collapseWhitespace: true, minifyCSS: true - }, output); + }); input = ''; - test_minify_sync(assert, input, input); + test_minify(assert, input, input); output = ''; - test_minify_sync(assert, input, { minifyCSS: true }, output); + test_minify(assert, input, output, { minifyCSS: true }); output = ''; - test_minify_sync(assert, input, { + test_minify(assert, input, output, { minifyCSS: true, removeAttributeQuotes: true - }, output); + }); input = ''; - test_minify_sync(assert, input, input); + test_minify(assert, input, input); output = ''; - test_minify_sync(assert, input, { minifyCSS: true }, output); + test_minify(assert, input, output, { minifyCSS: true }); output = ''; - test_minify_sync(assert, input, { + test_minify(assert, input, output, { minifyCSS: true, removeAttributeQuotes: true - }, output); + }); }); QUnit.test('style attribute minification', function(assert) { var input = '
    '; var output = '
    '; - test_minify_sync(assert, input, { minifyCSS: true }, output); + test_minify(assert, input, output, { minifyCSS: true }); }); QUnit.test('url attribute minification', function(assert) { @@ -2552,61 +2554,61 @@ QUnit.test('url attribute minification', function(assert) { input = '
    link
    '; output = '
    link
    '; - test_minify_sync(assert, input, { minifyURLs: 'http://website.com/folder/' }, output); - test_minify_sync(assert, input, { minifyURLs: { site: 'http://website.com/folder/' } }, output); + test_minify(assert, input, output, { minifyURLs: 'http://website.com/folder/' }); + test_minify(assert, input, output, { minifyURLs: { site: 'http://website.com/folder/' } }); input = ''; - test_minify_sync(assert, input, { minifyURLs: 'http://website.com/' }, input); - test_minify_sync(assert, input, { minifyURLs: { site: 'http://website.com/' } }, input); + test_minify(assert, input, input, { minifyURLs: 'http://website.com/' }); + test_minify(assert, input, input, { minifyURLs: { site: 'http://website.com/' } }); input = ''; - test_minify_sync(assert, input, { minifyURLs: 'http://website.com/' }, input); - test_minify_sync(assert, input, { minifyURLs: { site: 'http://website.com/' } }, input); + test_minify(assert, input, input, { minifyURLs: 'http://website.com/' }); + test_minify(assert, input, input, { minifyURLs: { site: 'http://website.com/' } }); output = ''; - test_minify_sync(assert, input, { minifyCSS: true }, output); + test_minify(assert, input, output, { minifyCSS: true }); output = ''; - test_minify_sync(assert, input, { + test_minify(assert, input, output, { minifyCSS: true, minifyURLs: 'http://website.com/' - }, output); - test_minify_sync(assert, input, { + }); + test_minify(assert, input, output, { minifyCSS: true, minifyURLs: { site: 'http://website.com/' } - }, output); + }); input = ''; - test_minify_sync(assert, input, { minifyURLs: { site: 'http://website.com/foo bar/' } }, input); + test_minify(assert, input, input, { minifyURLs: { site: 'http://website.com/foo bar/' } }); output = ''; - test_minify_sync(assert, input, { minifyCSS: true }, output); + test_minify(assert, input, output, { minifyCSS: true }); output = ''; - test_minify_sync(assert, input, { + test_minify(assert, input, output, { minifyCSS: true, minifyURLs: { site: 'http://website.com/foo bar/' } - }, output); + }); input = ''; - test_minify_sync(assert, input, { minifyURLs: { site: 'http://website.com/' } }, input); - test_minify_sync(assert, input, { minifyURLs: { site: 'http://website.com/foo%20bar/' } }, input); - test_minify_sync(assert, input, { minifyURLs: { site: 'http://website.com/foo%20bar/(baz)/' } }, input); + test_minify(assert, input, input, { minifyURLs: { site: 'http://website.com/' } }); + test_minify(assert, input, input, { minifyURLs: { site: 'http://website.com/foo%20bar/' } }); + test_minify(assert, input, input, { minifyURLs: { site: 'http://website.com/foo%20bar/(baz)/' } }); output = ''; - test_minify_sync(assert, input, { + test_minify(assert, input, output, { minifyCSS: true, minifyURLs: { site: 'http://website.com/' } - }, output); + }); output = ''; - test_minify_sync(assert, input, { + test_minify(assert, input, output, { minifyCSS: true, minifyURLs: { site: 'http://website.com/foo%20bar/' } - }, output); + }); output = ''; - test_minify_sync(assert, input, { + test_minify(assert, input, output, { minifyCSS: true, minifyURLs: { site: 'http://website.com/foo%20bar/(baz)/' } - }, output); + }); input = ''; output = ''; - test_minify_sync(assert, input, { minifyURLs: { site: 'http://site.com/' } }, output); + test_minify(assert, input, output, { minifyURLs: { site: 'http://site.com/' } }); }); QUnit.test('srcset attribute minification', function(assert) { @@ -2614,20 +2616,20 @@ QUnit.test('srcset attribute minification', function(assert) { input = ''; output = ''; - test_minify_sync(assert, input, output); + test_minify(assert, input, output); output = ''; - test_minify_sync(assert, input, { minifyURLs: { site: 'http://site.com/' } }, output); + test_minify(assert, input, output, { minifyURLs: { site: 'http://site.com/' } }); }); QUnit.test('valueless attributes', function(assert) { var input = '
    '; - test_minify_sync(assert, input, input); + test_minify(assert, input, input); }); QUnit.test('newlines becoming whitespaces', function(assert) { var input = 'test\n\n\n\ntest'; var output = 'test test'; - test_minify_sync(assert, input, { collapseWhitespace: true }, output); + test_minify(assert, input, output, { collapseWhitespace: true }); }); QUnit.test('conservative collapse', function(assert) { @@ -2635,115 +2637,115 @@ QUnit.test('conservative collapse', function(assert) { input = ' foo \n\n'; output = ' foo '; - test_minify_sync(assert, input, { + test_minify(assert, input, output, { collapseWhitespace: true, conservativeCollapse: true - }, output); + }); input = '\n\n\n\n'; output = ' '; - test_minify_sync(assert, input, { + test_minify(assert, input, output, { removeComments: true, collapseWhitespace: true, conservativeCollapse: true - }, output); + }); input = '

    \u00A0

    '; - test_minify_sync(assert, input, { collapseWhitespace: true }, input); - test_minify_sync(assert, input, { + test_minify(assert, input, input, { collapseWhitespace: true }); + test_minify(assert, input, input, { collapseWhitespace: true, conservativeCollapse: true - }, input); + }); input = '

    \u00A0

    '; output = '

    \u00A0

    '; - test_minify_sync(assert, input, { collapseWhitespace: true }, output); - test_minify_sync(assert, input, { + test_minify(assert, input, output, { collapseWhitespace: true }); + test_minify(assert, input, output, { collapseWhitespace: true, conservativeCollapse: true - }, output); + }); input = '

    \u00A0

    '; output = '

    \u00A0

    '; - test_minify_sync(assert, input, { collapseWhitespace: true }, output); - test_minify_sync(assert, input, { + test_minify(assert, input, output, { collapseWhitespace: true }); + test_minify(assert, input, output, { collapseWhitespace: true, conservativeCollapse: true - }, output); + }); input = '

    \u00A0

    '; output = '

    \u00A0

    '; - test_minify_sync(assert, input, { collapseWhitespace: true }, output); - test_minify_sync(assert, input, { + test_minify(assert, input, output, { collapseWhitespace: true }); + test_minify(assert, input, output, { collapseWhitespace: true, conservativeCollapse: true - }, output); + }); input = '

    \u00A0\u00A0 \u00A0

    '; output = '

    \u00A0\u00A0 \u00A0

    '; - test_minify_sync(assert, input, { collapseWhitespace: true }, output); - test_minify_sync(assert, input, { + test_minify(assert, input, output, { collapseWhitespace: true }); + test_minify(assert, input, output, { collapseWhitespace: true, conservativeCollapse: true - }, output); + }); input = '

    foo \u00A0\u00A0 \u00A0

    '; output = '

    foo \u00A0\u00A0 \u00A0

    '; - test_minify_sync(assert, input, { collapseWhitespace: true }, output); - test_minify_sync(assert, input, { + test_minify(assert, input, output, { collapseWhitespace: true }); + test_minify(assert, input, output, { collapseWhitespace: true, conservativeCollapse: true - }, output); + }); input = '

    \u00A0\u00A0 \u00A0 bar

    '; output = '

    \u00A0\u00A0 \u00A0 bar

    '; - test_minify_sync(assert, input, { collapseWhitespace: true }, output); - test_minify_sync(assert, input, { + test_minify(assert, input, output, { collapseWhitespace: true }); + test_minify(assert, input, output, { collapseWhitespace: true, conservativeCollapse: true - }, output); + }); input = '

    foo \u00A0\u00A0 \u00A0 bar

    '; output = '

    foo \u00A0\u00A0 \u00A0 bar

    '; - test_minify_sync(assert, input, { collapseWhitespace: true }, output); - test_minify_sync(assert, input, { + test_minify(assert, input, output, { collapseWhitespace: true }); + test_minify(assert, input, output, { collapseWhitespace: true, conservativeCollapse: true - }, output); + }); input = '

    \u00A0foo\u00A0\t

    '; output = '

    \u00A0foo\u00A0

    '; - test_minify_sync(assert, input, { collapseWhitespace: true }, output); - test_minify_sync(assert, input, { + test_minify(assert, input, output, { collapseWhitespace: true }); + test_minify(assert, input, output, { collapseWhitespace: true, conservativeCollapse: true - }, output); + }); input = '

    \u00A0\nfoo\u00A0\t

    '; output = '

    \u00A0 foo\u00A0

    '; - test_minify_sync(assert, input, { collapseWhitespace: true }, output); - test_minify_sync(assert, input, { + test_minify(assert, input, output, { collapseWhitespace: true }); + test_minify(assert, input, output, { collapseWhitespace: true, conservativeCollapse: true - }, output); + }); input = '

    \u00A0foo \u00A0\t

    '; output = '

    \u00A0foo \u00A0

    '; - test_minify_sync(assert, input, { collapseWhitespace: true }, output); - test_minify_sync(assert, input, { + test_minify(assert, input, output, { collapseWhitespace: true }); + test_minify(assert, input, output, { collapseWhitespace: true, conservativeCollapse: true - }, output); + }); input = '

    \u00A0\nfoo \u00A0\t

    '; output = '

    \u00A0 foo \u00A0

    '; - test_minify_sync(assert, input, { collapseWhitespace: true }, output); - test_minify_sync(assert, input, { + test_minify(assert, input, output, { collapseWhitespace: true }); + test_minify(assert, input, output, { collapseWhitespace: true, conservativeCollapse: true - }, output); + }); }); QUnit.test('collapse preseving a line break', function(assert) { @@ -2773,15 +2775,15 @@ QUnit.test('collapse preseving a line break', function(assert) { '\n' + '\n' + '\n\n

    \ntest test test\n

    \n'; - test_minify_sync(assert, input, { + test_minify(assert, input, output, { collapseWhitespace: true, preserveLineBreaks: true - }, output); - test_minify_sync(assert, input, { + }); + test_minify(assert, input, output, { collapseWhitespace: true, conservativeCollapse: true, preserveLineBreaks: true - }, output); + }); output = '\n\n\n' + '\n\n\n' + 'Carbon\n\n' + @@ -2793,140 +2795,140 @@ QUnit.test('collapse preseving a line break', function(assert) { '\n' + '\n' + '\n\n

    \ntest test test\n

    \n'; - test_minify_sync(assert, input, { + test_minify(assert, input, output, { collapseWhitespace: true, conservativeCollapse: true, preserveLineBreaks: true, removeComments: true - }, output); + }); input = '
    text \n text \n
    '; output = '
    text \ntext\n
    '; - test_minify_sync(assert, input, { + test_minify(assert, input, output, { collapseWhitespace: true, preserveLineBreaks: true - }, output); + }); input = '
    text \n
    '; output = '
    text\n
    '; - test_minify_sync(assert, input, { + test_minify(assert, input, output, { collapseWhitespace: true, preserveLineBreaks: true - }, output); + }); output = '
    text\n
    '; - test_minify_sync(assert, input, { + test_minify(assert, input, output, { collapseWhitespace: true, conservativeCollapse: true, preserveLineBreaks: true - }, output); + }); input = '
    \ntext
    '; output = '
    \ntext
    '; - test_minify_sync(assert, input, { + test_minify(assert, input, output, { collapseWhitespace: true, preserveLineBreaks: true - }, output); + }); output = '
    \ntext
    '; - test_minify_sync(assert, input, { + test_minify(assert, input, output, { collapseWhitespace: true, conservativeCollapse: true, preserveLineBreaks: true - }, output); + }); input = 'This is the start. <% ... %>\r\n<%= ... %>\r\n\r\n\r\nNo comment, but middle.\r\n\r\n\r\n\r\nHello, this is the end!'; output = 'This is the start. <% ... %>\n<%= ... %>\n\nNo comment, but middle.\n\n\n\nHello, this is the end!'; - test_minify_sync(assert, input, { + test_minify(assert, input, output, { removeComments: true, collapseWhitespace: true, preserveLineBreaks: true - }, output); + }); }); QUnit.test('collapse inline tag whitespace', function(assert) { var input, output; input = ' '; - test_minify_sync(assert, input, { + test_minify(assert, input, input, { collapseWhitespace: true - }, input); + }); output = ''; - test_minify_sync(assert, input, { + test_minify(assert, input, output, { collapseWhitespace: true, collapseInlineTagWhitespace: true - }, output); + }); input = '

    where R is the Rici tensor.

    '; output = '

    where R is the Rici tensor.

    '; - test_minify_sync(assert, input, { + test_minify(assert, input, output, { collapseWhitespace: true - }, output); + }); output = '

    whereRis the Rici tensor.

    '; - test_minify_sync(assert, input, { + test_minify(assert, input, output, { collapseWhitespace: true, collapseInlineTagWhitespace: true - }, output); + }); }); QUnit.test('ignore custom comments', function(assert) { var input, output; input = ''; - test_minify_sync(assert, input, input); - test_minify_sync(assert, input, { removeComments: true }, input); - test_minify_sync(assert, input, { ignoreCustomComments: false }, input); - test_minify_sync(assert, input, { + test_minify(assert, input, input); + test_minify(assert, input, input, { removeComments: true }); + test_minify(assert, input, input, { ignoreCustomComments: false }); + test_minify(assert, input, '', { removeComments: true, ignoreCustomComments: [] - }, ''); - test_minify_sync(assert, input, { + }); + test_minify(assert, input, '', { removeComments: true, ignoreCustomComments: false - }, ''); + }); input = 'test'; output = 'test'; - test_minify_sync(assert, input, output); - test_minify_sync(assert, input, { removeComments: true }, output); - test_minify_sync(assert, input, { ignoreCustomComments: false }, output); - test_minify_sync(assert, input, { + test_minify(assert, input, output); + test_minify(assert, input, output, { removeComments: true }); + test_minify(assert, input, output, { ignoreCustomComments: false }); + test_minify(assert, input, output, { removeComments: true, ignoreCustomComments: [] - }, output); - test_minify_sync(assert, input, { + }); + test_minify(assert, input, output, { removeComments: true, ignoreCustomComments: false - }, output); + }); input = '
  • test
  • '; - test_minify_sync(assert, input, { + test_minify(assert, input, input, { removeComments: true, // ignore knockout comments ignoreCustomComments: [ /^\s+ko/, /\/ko\s+$/ ] - }, input); + }); input = ''; - test_minify_sync(assert, input, { + test_minify(assert, input, input, { removeComments: true, // ignore Apache SSI includes ignoreCustomComments: [ /^\s*#/ ] - }, input); + }); }); QUnit.test('processScripts', function(assert) { var input = ''; var output = ''; - test_minify_sync(assert, input, { + test_minify(assert, input, output, { collapseWhitespace: true, removeComments: true, processScripts: ['text/ng-template'] - }, output); + }); }); QUnit.test('ignore', function(assert) { @@ -2936,10 +2938,10 @@ QUnit.test('ignore', function(assert) { '
    \n test foo \n\n
    '; output = '
    \n test foo \n\n
    ' + '
    test foo
    '; - test_minify_sync(assert, input, { collapseWhitespace: true }, output); + test_minify(assert, input, output, { collapseWhitespace: true }); input = ''; - test_minify_sync(assert, input, ''); + test_minify(assert, input, ''); input = '

    .....

    ' + '@for( $i = 0 ; $i < $criterions->count() ; $i++ )' + @@ -2951,23 +2953,23 @@ QUnit.test('ignore', function(assert) { '

    {{ $criterions[$i]->value }}

    ' + '@endfor' + '

    ....

    '; - test_minify_sync(assert, input, { removeComments: true }, output); + test_minify(assert, input, output, { removeComments: true }); input = '

    bar

    '; output = '

    bar

    '; - test_minify_sync(assert, input, output); + test_minify(assert, input, output); input = '>'; output = '>'; - test_minify_sync(assert, input, { ignoreCustomFragments: [/<\?php[\s\S]*?\?>/] }, output); + test_minify(assert, input, output, { ignoreCustomFragments: [/<\?php[\s\S]*?\?>/] }); input = 'a\nb'; output = 'a b'; - test_minify_sync(assert, input, { collapseWhitespace: true }, output); + test_minify(assert, input, output, { collapseWhitespace: true }); input = '

    foo \n\tbar\n.

    '; output = '

    foo \n\tbar\n.

    '; - test_minify_sync(assert, input, { collapseWhitespace: true }, output); + test_minify(assert, input, output, { collapseWhitespace: true }); }); QUnit.test('meta viewport', function(assert) { @@ -2975,37 +2977,36 @@ QUnit.test('meta viewport', function(assert) { input = ''; output = ''; - test_minify_sync(assert, input, output); + test_minify(assert, input, output); input = ''; output = ''; - test_minify_sync(assert, input, output); + test_minify(assert, input, output); input = ''; output = ''; - test_minify_sync(assert, input, output); + test_minify(assert, input, output); input = ''; output = ''; - test_minify_sync(assert, input, output); + test_minify(assert, input, output); }); QUnit.test('downlevel-revealed conditional comments', function(assert) { var input = ''; - test_minify_sync(assert, input, input); - test_minify_sync(assert, input, { removeComments: true }, input); + test_minify(assert, input, input); + test_minify(assert, input, input, { removeComments: true }); }); QUnit.test('noscript', function(assert) { var input; input = ''; - test_minify_sync(assert, input, ''); + test_minify(assert, input, ''); input = ''; - test_minify_sync(assert, input, { removeComments: true, collapseWhitespace: true, removeEmptyAttributes: true }, - ''); + test_minify(assert, input, '', { removeComments: true, collapseWhitespace: true, removeEmptyAttributes: true }); }); QUnit.test('max line length', function(assert) { @@ -3013,57 +3014,51 @@ QUnit.test('max line length', function(assert) { var options = { maxLineLength: 25 }; input = '123456789012345678901234567890'; - test_minify_sync(assert, input, options, input); + test_minify(assert, input, input, options); input = '
    '; - test_minify_sync(assert, input, options, '
    \n
    '); + test_minify(assert, input, '
    \n
    ', options); input = ' hello world \n world hello '; - test_minify_sync(assert, input, options, '\n hello world \n world hello \n'); + test_minify(assert, input, '\n hello world \n world hello \n', options); - test_minify_sync(assert, '

    x

    ', '

    x

    '); - test_minify_sync(assert, '

    x

    ', '

    x

    '); - test_minify_sync(assert, '

    x

    ', '

    x

    '); - test_minify_sync(assert, '

    xxx

    ', '

    xxx

    '); - test_minify_sync(assert, '

    xxx

    ', '

    xxx

    '); + test_minify(assert, '

    x

    ', '

    x

    '); + test_minify(assert, '

    x

    ', '

    x

    '); + test_minify(assert, '

    x

    ', '

    x

    '); + test_minify(assert, '

    xxx

    ', '

    xxx

    '); + test_minify(assert, '

    xxx

    ', '

    xxx

    '); input = '
    ' + 'i\'m 10 levels deep' + '
    '; - test_minify_sync(assert, input, input); + test_minify(assert, input, input); - test_minify_sync(assert, '', options, ''); + test_minify(assert, '', '', options); input = ''; - test_minify_sync(assert, '', options, input); - test_minify_sync(assert, input, options, input); - test_minify_sync(assert, '', options, ''); - - test_minify_sync(assert, 'foo', options, 'foo\n'); - test_minify_sync(assert, '

    x', options, '

    x

    '); - test_minify_sync(assert, '

    x

    ', options, '

    x

    ', 'trailing quote should be ignored'); - test_minify_sync(assert, '

    Click me

    ', options, '

    Click me\n

    '); + test_minify(assert, '', input, options); + test_minify(assert, input, input, options); + test_minify(assert, '', '', options); + + test_minify(assert, 'foo', 'foo\n', options); + test_minify(assert, '

    x', '

    x

    ', options); + test_minify(assert, '

    x

    ', '

    x

    ', options, 'trailing quote should be ignored'); + test_minify(assert, '

    Click me

    ', '

    Click me\n

    ', options); input = ''; - test_minify_sync(assert, '', options, input); - test_minify_sync(assert, input, options, input); - test_minify_sync(assert, '
    [fallback image]
    ', options, - '
    \n[fallback image]
    \n
    ' - ); + test_minify(assert, '', input, options); + test_minify(assert, input, input, options); + test_minify(assert, '
    [fallback image]
    ', '
    \n[fallback image]
    \n
    ', options); - test_minify_sync(assert, '', options, '\n'); - test_minify_sync(assert, '', options, '\n'); - test_minify_sync(assert, '
    ', options, - '\n
    ' - ); - test_minify_sync(assert, '', options, - '\n\n\n' - ); - test_minify_sync(assert, '[\']["]', options, '[\']["]'); - test_minify_sync(assert, '
    hey
    ', options, '\n
    hey
    '); - test_minify_sync(assert, ':) link', options, ':) \nlink'); - test_minify_sync(assert, ':) \nlink', options, ':) \nlink'); - test_minify_sync(assert, ':) \n\nlink', options, ':) \n\nlink'); + test_minify(assert, '', '\n', options); + test_minify(assert, '', '\n', options); + test_minify(assert, '
    ', '\n
    ', options); + test_minify(assert, '', '\n\n\n', options); + test_minify(assert, '[\']["]', '[\']["]', options); + test_minify(assert, '
    hey
    ', '\n
    hey
    ', options); + test_minify(assert, ':) link', ':) \nlink', options); + test_minify(assert, ':) \nlink', ':) \nlink', options); + test_minify(assert, ':) \n\nlink', ':) \n\nlink', options); - test_minify_sync(assert, 'ok', options, 'ok'); + test_minify(assert, 'ok', 'ok', options); }); QUnit.test('custom attribute collapse', function(assert) { @@ -3080,15 +3075,15 @@ QUnit.test('custom attribute collapse', function(assert) { '">foo'; output = '
    foo
    '; - test_minify_sync(assert, input, input); - test_minify_sync(assert, input, { customAttrCollapse: /data-bind/ }, output); + test_minify(assert, input, input); + test_minify(assert, input, output, { customAttrCollapse: /data-bind/ }); input = '
    bar
    '; output = '
    bar
    '; - test_minify_sync(assert, input, { customAttrCollapse: /style/ }, output); + test_minify(assert, input, output, { customAttrCollapse: /style/ }); input = '
    ' + '
    '; output = '
    '; - test_minify_sync(assert, input, { customAttrCollapse: /ng-class/ }, output); + test_minify(assert, input, output, { customAttrCollapse: /ng-class/ }); }); QUnit.test('custom attribute collapse with empty attribute value', function(assert) { var input = '
    '; var output = '
    '; - test_minify_sync(assert, input, { customAttrCollapse: /.+/ }, output); + test_minify(assert, input, output, { customAttrCollapse: /.+/ }); }); QUnit.test('custom attribute collapse with newlines, whitespace, and carriage returns', function(assert) { @@ -3115,7 +3110,7 @@ QUnit.test('custom attribute collapse with newlines, whitespace, and carriage re ' value2:false \n\r' + ' }">'; var output = '
    '; - test_minify_sync(assert, input, { customAttrCollapse: /ng-class/ }, output); + test_minify(assert, input, output, { customAttrCollapse: /ng-class/ }); }); QUnit.test('do not escape attribute value', function(assert) { @@ -3124,23 +3119,23 @@ QUnit.test('do not escape attribute value', function(assert) { input = '
    \n"' + '}\'>'; - test_minify_sync(assert, input, input); - test_minify_sync(assert, input, { preventAttributesEscaping: true }, input); + test_minify(assert, input, input); + test_minify(assert, input, input, { preventAttributesEscaping: true }); input = '
    '; - test_minify_sync(assert, input, { preventAttributesEscaping: true }, input); + test_minify(assert, input, input, { preventAttributesEscaping: true }); output = '
    '; - test_minify_sync(assert, input, output); + test_minify(assert, input, output); }); QUnit.test('quoteCharacter is single quote', function(assert) { - test_minify_sync(assert, '
    foo
    ', { quoteCharacter: '\'' }, '
    foo
    '); - test_minify_sync(assert, '
    foo
    ', { quoteCharacter: '\'' }, '
    foo
    '); + test_minify(assert, '
    foo
    ', '
    foo
    ', { quoteCharacter: '\'' }); + test_minify(assert, '
    foo
    ', '
    foo
    ', { quoteCharacter: '\'' }); }); QUnit.test('quoteCharacter is not single quote or double quote', function(assert) { - test_minify_sync(assert, '
    foo
    ', { quoteCharacter: 'm' }, '
    foo
    '); - test_minify_sync(assert, '
    foo
    ', { quoteCharacter: 'm' }, '
    foo
    '); + test_minify(assert, '
    foo
    ', '
    foo
    ', { quoteCharacter: 'm' }); + test_minify(assert, '
    foo
    ', '
    foo
    ', { quoteCharacter: 'm' }); }); QUnit.test('remove space between attributes', function(assert) { @@ -3154,27 +3149,27 @@ QUnit.test('remove space between attributes', function(assert) { input = ''; output = ''; - test_minify_sync(assert, input, options, output); + test_minify(assert, input, output, options); input = ''; output = ''; - test_minify_sync(assert, input, options, output); + test_minify(assert, input, output, options); input = ''; output = ''; - test_minify_sync(assert, input, options, output); + test_minify(assert, input, output, options); input = ''; output = ''; - test_minify_sync(assert, input, options, output); + test_minify(assert, input, output, options); input = ''; output = ''; - test_minify_sync(assert, input, options, output); + test_minify(assert, input, output, options); input = ''; output = ''; - test_minify_sync(assert, input, options, output); + test_minify(assert, input, output, options); }); QUnit.test('markups from Angular 2', function(assert) { @@ -3200,7 +3195,7 @@ QUnit.test('markups from Angular 2', function(assert) { ' \n' + ' \n' + ''; - test_minify_sync(assert, input, { caseSensitive: true }, output); + test_minify(assert, input, output, { caseSensitive: true }); output = '' + @@ -3211,7 +3206,7 @@ QUnit.test('markups from Angular 2', function(assert) { '' + '' + ''; - test_minify_sync(assert, input, { + test_minify(assert, input, output, { caseSensitive: true, collapseBooleanAttributes: true, collapseWhitespace: true, @@ -3224,58 +3219,58 @@ QUnit.test('markups from Angular 2', function(assert) { removeStyleLinkTypeAttributes: true, removeTagWhitespace: true, useShortDoctype: true - }, output); + }); }); QUnit.test('auto-generated tags', function(assert) { var input, output; input = '

    '; - test_minify_sync(assert, input, { includeAutoGeneratedTags: false }, input); + test_minify(assert, input, input, { includeAutoGeneratedTags: false }); input = '

    x'; output = '

    x'; - test_minify_sync(assert, input, { includeAutoGeneratedTags: false }, output); + test_minify(assert, input, output, { includeAutoGeneratedTags: false }); output = '

    x

    '; - test_minify_sync(assert, input, output); - test_minify_sync(assert, input, { includeAutoGeneratedTags: true }, output); + test_minify(assert, input, output); + test_minify(assert, input, output, { includeAutoGeneratedTags: true }); input = '

    x'; output = '

    x'; - test_minify_sync(assert, input, { includeAutoGeneratedTags: false }, output); + test_minify(assert, input, output, { includeAutoGeneratedTags: false }); input = '

    '; output = '
    Well, look at me! I\'m a div!
    '; - test_minify_sync(assert, input, { html5: false, includeAutoGeneratedTags: false }, output); - test_minify_sync(assert, '

    x', { + test_minify(assert, input, output, { html5: false, includeAutoGeneratedTags: false }); + test_minify(assert, '

    x', '

    x', { maxLineLength: 25, includeAutoGeneratedTags: false - }, '

    x'); + }); input = '

    foo'; - test_minify_sync(assert, input, { includeAutoGeneratedTags: false }, input); - test_minify_sync(assert, input, { + test_minify(assert, input, input, { includeAutoGeneratedTags: false }); + test_minify(assert, input, input, { includeAutoGeneratedTags: false, removeOptionalTags: true - }, input); + }); input = '

    '; - test_minify_sync(assert, input, { includeAutoGeneratedTags: false }, input); + test_minify(assert, input, input, { includeAutoGeneratedTags: false }); output = ''; - test_minify_sync(assert, input, { + test_minify(assert, input, output, { includeAutoGeneratedTags: false, removeOptionalTags: true - }, output); + }); input = ''; - test_minify_sync(assert, input, { includeAutoGeneratedTags: false }, input); + test_minify(assert, input, input, { includeAutoGeneratedTags: false }); output = ''; - test_minify_sync(assert, input, { includeAutoGeneratedTags: true }, output); + test_minify(assert, input, output, { includeAutoGeneratedTags: true }); input = ''; - test_minify_sync(assert, input, { includeAutoGeneratedTags: false }, input); + test_minify(assert, input, input, { includeAutoGeneratedTags: false }); output = ''; - test_minify_sync(assert, input, { includeAutoGeneratedTags: true }, output); + test_minify(assert, input, output, { includeAutoGeneratedTags: true }); }); QUnit.test('sort attributes', function(assert) { @@ -3284,31 +3279,31 @@ QUnit.test('sort attributes', function(assert) { input = '' + '' + ''; - test_minify_sync(assert, input, input); - test_minify_sync(assert, input, { sortAttributes: false }, input); + test_minify(assert, input, input); + test_minify(assert, input, input, { sortAttributes: false }); output = '' + '' + ''; - test_minify_sync(assert, input, { sortAttributes: true }, output); + test_minify(assert, input, output, { sortAttributes: true }); input = '' + '' + ''; - test_minify_sync(assert, input, input); - test_minify_sync(assert, input, { sortAttributes: false }, input); + test_minify(assert, input, input); + test_minify(assert, input, input, { sortAttributes: false }); output = '' + '' + ''; - test_minify_sync(assert, input, { sortAttributes: true }, output); + test_minify(assert, input, output, { sortAttributes: true }); output = '' + '' + ''; - test_minify_sync(assert, input, { + test_minify(assert, input, output, { processScripts: [ 'text/html' ], sortAttributes: true - }, output); + }); input = '' + '' + @@ -3316,45 +3311,45 @@ QUnit.test('sort attributes', function(assert) { output = '' + '' + ''; - test_minify_sync(assert, input, { sortAttributes: true }, output); + test_minify(assert, input, output, { sortAttributes: true }); output = '' + '' + ''; - test_minify_sync(assert, input, { + test_minify(assert, input, output, { removeStyleLinkTypeAttributes: true, sortAttributes: true - }, output); + }); input = '
    ' + '' + '' + '' + ''; - test_minify_sync(assert, input, input); - test_minify_sync(assert, input, { sortAttributes: false }, input); + test_minify(assert, input, input); + test_minify(assert, input, input, { sortAttributes: false }); output = '' + '' + '' + '' + ''; - test_minify_sync(assert, input, { sortAttributes: true }, output); + test_minify(assert, input, output, { sortAttributes: true }); input = ' foo_bar>'; - test_minify_sync(assert, input, { + test_minify(assert, input, input, { ignoreCustomFragments: [/<#[\s\S]*?#>/] - }, input); - test_minify_sync(assert, input, { + }); + test_minify(assert, input, input, { ignoreCustomFragments: [/<#[\s\S]*?#>/], sortAttributes: false - }, input); + }); output = ' >'; - test_minify_sync(assert, input, { + test_minify(assert, input, output, { ignoreCustomFragments: [/<#[\s\S]*?#>/], sortAttributes: true - }, output); + }); input = ''; - test_minify_sync(assert, input, { sortAttributes: true }, input); + test_minify(assert, input, input, { sortAttributes: true }); }); QUnit.test('sort style classes', function(assert) { @@ -3365,125 +3360,125 @@ QUnit.test('sort style classes', function(assert) { '' + '' + ''; - test_minify_sync(assert, input, input); - test_minify_sync(assert, input, { sortClassName: false }, input); + test_minify(assert, input, input); + test_minify(assert, input, input, { sortClassName: false }); output = '' + '' + '' + '' + ''; - test_minify_sync(assert, input, { sortClassName: true }, output); + test_minify(assert, input, output, { sortClassName: true }); input = ''; output = ''; - test_minify_sync(assert, input, output); - test_minify_sync(assert, input, { sortClassName: false }, output); + test_minify(assert, input, output); + test_minify(assert, input, output, { sortClassName: false }); output = ''; - test_minify_sync(assert, input, { sortClassName: true }, output); + test_minify(assert, input, output, { sortClassName: true }); input = ''; - test_minify_sync(assert, input, { + test_minify(assert, input, input, { ignoreCustomFragments: [/<#[\s\S]*?#>/] - }, input); - test_minify_sync(assert, input, { + }); + test_minify(assert, input, input, { ignoreCustomFragments: [/<#[\s\S]*?#>/], sortClassName: false - }, input); - test_minify_sync(assert, input, { + }); + test_minify(assert, input, input, { ignoreCustomFragments: [/<#[\s\S]*?#>/], sortClassName: true - }, input); + }); input = ''; - test_minify_sync(assert, input, { sortClassName: false }, input); - test_minify_sync(assert, input, { sortClassName: true }, input); + test_minify(assert, input, input, { sortClassName: false }); + test_minify(assert, input, input, { sortClassName: true }); input = ''; - test_minify_sync(assert, input, { sortClassName: false }, input); + test_minify(assert, input, input, { sortClassName: false }); output = ''; - test_minify_sync(assert, input, { sortClassName: true }, output); + test_minify(assert, input, output, { sortClassName: true }); input = ''; - test_minify_sync(assert, input, { + test_minify(assert, input, input, { collapseWhitespace: true, ignoreCustomFragments: [/{{.*?}}/], removeAttributeQuotes: true, sortClassName: true - }, input); + }); input = ''; - test_minify_sync(assert, input, { + test_minify(assert, input, input, { collapseWhitespace: true, ignoreCustomFragments: [/{{.*?}}/], removeAttributeQuotes: true, sortClassName: true - }, input); + }); input = ''; - test_minify_sync(assert, input, { + test_minify(assert, input, input, { collapseWhitespace: true, ignoreCustomFragments: [/{{.*?}}/], removeAttributeQuotes: true, sortClassName: true - }, input); + }); input = ''; - test_minify_sync(assert, input, { + test_minify(assert, input, input, { collapseWhitespace: true, ignoreCustomFragments: [/{{.*?}}/], removeAttributeQuotes: true, sortClassName: true - }, input); + }); input = ''; output = ''; - test_minify_sync(assert, input, { + test_minify(assert, input, output, { collapseWhitespace: true, ignoreCustomFragments: [/{{.*?}}/], removeAttributeQuotes: true, sortClassName: true - }, output); + }); }); QUnit.test('decode entity characters', function(assert) { var input, output; input = ''; - test_minify_sync(assert, input, input); - test_minify_sync(assert, input, { decodeEntities: false }, input); - test_minify_sync(assert, input, { decodeEntities: true }, input); + test_minify(assert, input, input); + test_minify(assert, input, input, { decodeEntities: false }); + test_minify(assert, input, input, { decodeEntities: true }); input = ''; - test_minify_sync(assert, input, input); - test_minify_sync(assert, input, { decodeEntities: false }, input); - test_minify_sync(assert, input, { decodeEntities: true }, input); + test_minify(assert, input, input); + test_minify(assert, input, input, { decodeEntities: false }); + test_minify(assert, input, input, { decodeEntities: true }); output = ''; - test_minify_sync(assert, input, { decodeEntities: true, processScripts: ['text/html'] }, output); + test_minify(assert, input, output, { decodeEntities: true, processScripts: ['text/html'] }); input = '
    foo$
    '; - test_minify_sync(assert, input, input); - test_minify_sync(assert, input, { decodeEntities: false }, input); + test_minify(assert, input, input); + test_minify(assert, input, input, { decodeEntities: false }); output = '
    foo$
    '; - test_minify_sync(assert, input, { decodeEntities: true }, output); + test_minify(assert, input, output, { decodeEntities: true }); output = '
    foo$
    '; - test_minify_sync(assert, input, { minifyCSS: true }, output); - test_minify_sync(assert, input, { decodeEntities: false, minifyCSS: true }, output); + test_minify(assert, input, output, { minifyCSS: true }); + test_minify(assert, input, output, { decodeEntities: false, minifyCSS: true }); output = '
    foo$
    '; - test_minify_sync(assert, input, { decodeEntities: true, minifyCSS: true }, output); + test_minify(assert, input, output, { decodeEntities: true, minifyCSS: true }); input = 'baz<moo>©'; - test_minify_sync(assert, input, input); - test_minify_sync(assert, input, { decodeEntities: false }, input); + test_minify(assert, input, input); + test_minify(assert, input, input, { decodeEntities: false }); output = 'baz<moo>\u00a9'; - test_minify_sync(assert, input, { decodeEntities: true }, output); + test_minify(assert, input, output, { decodeEntities: true }); input = '&
    &
    '; - test_minify_sync(assert, input, input); - test_minify_sync(assert, input, { collapseWhitespace: false, decodeEntities: false }, input); - test_minify_sync(assert, input, { collapseWhitespace: true, decodeEntities: false }, input); + test_minify(assert, input, input); + test_minify(assert, input, input, { collapseWhitespace: false, decodeEntities: false }); + test_minify(assert, input, input, { collapseWhitespace: true, decodeEntities: false }); output = '&
    &
    '; - test_minify_sync(assert, input, { collapseWhitespace: false, decodeEntities: true }, output); - test_minify_sync(assert, input, { collapseWhitespace: true, decodeEntities: true }, output); + test_minify(assert, input, output, { collapseWhitespace: false, decodeEntities: true }); + test_minify(assert, input, output, { collapseWhitespace: true, decodeEntities: true }); }); QUnit.test('tests from PHPTAL', function(assert) { @@ -3565,7 +3560,7 @@ QUnit.test('tests from PHPTAL', function(assert) { 'foo ' ]*/ ].forEach(function(tokens) { - test_minify_sync(assert, tokens[1], { + test_minify(assert, tokens[1], tokens[0], { collapseBooleanAttributes: true, collapseWhitespace: true, removeAttributeQuotes: true, @@ -3578,7 +3573,7 @@ QUnit.test('tests from PHPTAL', function(assert) { removeTagWhitespace: true, sortAttributes: true, useShortDoctype: true - }, tokens[0]); + }); }); }); @@ -3593,33 +3588,33 @@ QUnit.test('canCollapseWhitespace and canTrimWhitespace hooks', function(assert) var input = '
    foo bar
    '; var output = '
    foo bar
    '; - test_minify_sync(assert, input, { + test_minify(assert, input, output, { collapseWhitespace: true, canTrimWhitespace: canCollapseAndTrimWhitespace, canCollapseWhitespace: canCollapseAndTrimWhitespace - }, output); + }); // Regression test: Previously the first would clear the internal // stackNo{Collapse,Trim}Whitespace, so that ' foo bar' turned into ' foo bar' input = '
    foo bar
    '; output = '
    foo bar
    '; - test_minify_sync(assert, input, { + test_minify(assert, input, output, { collapseWhitespace: true, canTrimWhitespace: canCollapseAndTrimWhitespace, canCollapseWhitespace: canCollapseAndTrimWhitespace - }, output); + }); // Make sure that the stack does get reset when leaving the element for which // the hooks returned false: input = '
    foo bar
    '; output = '
    foo bar
    '; - test_minify_sync(assert, input, { + test_minify(assert, input, output, { collapseWhitespace: true, canTrimWhitespace: canCollapseAndTrimWhitespace, canCollapseWhitespace: canCollapseAndTrimWhitespace - }, output); + }); }); QUnit.test('Async execution', function(assert) { @@ -3652,26 +3647,26 @@ QUnit.test('Async execution', function(assert) { var styleOutput = ''; var scriptOutput = ''; - test_minify_async(assert, input, {}, input); + test_minify(assert, input, input, {}, null, true); output = styleOutput + scriptInput; - test_minify_async(assert, input, { minifyCSS: cssAsync }, output); - test_minify_async(assert, input, { minifyCSS: cssAsync, minifyJS: false }, output); + test_minify(assert, input, output, { minifyCSS: cssAsync }, null, true); + test_minify(assert, input, output, { minifyCSS: cssAsync, minifyJS: false }, null, true); output = styleInput + scriptOutput; - test_minify_async(assert, input, { minifyJS: jsAsync }, output); - test_minify_async(assert, input, { minifyCSS: false, minifyJS: jsAsync }, output); + test_minify(assert, input, output, { minifyJS: jsAsync }, null, true); + test_minify(assert, input, output, { minifyCSS: false, minifyJS: jsAsync }, null, true); output = styleOutput + scriptOutput; - test_minify_async(assert, input, { minifyCSS: cssAsync, minifyJS: jsAsync }, output); - test_minify_async(assert, input, { minifyCSS: cssAsync, minifyJS: jsSync }, output); - test_minify_async(assert, input, { minifyCSS: cssSync, minifyJS: jsAsync }, output); + test_minify(assert, input, output, { minifyCSS: cssAsync, minifyJS: jsAsync }, null, true); + test_minify(assert, input, output, { minifyCSS: cssAsync, minifyJS: jsSync }, null, true); + test_minify(assert, input, output, { minifyCSS: cssSync, minifyJS: jsAsync }, null, true); }); QUnit.test('minify error with callback', function(assert) { var input = '<$unicorn>'; - test_minify_async_error(assert, input, 'Invalid tag name'); + test_minify_error(assert, input, null, null, 'Invalid tag name', true); }); QUnit.test('error in callback', function(assert) { @@ -3682,7 +3677,7 @@ QUnit.test('error in callback', function(assert) { throw error; } - test_minify_async_error(assert, input, { minifyCSS: css }, error); + test_minify_error(assert, input, { minifyCSS: css }, error, null, true); }); QUnit.test('callback called multiple times', function(assert) { From 1a1edc548afb1de6207ed9796f368854a77ed5a2 Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Tue, 24 Apr 2018 22:15:40 +1200 Subject: [PATCH 53/66] Refactored. --- tests/minifier.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/minifier.js b/tests/minifier.js index dcdad2d2..5de14c41 100644 --- a/tests/minifier.js +++ b/tests/minifier.js @@ -1,6 +1,15 @@ /* global minify */ 'use strict'; +QUnit.config.autostart = false; +if (typeof minify === 'undefined') { + self.minify = require('html-minifier').minify; +} + +QUnit.test('`minifiy` exists', function(assert) { + assert.ok(minify); +}); + /** * Converts the options in the given object to use callbacks where possible. * @@ -140,7 +149,7 @@ function test_minify(assert, input, output, inputOptions, description, asyncOnly * * @param {Assert} assert * @param {string} input - * @param {Object} [options] + * @param {Object} [inputOptions] * @param {Error|function(new:Error)|RegExp|function(boolean)} [errorMatcher] * @param {string} [description=input] * @param {boolean} [asyncOnly=false] @@ -223,15 +232,6 @@ function test_minify_error(assert, input, inputOptions, errorMatcher, descriptio }); } -QUnit.config.autostart = false; -if (typeof minify === 'undefined') { - self.minify = require('html-minifier').minify; -} - -QUnit.test('`minifiy` exists', function(assert) { - assert.ok(minify); -}); - QUnit.test('parsing non-trivial markup', function(assert) { var input, output; From 61e5cd9b65f342dc776c83fbdba942a54f9f62cd Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Tue, 24 Apr 2018 22:27:54 +1200 Subject: [PATCH 54/66] Added safety checks and fix bad test. --- tests/minifier.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/tests/minifier.js b/tests/minifier.js index 5de14c41..38bece6e 100644 --- a/tests/minifier.js +++ b/tests/minifier.js @@ -89,6 +89,23 @@ function test_minify(assert, input, output, inputOptions, description, asyncOnly asyncOnly = false; } + // Safety Checks - ensure this function was called with the correct var types. + if (typeof input !== 'string') { + throw new Error('Bad input: ' + input); + } + if (typeof output !== 'string') { + throw new Error('Bad output: ' + output); + } + if (inputOptions !== null && typeof inputOptions !== 'undefined' && typeof inputOptions !== 'object') { + throw new Error('Bad inputOptions: ' + inputOptions); + } + if (typeof description !== 'string') { + throw new Error('Bad description: ' + description); + } + if (typeof asyncOnly !== 'boolean') { + throw new Error('Bad asyncOnly: ' + asyncOnly); + } + // Standard test. if (!asyncOnly) { var descriptionPrefix = 'Standard Test: '; @@ -258,7 +275,7 @@ QUnit.test('parsing non-trivial markup', function(assert) { test_minify(assert, 'foo', 'foo'); test_minify(assert, '

    x', '

    x

    '); - test_minify(assert, '

    x

    ', '

    x

    ', 'trailing quote should be ignored'); + test_minify(assert, '

    x

    ', '

    x

    ', null, 'trailing quote should be ignored'); test_minify(assert, '

    Click me

    ', '

    Click me

    '); test_minify(assert, '', ''); test_minify(assert, '
    [fallback image]
    ', '
    [fallback image]
    '); From 7ef92b4d85058f589688268a7bddb0030a422890 Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Tue, 24 Apr 2018 23:04:45 +1200 Subject: [PATCH 55/66] Switch out assert.throws with test_minify_error --- tests/minifier.js | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/tests/minifier.js b/tests/minifier.js index 38bece6e..016e488b 100644 --- a/tests/minifier.js +++ b/tests/minifier.js @@ -296,9 +296,7 @@ QUnit.test('parsing non-trivial markup', function(assert) { test_minify(assert, input, input); input = '<$unicorn>'; - assert.throws(function() { - minify(input); - }, 'Invalid tag name'); + test_minify_error(assert, input, null, null, 'Invalid tag name'); input = ''; test_minify(assert, input, input); @@ -326,9 +324,7 @@ QUnit.test('parsing non-trivial markup', function(assert) { // https://github.com/kangax/html-minifier/issues/507 input = ''; test_minify(assert, input, input); - assert.throws(function() { - minify(''); - }, 'invalid attribute name'); + test_minify_error(assert, '', null, null, 'invalid attribute name'); // https://github.com/kangax/html-minifier/issues/512 input = ''; test_minify(assert, input, input); - assert.throws(function() { - minify( - '' + ' placeholder="YYYY-MM-DD"' + ' date-range-picker' + ' data-ng-model="vm.value"' + ' data-ng-model-options="{ debounce: 1000 }"' + ' data-ng-pattern="vm.options.format"' + - ' data-options="vm.datepickerOptions">' - ); - }, 'HTML comment inside tag'); + ' data-options="vm.datepickerOptions">', null, null, 'HTML comment inside tag'); input = '
    '; output = '
    '; From b17b970a5269042f8e7f80542d52bb3cc32ad45c Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Thu, 26 Apr 2018 12:55:09 +1200 Subject: [PATCH 56/66] Removed async only option from test_minify. --- tests/minifier.js | 205 ++++++++++++++++++++-------------------------- 1 file changed, 89 insertions(+), 116 deletions(-) diff --git a/tests/minifier.js b/tests/minifier.js index 016e488b..c7fd6b36 100644 --- a/tests/minifier.js +++ b/tests/minifier.js @@ -76,19 +76,13 @@ function convertOptionsCallbacks(options, async) { * @param {string} output * @param {Object} [inputOptions] * @param {string} [description=input] - * @param {boolean} [asyncOnly=false] */ -function test_minify(assert, input, output, inputOptions, description, asyncOnly) { +function test_minify(assert, input, output, inputOptions, description) { // Set default description. if (description === null || typeof description === 'undefined') { description = input; } - // Set default asyncOnly. - if (asyncOnly === null || typeof asyncOnly === 'undefined') { - asyncOnly = false; - } - // Safety Checks - ensure this function was called with the correct var types. if (typeof input !== 'string') { throw new Error('Bad input: ' + input); @@ -102,43 +96,35 @@ function test_minify(assert, input, output, inputOptions, description, asyncOnly if (typeof description !== 'string') { throw new Error('Bad description: ' + description); } - if (typeof asyncOnly !== 'boolean') { - throw new Error('Bad asyncOnly: ' + asyncOnly); - } // Standard test. - if (!asyncOnly) { - var descriptionPrefix = 'Standard Test: '; - assert.equal(minify(input, inputOptions), output, descriptionPrefix + description); - } + assert.equal(minify(input, inputOptions), output, 'Standard Test: ' + description); // Callback tests. - var callbackTests = []; - - if (!asyncOnly) { + var callbackTests = [ // Sync callback test. - callbackTests.push({ + { options: convertOptionsCallbacks(inputOptions, false), async: false, done: assert.async(), descriptionPrefix: 'Synchronous Callback Test: ' - }); - } + }, + // Async callback test. + { + options: convertOptionsCallbacks(inputOptions, true), + async: true, + done: assert.async(), + descriptionPrefix: 'Asynchronous Callback Test: ' + } + ]; - // Async callback test. - callbackTests.push({ - options: asyncOnly ? inputOptions : convertOptionsCallbacks(inputOptions, true), - async: true, - done: assert.async(), - descriptionPrefix: 'Asynchronous Callback Test: ' - }); + // Callbacks should take very long to complete. + assert.timeout(100); // Run callback tests. - assert.timeout(100); callbackTests.forEach(function(test) { - var callbackTestFinished = false; assert.notOk(minify(input, test.options, function(error, result) { - if (!callbackTestFinished) { + if (!test.finished) { var stackTrace = ''; if (error && error instanceof Error) { stackTrace = error.stack; @@ -147,15 +133,15 @@ function test_minify(assert, input, output, inputOptions, description, asyncOnly assert.equal(error, null, test.descriptionPrefix + 'An error occurred - stack trace:\n' + stackTrace); assert.equal(result, output, test.descriptionPrefix + description); - callbackTestFinished = true; + test.finished = true; test.done(); } })); - // If callback test didn't finish synchronously. - if (!callbackTestFinished && !test.async) { + // If callback test didn't finish synchronously when it should have. + if (!(test.finished || test.async)) { assert.ok(false, test.descriptionPrefix + 'Didn\'t finish synchronously.'); - callbackTestFinished = true; + test.finished = true; test.done(); } }); @@ -169,76 +155,69 @@ function test_minify(assert, input, output, inputOptions, description, asyncOnly * @param {Object} [inputOptions] * @param {Error|function(new:Error)|RegExp|function(boolean)} [errorMatcher] * @param {string} [description=input] - * @param {boolean} [asyncOnly=false] */ -function test_minify_error(assert, input, inputOptions, errorMatcher, description, asyncOnly) { +function test_minify_error(assert, input, inputOptions, errorMatcher, description) { // Set default description. if (description === null || typeof description === 'undefined') { description = input; } - // Set default asyncOnly. - if (asyncOnly === null || typeof asyncOnly === 'undefined') { - asyncOnly = false; - } - // Standard test. - var descriptionPrefix = 'Standard Test: '; assert.throws( function() { minify(input, inputOptions); }, errorMatcher, - descriptionPrefix + description + 'Standard Test: ' + description ); // Callback tests. - var callbackTests = []; - - if (!asyncOnly) { + var callbackTests = [ // Sync callback test. - callbackTests.push({ + { options: convertOptionsCallbacks(inputOptions, false), async: false, done: assert.async(), descriptionPrefix: 'Synchronous Callback Test: ' - }); - } + }, + // Async callback test. + { + options: convertOptionsCallbacks(inputOptions, true), + async: true, + done: assert.async(), + descriptionPrefix: 'Asynchronous Callback Test: ' + } + ]; - // Async callback test. - callbackTests.push({ - options: asyncOnly ? inputOptions : convertOptionsCallbacks(inputOptions, true), - async: true, - done: assert.async(), - descriptionPrefix: 'Asynchronous Callback Test: ' - }); + // Callbacks should take very long to complete. + assert.timeout(100); // Run callback tests. callbackTests.forEach(function(test) { - var callbackTestFinished = false; try { - assert.timeout(100); assert.notOk(minify(input, test.options, function(error, result) { - if (!callbackTestFinished) { - assert.ok(error, descriptionPrefix + 'An error should have occurred.'); - assert.ok(error instanceof Error, descriptionPrefix + '"' + error + '" was returned as an error.'); - assert.throws(function() { throw error; }, errorMatcher, descriptionPrefix + description); + if (!test.finished) { + assert.ok(error, test.descriptionPrefix + 'An error should have occurred.'); + assert.ok(error instanceof Error, test.descriptionPrefix + '"' + error + '" was returned as an error.'); + assert.throws(function() { throw error; }, errorMatcher, test.descriptionPrefix + description); assert.notOk(result); - callbackTestFinished = true; + test.finished = true; test.done(); } })); - // If callback test didn't finish synchronously. - if (!callbackTestFinished && !test.async) { + // If callback test didn't finish synchronously when it should have. + if (!(test.finished || test.async)) { assert.ok(false, test.descriptionPrefix + 'Didn\'t finish synchronously.'); - callbackTestFinished = true; + test.finished = true; test.done(); } } catch (error) { - callbackTestFinished = true; + test.finished = true; + + // An error shouldn't be thrown - fail the test. if (error && error instanceof Error) { assert.ok(false, test.descriptionPrefix + 'threw an error - stack trace:\n' + error.stack); } @@ -3626,67 +3605,61 @@ QUnit.test('canCollapseWhitespace and canTrimWhitespace hooks', function(assert) }); }); -QUnit.test('Async execution', function(assert) { - var input, output; - - function cssSync(text, type) { - return (type || 'Normal') + ' CSS'; - } +QUnit.test('minify error with callback', function(assert) { + var input = '<$unicorn>'; - function jsSync(text, inline) { - return inline ? 'Inline JS' : 'Normal JS'; - } + var done = assert.async(); + assert.timeout(100); - function cssAsync(text, type, cb) { - setTimeout(function() { - cb(cssSync(text, type)); - }, 1); + try { + assert.notOk(minify(input, null, function(error, result) { + assert.ok(error, 'An error should have occurred.'); + assert.ok(error instanceof Error, '"' + error + '" was returned as an error.'); + assert.throws(function() { throw error; }, null, 'An error should have been thrown'); + assert.notOk(result); + done(); + })); } - - function jsAsync(text, inline, cb) { - setTimeout(function() { - cb(jsSync(text, inline)); - }, 1); + catch (error) { + // An error shouldn't be thrown - fail the test. + if (error && error instanceof Error) { + assert.ok(false, test.descriptionPrefix + 'threw an error - stack trace:\n' + error.stack); + } + else { + assert.ok(false, test.descriptionPrefix + 'threw an error - "' + error + '"'); + } } - - var styleInput = ''; - var scriptInput = ''; - input = styleInput + scriptInput; - - var styleOutput = ''; - var scriptOutput = ''; - - test_minify(assert, input, input, {}, null, true); - - output = styleOutput + scriptInput; - test_minify(assert, input, output, { minifyCSS: cssAsync }, null, true); - test_minify(assert, input, output, { minifyCSS: cssAsync, minifyJS: false }, null, true); - - output = styleInput + scriptOutput; - test_minify(assert, input, output, { minifyJS: jsAsync }, null, true); - test_minify(assert, input, output, { minifyCSS: false, minifyJS: jsAsync }, null, true); - - output = styleOutput + scriptOutput; - test_minify(assert, input, output, { minifyCSS: cssAsync, minifyJS: jsAsync }, null, true); - test_minify(assert, input, output, { minifyCSS: cssAsync, minifyJS: jsSync }, null, true); - test_minify(assert, input, output, { minifyCSS: cssSync, minifyJS: jsAsync }, null, true); -}); - -QUnit.test('minify error with callback', function(assert) { - var input = '<$unicorn>'; - - test_minify_error(assert, input, null, null, 'Invalid tag name', true); }); QUnit.test('error in callback', function(assert) { var input = ''; - var error = new Error(); + var cssError = new Error(); function css() { - throw error; + throw cssError; } - test_minify_error(assert, input, { minifyCSS: css }, error, null, true); + var done = assert.async(); + assert.timeout(100); + + try { + assert.notOk(minify(input, { minifyCSS: css }, function(error, result) { + assert.ok(error, 'An error should have occurred.'); + assert.ok(error instanceof Error, '"' + error + '" was returned as an error.'); + assert.throws(function() { throw error; }, cssError, cssError + ' should have been thrown'); + assert.notOk(result); + done(); + })); + } + catch (error) { + // An error shouldn't be thrown - fail the test. + if (error && error instanceof Error) { + assert.ok(false, test.descriptionPrefix + 'threw an error - stack trace:\n' + error.stack); + } + else { + assert.ok(false, test.descriptionPrefix + 'threw an error - "' + error + '"'); + } + } }); QUnit.test('callback called multiple times', function(assert) { From fcd3c59bbe6e4c0bcfcdeaf26c625b381877936b Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Thu, 26 Apr 2018 13:17:40 +1200 Subject: [PATCH 57/66] Refactored Task and TaskGroup. --- src/htmlminifier.js | 122 ++++++++++++++++++++++++-------------------- 1 file changed, 68 insertions(+), 54 deletions(-) diff --git a/src/htmlminifier.js b/src/htmlminifier.js index 42ab0ae0..ecd0c97b 100644 --- a/src/htmlminifier.js +++ b/src/htmlminifier.js @@ -842,46 +842,15 @@ function createSortFns(value, options, uidIgnore, uidAttr, cb) { } /** - * Minify HTML. + * A task that may finish either synchronously or asynchronously. * - * @param {string} value - * @param {Object} options - * @param {boolean} partialMarkup - * @param {Callback} cb + * The task will not be executed until explicitly told to. + * + * @class */ -function minify(value, options, partialMarkup, cb) { - if (options.collapseWhitespace) { - value = collapseWhitespace(value, options, true, true); - } - - var buffer = [], - charsPrevTag, - currentChars = '', - hasChars, - currentTag = '', - currentAttrs = [], - stackNoTrimWhitespace = [], - stackNoCollapseWhitespace = [], - optionalStartTag = '', - optionalEndTag = '', - ignoredMarkupChunks = [], - ignoredCustomMarkupChunks = [], - uidIgnore, - uidAttr, - uidPattern; - +var Task = (function() { /** - * Set of tasks to perform. - * - * @type {Array} - */ - var tasks = []; - - /** - * A task. - * * @constructor - * * @param {function(Callback)} task */ function Task(task) { @@ -897,12 +866,23 @@ function minify(value, options, partialMarkup, cb) { this.task(cb); }; + return Task; +})(); + + +/** + * A group of Tasks and or other TaskGroups to execute in series. + * + * The tasks will not be executed until explicitly told to. + * Additional tasks can be added to the group by pushing to the `tasks` array + * property. Do not modify this property once execution was begun. + * + * @class + */ +var TaskGroup = (function() { /** - * A group of Tasks to execute in series. - * * @constructor - * - * @param {Task[]} [tasks] + * @param {Array} [tasks] */ function TaskGroup(tasks) { this.tasks = tasks ? tasks : []; @@ -923,20 +903,16 @@ function minify(value, options, partialMarkup, cb) { (function implementation(index) { if (index < this.tasks.length) { try { - this.tasks[index].exec( - function(error) { - if (error) { - throw error; - } - - if (this.tasks[index].cbExecuted) { - throw new Error('Async completion has already occurred.'); - } - this.tasks[index].cbExecuted = true; - - implementation.call(this, index + 1); - }.bind(this) - ); + this.tasks[index].exec(function(error) { + if (error) { + throw error; + } + if (this.tasks[index].cbExecuted) { + throw new Error('Async completion has already occurred.'); + } + this.tasks[index].cbExecuted = true; + implementation.call(this, index + 1); + }.bind(this)); } catch (error) { cb(error); @@ -947,6 +923,44 @@ function minify(value, options, partialMarkup, cb) { } }.bind(this))(0); }; + return TaskGroup; +})(); + +/** + * Minify HTML. + * + * @param {string} value + * @param {Object} options + * @param {boolean} partialMarkup + * @param {Callback} cb + */ +function minify(value, options, partialMarkup, cb) { + if (options.collapseWhitespace) { + value = collapseWhitespace(value, options, true, true); + } + + var buffer = [], + charsPrevTag, + currentChars = '', + hasChars, + currentTag = '', + currentAttrs = [], + stackNoTrimWhitespace = [], + stackNoCollapseWhitespace = [], + optionalStartTag = '', + optionalEndTag = '', + ignoredMarkupChunks = [], + ignoredCustomMarkupChunks = [], + uidIgnore, + uidAttr, + uidPattern; + + /** + * Set of tasks to perform. + * + * @type {Array} + */ + var tasks = []; // temporarily replace ignored chunks with comments, // so that we don't have to worry what's there. From a2968a0409ab599285d9cfdc3d3699da6c42badd Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Thu, 26 Apr 2018 13:31:20 +1200 Subject: [PATCH 58/66] Fix issue with not all callbacks being in the form of (error, result). --- src/htmlminifier.js | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/src/htmlminifier.js b/src/htmlminifier.js index ecd0c97b..878e0539 100644 --- a/src/htmlminifier.js +++ b/src/htmlminifier.js @@ -265,9 +265,11 @@ function isSrcset(attrName, tag) { function cleanAttributeValue(tag, attrName, attrValue, options, attrs, cb) { if (attrValue && isEventAttribute(attrName, options)) { attrValue = trimWhitespace(attrValue).replace(/^javascript:\s*/i, ''); - attrValue = options.minifyJS(attrValue, true, cb); + attrValue = options.minifyJS(attrValue, true, function(result) { + cb(null, result); + }); if (typeof attrValue !== 'undefined') { - return cb(attrValue); + return cb(null, attrValue); } return; } @@ -279,14 +281,14 @@ function cleanAttributeValue(tag, attrName, attrValue, options, attrs, cb) { else { attrValue = collapseWhitespaceAll(attrValue); } - return cb(attrValue); + return cb(null, attrValue); } else if (isUriTypeAttribute(attrName, tag)) { attrValue = trimWhitespace(attrValue); - return cb(isLinkType(tag, attrs, 'canonical') ? attrValue : options.minifyURLs(attrValue)); + return cb(null, isLinkType(tag, attrs, 'canonical') ? attrValue : options.minifyURLs(attrValue)); } else if (isNumberTypeAttribute(attrName, tag)) { - return cb(trimWhitespace(attrValue)); + return cb(null, trimWhitespace(attrValue)); } else if (attrName === 'style') { attrValue = trimWhitespace(attrValue); @@ -294,13 +296,15 @@ function cleanAttributeValue(tag, attrName, attrValue, options, attrs, cb) { if (/;$/.test(attrValue) && !/&#?[0-9a-zA-Z]+;$/.test(attrValue)) { attrValue = attrValue.replace(/\s*;$/, ';'); } - attrValue = options.minifyCSS(attrValue, 'inline', cb); + attrValue = options.minifyCSS(attrValue, 'inline', function(result) { + cb(null, result); + }); if (typeof attrValue !== 'undefined') { - return cb(attrValue); + return cb(null, attrValue); } return; } - return cb(attrValue); + return cb(null, attrValue); } else if (isSrcset(attrName, tag)) { // https://html.spec.whatwg.org/multipage/embedded-content.html#attr-img-srcset @@ -335,13 +339,15 @@ function cleanAttributeValue(tag, attrName, attrValue, options, attrs, cb) { } else if (isMediaQuery(tag, attrs, attrName)) { attrValue = trimWhitespace(attrValue); - attrValue = options.minifyCSS(attrValue, 'media', cb); + attrValue = options.minifyCSS(attrValue, 'media', function(result) { + cb(null, result); + }); if (typeof attrValue !== 'undefined') { - return cb(attrValue); + return cb(null, attrValue); } return; } - return cb(attrValue); + return cb(null, attrValue); } function isMetaViewport(tag, attrs) { @@ -394,7 +400,7 @@ function processScript(text, options, currentAttrs, cb) { return minify(text, options, false, cb); } } - return cb(text); + return cb(null, text); } // Tag omission rules from https://html.spec.whatwg.org/multipage/syntax.html#optional-tags @@ -561,7 +567,11 @@ function normalizeAttr(attr, attrs, tag, options, cb) { return cb(); } - cleanAttributeValue(tag, attrName, attrValue, options, attrs, function(attrValue) { + cleanAttributeValue(tag, attrName, attrValue, options, attrs, function(error, attrValue) { + if (error) { + return cb(error); + } + if (options.removeEmptyAttributes && canDeleteEmptyAttribute(tag, attrName, attrValue, options)) { return cb(); From f9dee3c2d163207f01729b8098921933cb1dab46 Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Thu, 26 Apr 2018 14:57:16 +1200 Subject: [PATCH 59/66] Moved typedefs below imports. --- src/htmlminifier.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/htmlminifier.js b/src/htmlminifier.js index 878e0539..4fe544c0 100644 --- a/src/htmlminifier.js +++ b/src/htmlminifier.js @@ -1,10 +1,5 @@ 'use strict'; -/** - * A callback that tasks an error and a result. - * @typedef {function([?Error], [string]):void} Callback - */ - var CleanCSS = require('clean-css'); var decode = require('he').decode; var HTMLParser = require('./htmlparser').HTMLParser; @@ -13,6 +8,11 @@ var TokenChain = require('./tokenchain'); var UglifyJS = require('uglify-js'); var utils = require('./utils'); +/** + * A callback that takes an error and a result. + * @typedef {function([?Error], [string]):void} Callback + */ + function trimWhitespace(str) { if (typeof str !== 'string') { return str; From 675d086505a81f41c9b929112277480e3ec01b2f Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Thu, 26 Apr 2018 16:32:16 +1200 Subject: [PATCH 60/66] Fixed 'Maximum call stack size exceeded' in the sync case. --- src/htmlminifier.js | 738 +++++++++++++++++++++++++------------------- 1 file changed, 414 insertions(+), 324 deletions(-) diff --git a/src/htmlminifier.js b/src/htmlminifier.js index 4fe544c0..b0607635 100644 --- a/src/htmlminifier.js +++ b/src/htmlminifier.js @@ -646,10 +646,11 @@ function identity(value) { return value; } -function processOptions(values) { +function processOptions(values, ensureSynchronicity) { var options = { canCollapseWhitespace: canCollapseWhitespace, canTrimWhitespace: canTrimWhitespace, + ensureSynchronicity: ensureSynchronicity, html5: true, ignoreCustomComments: [/^!/], ignoreCustomFragments: [ @@ -861,7 +862,7 @@ function createSortFns(value, options, uidIgnore, uidAttr, cb) { var Task = (function() { /** * @constructor - * @param {function(Callback)} task + * @param {function([Callback])} task */ function Task(task) { this.task = task; @@ -870,9 +871,12 @@ var Task = (function() { /** * Execute this task. * - * @param {Callback} cb + * @param {Callback} [cb] */ Task.prototype.exec = function(cb) { + if (!cb) { + cb = function() {}; + } this.task(cb); }; @@ -945,6 +949,8 @@ var TaskGroup = (function() { * @param {Callback} cb */ function minify(value, options, partialMarkup, cb) { + var topLevelCb = cb; + if (options.collapseWhitespace) { value = collapseWhitespace(value, options, true, true); } @@ -972,6 +978,13 @@ function minify(value, options, partialMarkup, cb) { */ var tasks = []; + /** + * The next task to perform. + * + * @type {Task} + */ + var nextTask; + // temporarily replace ignored chunks with comments, // so that we don't have to worry what's there. // for all we care there might be @@ -1027,9 +1040,15 @@ function minify(value, options, partialMarkup, cb) { if (options.sortAttributes && typeof options.sortAttributes !== 'function' || options.sortClassName && typeof options.sortClassName !== 'function') { - tasks.push(new Task(function(cb) { + nextTask = new Task(function(cb) { createSortFns(value, options, uidIgnore, uidAttr, cb); - })); + }); + if (options.ensureSynchronicity) { + nextTask.exec(); + } + else { + tasks.push(nextTask); + } } function _canCollapseWhitespace(tag, attrs) { @@ -1084,7 +1103,7 @@ function minify(value, options, partialMarkup, cb) { trimTrailingWhitespace(charsIndex, nextTag); } - tasks.push(new Task(function(cb) { + nextTask = new Task(function(cb) { try { var subtasks = []; @@ -1093,395 +1112,462 @@ function minify(value, options, partialMarkup, cb) { html5: options.html5, start: function(tag, attrs, unary, unarySlash, autoGenerated) { - subtasks.push( - new Task(function(cb) { - var lowerTag = tag.toLowerCase(); - - if (lowerTag === 'svg') { - options = Object.create(options); - options.keepClosingSlash = true; - options.caseSensitive = true; - } + nextTask = new Task(function(cb) { + var lowerTag = tag.toLowerCase(); - tag = options.caseSensitive ? tag : lowerTag; + if (lowerTag === 'svg') { + options = Object.create(options); + options.keepClosingSlash = true; + options.caseSensitive = true; + } - currentTag = tag; - charsPrevTag = tag; - if (!inlineTextTags(tag)) { - currentChars = ''; - } - hasChars = false; - currentAttrs = attrs; + tag = options.caseSensitive ? tag : lowerTag; - var optional = options.removeOptionalTags; - if (optional) { - var htmlTag = htmlTags(tag); - // may be omitted if first thing inside is not comment - // may be omitted if first thing inside is an element - // may be omitted if first thing inside is not space, comment, , ,