Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/python | |
| 2 # Copyright 2016 The Chromium Authors. All rights reserved. | |
| 3 # Use of this source code is governed by a BSD-style license that can be | |
| 4 # found in the LICENSE file. | |
| 5 | |
| 6 import sys | |
| 7 import tempfile | |
| 8 from compile2 import Checker | |
| 9 | |
| 10 | |
| 11 closure_args = [ | |
|
Dan Beam
2016/07/25 17:29:16
can we just compose these rather than duplicate th
aberent
2016/07/27 09:46:35
Now using closure_args.gni.
| |
| 12 "compilation_level=WHITESPACE_ONLY", | |
| 13 | |
| 14 "extra_annotation_name=attribute", | |
| 15 "extra_annotation_name=demo", | |
| 16 "extra_annotation_name=element", | |
| 17 "extra_annotation_name=group", | |
| 18 "extra_annotation_name=hero", | |
| 19 "extra_annotation_name=homepage", | |
| 20 "extra_annotation_name=status", | |
| 21 "extra_annotation_name=submodule", | |
| 22 "language_in=ECMASCRIPT6_STRICT", | |
| 23 "language_out=ECMASCRIPT5_STRICT", | |
| 24 | |
| 25 "polymer_pass", | |
| 26 | |
| 27 "source_map_format=V3", | |
| 28 ] | |
| 29 | |
| 30 | |
| 31 def Minify(source): | |
| 32 with tempfile.NamedTemporaryFile(suffix='.js') as t1, tempfile.NamedTemporaryF ile(suffix='.js', delete=False) as t2: | |
|
Dan Beam
2016/07/25 17:29:16
80 col wrap
Dan Beam
2016/07/25 17:29:16
nit: use double quotes (") instead of single quote
Dirk Pranke
2016/07/25 21:12:36
I would actually change everything else to be sing
aberent
2016/07/27 09:46:35
Done. All single quotes.
aberent
2016/07/27 09:46:36
Done.
| |
| 33 t1.write(source) | |
| 34 t1.seek(0) | |
| 35 checker = Checker() | |
| 36 checker.check([t1.name], out_file=t2.name, closure_args=closure_args) | |
| 37 t2.seek(0) | |
| 38 result = t2.read() | |
| 39 return result | |
| 40 | |
|
Dan Beam
2016/07/25 17:29:16
this should be 2 blank lines between top-level glo
aberent
2016/07/27 09:46:36
Done.
| |
| 41 if __name__ == "__main__": | |
| 42 orig_stdout = sys.stdout | |
|
Dan Beam
2016/07/25 17:29:16
you probably want to wrap this in a try/finally, i
aberent
2016/07/27 09:46:35
Done.
| |
| 43 sys.stdout = sys.stderr | |
|
Dan Beam
2016/07/25 17:29:16
why is this stderr/stdout redirection required?
aberent
2016/07/27 09:46:35
In traditional Unix pipeline style (and as I defin
| |
| 44 result = Minify(sys.stdin.read()) | |
| 45 sys.stdout = orig_stdout | |
| 46 print result | |
| 47 | |
| OLD | NEW |