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

Unified Diff: chrome/browser/resources/vulcanize.py

Issue 2252963002: MD WebUI: Strip comments from vulcanized JS files (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@history_vulcanize
Patch Set: Fix comments ending in **/ Created 4 years, 4 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 | « chrome/browser/resources/md_history/app.crisper.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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)
« no previous file with comments | « chrome/browser/resources/md_history/app.crisper.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698