html-minifier icon indicating copy to clipboard operation
html-minifier copied to clipboard

Minifier fails to parse a JavaScript for loop

Open ackh opened this issue 4 years ago • 2 comments

Minifying the following JavaScript code

"use strict";

function test() {
  for(let i = 0; i < arguments.length; i++) {
    console.log("Argument " + i + " : " + arguments[i]);
  }
}

test();

using the following command line call:

/usr/local/bin/html-minifier --collapse-whitespace \
                             --remove-comments \
                             --remove-optional-tags \
                             --remove-redundant-attributes \
                             --remove-script-type-attributes \
                             --remove-tag-whitespace \
                             --use-short-doctype \
                             --minify-css true \
                             --minify-js true \
                             --output test.min.js \
                             test.js

fails with the following error:

Minification error:
Parse Error: < arguments.length; i++) {
  for(let i = 0; i < arguments.length; i++) {
    console.log("Argument " + i + " : " + arguments[i]);
  }
}

As far as I can tell the code should minify but simply does not.

ackh avatar Mar 05 '21 10:03 ackh

Have same issue. Code: for (let row = 0; row < mapa.length; row++) {

Error: Parse Error: < mapa.length; row++) {

html-minifier \
--collapse-whitespace \
--remove-comments \
--remove-optional-tags \
--remove-redundant-attributes \
--remove-script-type-attributes \
--remove-tag-whitespace \
--use-short-doctype \
--minify-css true \
--minify-js true \
-o docs\script.js \
src\script.js

agentgoblin avatar May 01 '23 05:05 agentgoblin

This package can't handle ES6. You should look at html-minifier-terser instead.

R4356th avatar May 01 '23 16:05 R4356th