Closure-compiler: Haywired ?

Created on 7 May 2018  路  6Comments  路  Source: google/closure-compiler

Google closure-compiler goes a bit haywire for stuff like this :

input :

const SomeFunc = (i,k,x) => i * i + k * x
console.log(someFunc(2))
someFunc(3)
someFunc(10)
someFunc(21)
someFunc(123)
someFunc(12314)
someFunc(123144)

Output :

console.log(someFunc(2));someFunc(3);someFunc(10);someFunc(21);someFunc(123);someFunc(12314);someFunc(123144);

The only happens when I run this on advanced optimization

On a side note : ES5+ is not supported even though we are now well on our way to ES9 ? (Kindly implement some basic ES6 functionalities).

For now this happens :

const xyz = () => // the whole code you know what

compiles to

var xyz = function() {};

Similarly spread operators , string literals or any other ES5+ functionality is not supported at all.

All 6 comments

In your example, the function name is capitalized inconsistently (SomeFunc vs someFunc).

To enable ES6 output, set e.g. a --language_out ECMASCRIPT_2015 flag (or the @language_out ECMASCRIPT_2015 option in https://closure-compiler.appspot.com).

@tjgq :
So closure compiler won't accept functions with inconsistent capitalization ?

is there a reason for that ? (Just cruious)

Thanks for informing me of that

It's not about Closure, it's just JS. Identifiers are case sensitive.

@lazarljubenovic :

What does JS being case sensitive got anything to do with Closure , closure is compressing the code not finding the grammar mistake in it

Closure sees that you do not use SomeFunc, so it removes it. It analyzes the code and in order to minify is properly it has to be correct JavaScript. It's done exactly what it was supposed to do in your example.

@lazarljubenovic : My bad I didn't see it thanks. :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ChadKillingsworth picture ChadKillingsworth  路  5Comments

zzo picture zzo  路  6Comments

an3ss picture an3ss  路  4Comments

joscha picture joscha  路  5Comments

sam6321 picture sam6321  路  3Comments