handle `clean-css` errors correctly (#955)
authorFelipe Matos Santana <felipems@yahoo.com.br>
Thu, 23 Aug 2018 07:25:24 +0000 (04:25 -0300)
committerAlex Lam S.L <alexlamsl@gmail.com>
Thu, 23 Aug 2018 07:25:24 +0000 (15:25 +0800)
Latest version of `clean-css` no longer throws processing errors.

src/htmlminifier.js

index ecf06eb..9fe9e07 100644 (file)
@@ -664,13 +664,12 @@ function processOptions(values) {
         text = text.replace(/(url\s*\(\s*)("|'|)(.*?)\2(\s*\))/ig, function(match, prefix, quote, url, suffix) {
           return prefix + quote + options.minifyURLs(url) + quote + suffix;
         });
-        try {
-          return unwrapCSS(new CleanCSS(value).minify(wrapCSS(text, type)).styles, type);
-        }
-        catch (err) {
-          options.log(err);
+        var cleanCssOutput = new CleanCSS(value).minify(wrapCSS(text, type));
+        if (cleanCssOutput.errors.length > 0) {
+          cleanCssOutput.errors.forEach(options.log);
           return text;
         }
+        return unwrapCSS(cleanCssOutput.styles, type);
       };
     }
     else if (key === 'minifyJS' && typeof value !== 'function') {