I'm trying to get the closure compiler to inline some of my code wrapped in configuration objects in SIMPLE mode without any type annotations. React does this and managed to bring down bundle sizes
I observed the following:
a.js
(function main() {
const config = {
log(m) {
console.log(m);
}
}
function reconciler(c) {
const log = c.log;
log('jere');
}
reconciler(config);
}())
when compiled returns
a.min.js
(function() {
(function(a) {
a = a.log;
a("jere");
})({
log: function(a) {
console.log(a);
}
});
})();
And,
b.js
(function main() {
const config = {
log(m) {
console.log(m);
}
}
function reconciler(c) {
const log = c.log;
c.log('here');
// log('jere');
}
reconciler(config);
}())
when compiled gives,
b.min.js
(function() {
console.log("here");
})();
On the other hand,
function main(){
const config = {
log: function log(m) {
console.log(m);
}
};
const log = config.log;
log('m');
log('m');
log('m');
log('m');
}
main()
gives
function main() {
console.log("m");
console.log("m");
console.log("m");
console.log("m");
}
main();
How does Closure Compiler inline? Is there is definite way to get it to inline wrapped functions?
--
---
You received this message because you are subscribed to the Google Groups "Closure Compiler Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to closure-compiler-discuss+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/closure-compiler-discuss/1e12da92-0fa9-4646-a258-c4ba77cd7f8c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.