opacify.pl 859 B

1234567891011121314151617181920212223242526272829303132
  1. #!/usr/bin/env perl
  2. # This script is a hack.
  3. #
  4. # Opacify all non-private names by turning them into strings.
  5. # That way, the Google compressor won't rename them.
  6. #
  7. # The script ignores properties whose names begin with _, because they
  8. # are believed to be private.
  9. #
  10. # XXX TODO FIXME: this messes with strings, so it screws up exceptions.
  11. my $script = join '', <>;
  12. # remove comments
  13. $script =~ s=/\*([^\*]|\*+[^\/])*\*/==g;
  14. $script =~ s=//.*==g;
  15. # stringify property names
  16. $script =~ s=\.([a-zA-Z0-9][_a-zA-Z0-9]*)=['$1']=g;
  17. # stringify sjcl
  18. $script =~ s=(?:var\s+)?sjcl(\.|\s*\=)=window['sjcl']$1=g;
  19. # stringify object notation
  20. $script =~ s=([\{,]\s*)([a-zA-Z0-9][_a-zA-Z0-9]*):=$1'$2':=g;
  21. # Export sjcl. This is a bit of a hack, and might get replaced later.
  22. print $script;
  23. # not necessary with windowization.
  24. # print "window\['sjcl'\] = sjcl;\n";