From: alexlamsl Date: Mon, 13 Mar 2017 19:24:42 +0000 (+0800) Subject: fix minifyJS on event attributes X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=f3031a275cf110e1620c0fd81f1a0a99fa11fa60;p=html-minifier.git fix minifyJS on event attributes latest `uglify-js` has advanced side-effect-free optimisation which invalidates an old hack fixes #792 --- diff --git a/src/htmlminifier.js b/src/htmlminifier.js index 18118aa..3fa6700 100644 --- a/src/htmlminifier.js +++ b/src/htmlminifier.js @@ -615,9 +615,6 @@ function identity(value) { return value; } -var fnPrefix = '!function(){'; -var fnSuffix = '}();'; - function processOptions(options) { ['html5', 'includeAutoGeneratedTags'].forEach(function(key) { if (!(key in options)) { @@ -681,17 +678,13 @@ function processOptions(options) { } minifyJS.fromString = true; (minifyJS.output || (minifyJS.output = {})).inline_script = true; + (minifyJS.parse || (minifyJS.parse = {})).bare_returns = false; options.minifyJS = function(text, inline) { var start = text.match(/^\s*\s*$/, '') : text; try { - if (inline) { - code = fnPrefix + code + fnSuffix; - } + minifyJS.parse.bare_returns = inline; code = UglifyJS.minify(code, minifyJS).code; - if (inline) { - code = code.slice(fnPrefix.length, -fnSuffix.length); - } if (/;$/.test(code)) { code = code.slice(0, -1); } diff --git a/tests/minifier.js b/tests/minifier.js index 7b7bec6..c39e3d8 100644 --- a/tests/minifier.js +++ b/tests/minifier.js @@ -1931,7 +1931,7 @@ QUnit.test('script minification', function(assert) { assert.equal(minify(input, { minifyJS: true }), output); input = ''; - output = ''; + output = ''; assert.equal(minify(input, { minifyJS: { mangle: false } }), output);