bazelbuild / bazelbuild/rules_closure
Property quoting compiler pass
- Dominant language
- Java
- Stars
- 159
- Forks
- 111
- PR merge metrics
- No merged PRs in 30d
Description
I was reading what @WebReflection wrote in [5 Reasons To Avoid Closure Compiler In Advanced Mode](http://webreflection.blogspot.com/2013/01/5-reasons-to-avoid-closure-compiler-in.html) back in 2013 and I struck by an idea that might be interesting.
What if `ADVANCED` mode could be specified on a per-library basis?
That way you can link legacy code into your binary without having to turn off _minification uber alles_ for the entire binary. Or using a separate script tag. This should be beneficial to open source users with heterogeneous codebases.
In order for this to work:
1. The library rules would have to propagate the set of primitive source files to the binary rule.
2. A compiler pass would have to be introduced that rewrites primitive source files to quote stuff.
For example, the following primitive file:
``` javascript
window.jeepers = 'creepers';
function madDogsAndEnglishmen() {
function goOutInTheMiddaySun() {
return 'there';
}
return {hi: goOutInTheMiddaySun()};
}
```
``` python
closure_js_library(
name = "primitive_lib",
srcs = ["primitive.js"],
advanced = False,
)
```
Would be rewritten to the following mid-compilation when making the `closure_js_binary`:
``` javascript
goog.global['window']['jeepers'] = 'creepers';
goog.global['madDogsAndEnglishmen'] = function() {
function goOutInTheMiddaySun() {
return 'there';
}
return {'hi': goOutInTheMiddaySun()};
}
```
Has something like this been considered before @MatrixFrog? I poked through the jscomp codebase real quick and didn't see any passes that auto-quote properties.
CC: @hochhaus
Contributor guide
Assessment
This issue has not been assessed yet.