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

Unified Diff: tools/jsmin.py

Issue 1109343004: Wrap v8natives.js into a function. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: alpha sort Created 5 years, 8 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 | « test/mjsunit/compiler/jsnatives.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/jsmin.py
diff --git a/tools/jsmin.py b/tools/jsmin.py
index 250dea9d72bf2f6e2780c3368d7891d1efdc3278..cadc98b25897b30441236f790169adf4debe7d4d 100644
--- a/tools/jsmin.py
+++ b/tools/jsmin.py
@@ -100,6 +100,12 @@ class JavaScriptMinifier(object):
The string that should replace the match in the rewritten program.
"""
matched_text = m.group(0)
+
+ if matched_text.startswith("`") and matched_text.endswith("`"):
+ return re.sub(r"\$\{([\w$%]+)\}",
+ lambda m: '${' + self.FindNewName(m.group(1)) + '}',
+ matched_text)
+
if matched_text == "{":
self.Push()
return matched_text
@@ -152,6 +158,9 @@ class JavaScriptMinifier(object):
return self.map[var_name]
if self.nesting == 0:
return var_name
+ # Do not rename arguments object.
+ if var_name == 'arguments':
+ return 'arguments'
while True:
identifier_first_char = self.identifier_counter % 52
identifier_second_char = self.identifier_counter // 52
@@ -184,6 +193,8 @@ class JavaScriptMinifier(object):
return entire_match
if re.match(r'".*"$', entire_match):
return entire_match
+ if re.match(r"`.*`$", entire_match):
+ return entire_match
if re.match(r"/.+/$", entire_match):
return entire_match
return replacement
@@ -227,8 +238,10 @@ class JavaScriptMinifier(object):
# This regexp can handle embedded backslash-escaped characters including
# embedded backslash-escaped double quotes.
double_quoted_string = r'"(?:[^"\\]|\\.)*"'
- # A regexp that matches a literal string surrounded by 'double quotes'.
+ # A regexp that matches a literal string surrounded by 'single quotes'.
single_quoted_string = r"'(?:[^'\\]|\\.)*'"
+ # A regexp that matches a template string
+ template_string = r"`(?:[^'\\]|\\.)*`"
# A regexp that matches a regexp literal surrounded by /slashes/.
# Don't allow a regexp to have a ) before the first ( since that's a
# syntax error and it's probably just two unrelated slashes.
@@ -238,6 +251,7 @@ class JavaScriptMinifier(object):
# Replace multiple spaces with a single space.
line = re.sub("|".join([double_quoted_string,
single_quoted_string,
+ template_string,
slash_quoted_regexp,
"( )+"]),
self.RemoveSpaces,
@@ -246,6 +260,7 @@ class JavaScriptMinifier(object):
# and after the space. % and $ are counted as identifier characters.
line = re.sub("|".join([double_quoted_string,
single_quoted_string,
+ template_string,
slash_quoted_regexp,
r"(?<![a-zA-Z_0-9$%]) | (?![a-zA-Z_0-9$%])()"]),
self.RemoveSpaces,
@@ -269,6 +284,7 @@ class JavaScriptMinifier(object):
variable_use_regexp = r"(?<![.\w$%])[\w$%]+" + block_trailing_colon
line = re.sub("|".join([double_quoted_string,
single_quoted_string,
+ template_string,
slash_quoted_regexp,
r"\{", # Curly braces.
r"\}",
« no previous file with comments | « test/mjsunit/compiler/jsnatives.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698