Chromium Code Reviews| Index: chrome/browser/resources/vulcanize.py |
| diff --git a/chrome/browser/resources/vulcanize.py b/chrome/browser/resources/vulcanize.py |
| index d2773161da0bc23add7d1747bd3eca15184fc6ff..1d5aa17309d23c111d4813dab1399ed69772d437 100755 |
| --- a/chrome/browser/resources/vulcanize.py |
| +++ b/chrome/browser/resources/vulcanize.py |
| @@ -4,6 +4,7 @@ |
| # found in the LICENSE file. |
| import os |
| +import re |
| import subprocess |
| import sys |
| import tempfile |
| @@ -49,6 +50,31 @@ _VULCANIZE_BASE_ARGS = [ |
| ] |
| +def _strip_js_comments(filename): |
| + start_comment = re.compile(r'^ */\*\*?$') |
| + end_comment = re.compile(r'^ *\*\*?/$') |
| + single_line_comment = re.compile(r'^ *//') |
| + keep_comment = re.compile(r'Copyright|license|LICENSE|\<\/?if') |
|
michaelpg
2016/08/17 07:39:56
ugh, grit works inside comments? what about
//
tsergeant
2016/08/17 07:57:52
The commented-if is used in one place in util.js.
|
| + |
| + with open(filename) as f: |
| + contents = f.readlines() |
| + |
| + out_lines = [] |
| + inside_comment = False |
| + |
| + for line in contents: |
| + if not inside_comment: |
| + if start_comment.match(line): |
| + inside_comment = True |
| + elif not single_line_comment.match(line) or keep_comment.search(line): |
| + out_lines.append(line) |
| + elif end_comment.match(line): |
| + inside_comment = False |
| + |
| + with open(filename, 'w') as f: |
| + f.writelines(out_lines) |
| + |
| + |
| def _vulcanize(directory, host, html_in_file, html_out_file='vulcanized.html', |
| js_out_file='crisper.js', extra_args=None): |
| def _run_cmd(cmd_parts, stdout=None): |
| @@ -85,6 +111,8 @@ def _vulcanize(directory, host, html_in_file, html_out_file='vulcanized.html', |
| '--script-in-head', 'false', |
| '--html', html_out_path, |
| '--js', js_out_path]) |
| + |
| + _strip_js_comments(js_out_path) |
| finally: |
| os.remove(tmp.name) |