google / google/closure-compiler

WHITESPACE_ONLY mode does non-whitespace-only optimizations

Open
#3,637 7 comments 3 reactions 1 assignee Assigned to @blickly View on GitHub
P2
Dominant language
JavaScript
Stars
7.7k
Forks
1.2k
Avg merge
2d 12h
Merged PRs (30d)
6

Description

Closure compiler v20200614

in.js:
```js
{
function foo(p) { self["external1"](p) }

console.log(foo());
console.log(foo());
}
```

Command: `java -jar ./closure-compiler.jar --js in.js --js_output_file out.js --compilation_level WHITESPACE_ONLY --formatting PRETTY_PRINT`

out.js:
```js
{
var foo = function(p) {
self["external1"](p);
};
console.log(foo());
console.log(foo());
}
;
```

Note that `function foo(p)` was rewritten as `var foo = function(p)`. This is not a whitespace-only change. It also causes a bug (#3623). Therefore even using the lowest tier of WHITESPACE_ONLY optimizations, we cannot escape this bug. I think it is reasonable to expect WHITESPACE_ONLY to only do what it says and not make other adjustments which alter the way scripts work.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.