need help with output_wrapper

67 views
Skip to first unread message

Erik Neumann

unread,
Feb 13, 2016, 3:02:45 PM2/13/16
to Closure Compiler Discuss
Two years ago I reported a performance issue:  https://github.com/google/closure-compiler/issues/171

The fix (recently found) is to tell the compiler

--output_wrapper="'(function() {%output%})()'"

This does solve the test case performance problem.  But trying to use it in my production code I'm getting errors at runtime.  The first error is

TypeError: undefined is not an object (evaluating 'goog.global.navigator')

I'm guessing that the globals like "goog" are not being created because of the output wrapper.  

So, I'm wondering what to do. Should I file a new issue about this?  Or is there some simple fix?


John Lenz

unread,
Feb 14, 2016, 12:17:58 AM2/14/16
to closure-compiler

Generally the output wrapper work for whole world builds.  For strict mode, you need to supply the proper "this" but you don't indicate that you are using strict mode.  Is there more information you can provide?

--

---
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-d...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/closure-compiler-discuss/3a5db101-da68-4bb2-8b80-99e502bad514%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Erik Neumann

unread,
Feb 14, 2016, 6:57:03 PM2/14/16
to closure-comp...@googlegroups.com
I am using strict mode and the solution is to provide "this" as follows:

--output_wrapper="'(function() {%output%}).call(window)'" \

With that in place it is all working now.

Is it a problem that the 'use strict' statement is no longer the first statement in the file?  It is now inside the wrapping function, so I guess that will also work.  But I think that with the flag

--language_in=ECMASCRIPT5_STRICT \

then the 'use strict' should appear outside of the wrapping function as the first statement?

Here is the start of my advance-compiled program:

(function() {'use strict';var h,aa=this;function r(a){return void 0!==a}function 

--ErikN


John Lenz

unread,
Feb 16, 2016, 1:12:24 AM2/16/16
to closure-compiler

Yes, the strict applies to the function which is what you want.

Reply all
Reply to author
Forward
0 new messages