Remove initial whitespace & empty lines to decrease JS files size
Patch will decrease size of JS files included into Chrome APK (about 11 KB now) Bug: Change-Id: I701c9904fbf22fd295199f255601dea6524a3766 Reviewed-on: https://chromium-review.googlesource.com/821071 Reviewed-by: Michael Achenbach <machenbach@chromium.org> Commit-Queue: Marcin Wiącek <marcin@mwiacek.com> Cr-Commit-Position: refs/heads/master@{#50179}
This commit is contained in:
parent
c3dda0bbac
commit
6e174eb826
1
AUTHORS
1
AUTHORS
@ -96,6 +96,7 @@ Luis Reis <luis.m.reis@gmail.com>
|
||||
Luke Zarko <lukezarko@gmail.com>
|
||||
Maciej Małecki <me@mmalecki.com>
|
||||
Marcin Cieślak <saper@marcincieslak.com>
|
||||
Marcin Wiącek <marcin@mwiacek.com>
|
||||
Mateusz Czeladka <mateusz.szczap@gmail.com>
|
||||
Mathias Bynens <mathias@qiwi.be>
|
||||
Matt Hanselman <mjhanselman@gmail.com>
|
||||
|
@ -50,10 +50,12 @@ def ToCArray(byte_sequence):
|
||||
return textwrap.fill(joined, 80)
|
||||
|
||||
|
||||
def RemoveCommentsAndTrailingWhitespace(lines):
|
||||
def RemoveCommentsEmptyLinesAndWhitespace(lines):
|
||||
lines = re.sub(r'\n+', '\n', lines) # empty lines
|
||||
lines = re.sub(r'//.*\n', '\n', lines) # end-of-line comments
|
||||
lines = re.sub(re.compile(r'/\*.*?\*/', re.DOTALL), '', lines) # comments.
|
||||
lines = re.sub(r'\s+\n+', '\n', lines) # trailing whitespace
|
||||
lines = re.sub(r'\s+\n', '\n', lines) # trailing whitespace
|
||||
lines = re.sub(r'\n\s+', '\n', lines) # initial whitespace
|
||||
return lines
|
||||
|
||||
|
||||
@ -342,7 +344,7 @@ def BuildFilterChain(macro_filename, message_template_file):
|
||||
filter_chain.append(lambda l: ExpandConstants(l, message_templates))
|
||||
|
||||
filter_chain.extend([
|
||||
RemoveCommentsAndTrailingWhitespace,
|
||||
RemoveCommentsEmptyLinesAndWhitespace,
|
||||
ExpandInlineMacros,
|
||||
ExpandInlineConstants,
|
||||
Validate,
|
||||
@ -355,7 +357,7 @@ def BuildFilterChain(macro_filename, message_template_file):
|
||||
return reduce(chain, filter_chain)
|
||||
|
||||
def BuildExtraFilterChain():
|
||||
return lambda x: RemoveCommentsAndTrailingWhitespace(Validate(x))
|
||||
return lambda x: RemoveCommentsEmptyLinesAndWhitespace(Validate(x))
|
||||
|
||||
class Sources:
|
||||
def __init__(self):
|
||||
|
Loading…
Reference in New Issue
Block a user