javascript - How can I tell Google closure compiler to not remove a var -


i have following code:

// ==closurecompiler== // @output_file_name default.js // @compilation_level advanced_optimizations // ==/closurecompiler==  var l = window.location; var s = 'hash'; l[s] = 'whatever need now'; 

which gets compiled google closure compiler (advanced mode) this:

window.location.hash="whatever need now"; 

but in case need keep using l[s]= ... in compiled code.

is there way tell compiler keep using var or ignore couple of lines?

compiler in action - demo

it's small hack hash function work junos pulse.

i'm having lot of trouble believing hack necessary, but:

// ==closurecompiler== // @output_file_name default.js // @compilation_level advanced_optimizations // ==/closurecompiler==  eval( "var l = window.location;\n" + "var s = 'hash';\n" + "l[s] = 'whatever need now';\n" ); 

*hack* *cough* :-)

or:

// ==closurecompiler== // @output_file_name default.js // @compilation_level advanced_optimizations // ==/closurecompiler==  sessionstorage.x = "hash"; window.location[sessionstorage.x] = 'whatever need now'; 

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -