closure-compiler icon indicating copy to clipboard operation
closure-compiler copied to clipboard

Missed IIFE inlining opportunity

Open chadaustin opened this issue 10 years ago • 4 comments

Given this code:

(function() {
  var $fun;
  var $str;
  (function() {
    $fun = function(a) {
      return console.log(a);
    };
    $str = "hello";
  })();
  (function() {
    $fun($str);
  })();
})();

It could be inlined all the way to:

console.log("hello");

However, Closure Compiler today only reduces that to:

(function() {
  var a, b;
  (function() {
    a = function(a) {
      return console.log(a);
    };
    b = "hello";
  })();
  a(b);
})();

chadaustin avatar Mar 22 '16 06:03 chadaustin

Fixed by https://github.com/google/closure-compiler/commit/ef9ff6433890d76eb9bc66148cc02c7dd0f96517.

Dominator008 avatar Mar 30 '16 02:03 Dominator008

This doesn't seem to be fixed yet, at least on the online playground, or in the latest maven package (v20160713).

That is, the specific example I gave still doesn't get inlined all the way down. Any ideas why?

chadaustin avatar Jul 27 '16 06:07 chadaustin

The change was rolled back at commit 0660acdb4691cade499563c663a2c83243d0c4b2.

dimvar avatar Jul 27 '16 16:07 dimvar

This is a missed optimisation I'm noticing most often in our projects as well.

RReverser avatar Oct 08 '25 11:10 RReverser