Is it possible to make Google Closure compiler *not* inline certain functions?

前端 未结 2 412
悲&欢浪女
悲&欢浪女 2021-02-09 08:05

Closure compiler is inlining a function, but the code size is smaller if that function is not inlined (I only care about code size - this is for JS1k). Can I tell the compiler t

2条回答
  •  南方客
    南方客 (楼主)
    2021-02-09 08:53

    This is an old question, but as of v20180101, Google Closure Compiler has an annotation that prevents inlining: @noinline.

    In your original example, all you'd need is to add jsdoc with this annotation in front of the function that shouldn't be inlined:

    /** @noinline */
    function hello(name) {
      alert('Hello, ' + name);
    }
    hello('New user');
    

提交回复
热议问题