Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(29)

Unified Diff: tools/js2c.py

Issue 19013: Further minify non-visible JavaScript. (Closed)
Patch Set: Add to LICENSE Created 11 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/mirror-delay.js ('k') | tools/jsmin.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/js2c.py
diff --git a/tools/js2c.py b/tools/js2c.py
index d568556ebfcd7df11df10051188cb8ff7635b770..0ae1ad91df6d4e6220b1293aac12f5c8dc7dd034 100755
--- a/tools/js2c.py
+++ b/tools/js2c.py
@@ -32,6 +32,7 @@
# library.
import os, re, sys, string
+import jsmin
def ToCArray(lines):
@@ -44,7 +45,12 @@ def ToCArray(lines):
return ", ".join(result)
-def CompressScript(lines):
+def CompressScript(lines, do_jsmin):
+ # If we're not expecting this code to be user visible, we can run it through
+ # a more aggressive minifier.
+ if do_jsmin:
+ return jsmin.jsmin(lines)
+
# Remove stuff from the source that we don't want to appear when
# people print the source code using Function.prototype.toString().
# Note that we could easily compress the scripts mode but don't
@@ -272,9 +278,10 @@ def JS2C(source, target, env):
for s in modules:
delay = str(s).endswith('-delay.js')
lines = ReadFile(str(s))
+ do_jsmin = lines.find('// jsminify this file, js2c: jsmin') != -1
lines = ExpandConstants(lines, consts)
lines = ExpandMacros(lines, macros)
- lines = CompressScript(lines)
+ lines = CompressScript(lines, do_jsmin)
data = ToCArray(lines)
id = (os.path.split(str(s))[1])[:-3]
if delay: id = id[:-6]
« no previous file with comments | « src/mirror-delay.js ('k') | tools/jsmin.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698