Javascript minification failed. Couldn't minify; stripping leading and trailing whitespace.

88 views
Skip to first unread message

Mahyar Damavand

unread,
Jun 19, 2023, 5:33:54 AM6/19/23
to mod-pagespeed-discuss
I got `Javascript minification failed` on an external javascript. when I followed up and removed extra lines, I found that parser fails to pars this code snippet:
```
(n) => {
    if (n==3) {
    }
}
```

this is the output:
```
user@ubuntu-apache-test:~$ pagespeed_js_minify /tmp/file.js
Error: /tmp/file.js: Couldn't minify; stripping leading and trailing whitespace.

Error: /tmp/tttt: Couldn't minify; stripping leading and trailing whitespace.

(n) => {
    if (n==3) {
    }
}
```
is there any problem with arrow functions?

Joshua Marantz

unread,
Jun 19, 2023, 7:49:26 AM6/19/23
to mod-pagesp...@googlegroups.com
I wasn't aware of that limitation. Does it work if you terminate the assignment statement with a semi-colon?

(n) => {
    if (n==3) {
    }
};


--
You received this message because you are subscribed to the Google Groups "mod-pagespeed-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mod-pagespeed-di...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mod-pagespeed-discuss/2d02fff6-7670-42dd-b474-c07dc0405417n%40googlegroups.com.

Mahyar Damavand

unread,
Jun 20, 2023, 5:46:26 AM6/20/23
to mod-pagesp...@googlegroups.com
Sorry, there's no assignment here. if you have a double check, you'll see an arrow function and an if statement. no semicolon needed. 
In addition the only way I was able to fix it, was when I changed the arrow function to a traditional function.

You received this message because you are subscribed to a topic in the Google Groups "mod-pagespeed-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mod-pagespeed-discuss/lhFYaVwrzmM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mod-pagespeed-di...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mod-pagespeed-discuss/CAGKR%2BEDYtdP%2BTJn90ifeH8C8JMt-UHik%2B2BVN9fHJN2j1tsYfw%40mail.gmail.com.


--

مهیار دماوند
Mahyar Damavand
---------------------------

Mahyar Damavand

unread,
Jun 20, 2023, 6:00:13 AM6/20/23
to mod-pagesp...@googlegroups.com
I noticed your example and the semicolon you added to my code and did these checks:
```
user@ubuntu-apache-test:~$ pagespeed_js_minify /tmp/file.js
Error: /tmp/file.js: Couldn't minify; stripping leading and trailing whitespace.

(n) => {
    if (n==3) {
    }
};
user@ubuntu-apache-test:~$ pagespeed_js_minify /tmp/file.js
Error: /tmp/file.js: Couldn't minify; stripping leading and trailing whitespace.

let mf = (n) => {
    if (n==3) {
    }
};
```
 
Reply all
Reply to author
Forward
0 new messages