Re: [closure-compiler-discuss] Compile with ADVANCED_OPTIMIZATIONS help needed please.

39 views
Skip to first unread message

Ilia Mirkin

unread,
Apr 16, 2013, 1:41:27 PM4/16/13
to closure-comp...@googlegroups.com
1. Get rid of the anonymous functions -- they just mess things up in
my experience. If you want the output wrapped, use
--output_wrapper='(function(){%output%})()' (or your favourite one
including window and/or document and/or undefined...). That will
actually wrap the output of the compiler. Right now, that is not
something that's happening, since closure compiler will add code of
its own to the output in advanced mode. And things like window.Main =
Main become unnecessary.

2. You're missing annotations. Things like /** @constructor */.

3. paddle.someUseMethod will try to get it on Paddle.prototype, not on
the Paddle. I'm surprised this works in simple mode.

4. On your page, main.init() will not work, since init is likely to
have been renamed. You need to export that property, e.g.
goog.exportProperty(Main.prototype, 'init', Main.prototype.init);

On Tue, Apr 16, 2013 at 1:29 PM, Adam Holland <adgho...@gmail.com> wrote:
> Hi, I'm trying to learn how to use the compiler.
>
> I can get it to work with simple optimisations but not with the advanced
> mode. If someone could tell me what I am doing wrong I would be very
> grateful.
>
> I am using a simple test to try and get things working, here is my code:
>
> // main.js
> ------------------------------------------------------------------------------------
>
>
> goog.require('Test.Paddle');
>
>
> goog.provide('Test.Main');
>
>
> (function ( window ) {
>
> "use strict";
>
>
> function Main () {
>
> }
>
>
> Main.prototype.init = function(){
>
> alert( "MAIN" );
>
> var paddle = new Paddle();
>
> paddle.someUsedMethod();
>
> };
>
>
> window.Main = Main;
>
> })( window );
>
>
> goog.exportSymbol('Test.Main', Main);
>
>
> //
> -------------------------------------------------------------------------------------------------
>
>
>
>
>
> // paddle.js
> ------------------------------------------------------------------------------------
>
>
> goog.provide('Test.Paddle');
>
>
> (function ( window ) {
>
> "use strict";
>
>
> function Paddle() {
>
> }
>
>
> Paddle.someUsedMethod = function () {
>
> alert( "HEY THIS IS A PADDLE" );
>
> };
>
>
> window.Paddle = Paddle;
>
> })( window );
>
>
>
> //
> -------------------------------------------------------------------------------------------------
>
>
> Then in my html I have a script tag that creates a "main":
>
> <script>
> var main = new Test.Main();
> main.init();
> </script>
>
>
>
> So this works with simple_optimizations or with the "base.js" loader and
> "deps.js" file but not with ADVANCED_OPTIMIZATIONS, I am not exporting any
> symbols apart from the Main, this is because I am trying to access it
> externally. Is that correct?
>
> Thanks for any help, Adam
>
>
> --
>
> ---
> 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.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Adam Holland

unread,
Apr 16, 2013, 3:50:10 PM4/16/13
to closure-comp...@googlegroups.com, imi...@alum.mit.edu
Hey thanks for the reply and info.

1. I will try without the anon functions.
2. will add some jsdocs
3. this is a typo and will fix.
4. I didnt realise a method was a 'property', will add it.

Thanks, il make some changes and post with results.

Ilia Mirkin

unread,
Apr 16, 2013, 4:14:29 PM4/16/13
to closure-comp...@googlegroups.com
If you're just getting started with closure library, I would recommend
reading over some of the core functions in base.js -- that should shed
some light on what they do, and will hopefully inform you on how to
use them; I've found it all to be quite readable. For example,
goog.exportProperty(a,b,c) is basically a[b]=c. Some of them have
special implementations in the compiler, but those implementations
will match the js ones in spirit.
>> > email to closure-compiler-d...@googlegroups.com.
>> > For more options, visit https://groups.google.com/groups/opt_out.
>> >
>> >
>
> --
>
> ---
> 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.

Adam Holland

unread,
Apr 17, 2013, 9:47:49 AM4/17/13
to closure-comp...@googlegroups.com, imi...@alum.mit.edu
Thanks for all the help. I have it all working now with externs too.

Just a quick note, im running a bat file and found a few things I thought i would share:
- if compiler flags have white space they need to be specified as two flags eg: --compiler_flags="--create_source_map" --compiler_flags="source_map.map"
- to use the "%OUTPUT% in a wrapper you need to wrap that, e.g. --compiler_flags="--output_wrapper"  --compiler_flags="(function() {%%output%%})();"

Thanks, now im onto automating the process... 
>> > For more options, visit https://groups.google.com/groups/opt_out.
>> >
>> >
>
> --
>
> ---
> 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

Ilia Mirkin

unread,
Apr 17, 2013, 2:15:30 PM4/17/13
to Adam Holland, closure-comp...@googlegroups.com
On Wed, Apr 17, 2013 at 9:47 AM, Adam Holland <adgho...@gmail.com> wrote:
> Thanks for all the help. I have it all working now with externs too.
>
> Just a quick note, im running a bat file and found a few things I thought i
> would share:
> - if compiler flags have white space they need to be specified as two flags
> eg: --compiler_flags="--create_source_map" --compiler_flags="source_map.map"

FTR, you could just do
--compiler_flags="--create_source_map=source_map.map" if that's more
intuitive. Both separate arguments and the = sign should be accepted.
Reply all
Reply to author
Forward
0 new messages