Index: third_party/closure_compiler/compile.py |
diff --git a/third_party/closure_compiler/compile.py b/third_party/closure_compiler/compile.py |
index f39f94f3380c79cd5fa224763685863a7f55d20f..ced4733b052dfb2db06953fd1b0acebd23e297c4 100755 |
--- a/third_party/closure_compiler/compile.py |
+++ b/third_party/closure_compiler/compile.py |
@@ -25,67 +25,6 @@ class Checker(object): |
"""Runs the Closure compiler on given source files to typecheck them |
and produce minified output.""" |
- _COMMON_JSCOMP_ERRORS = [ |
- "accessControls", |
- "ambiguousFunctionDecl", |
- "checkStructDictInheritance", |
- "checkTypes", |
- "checkVars", |
- "constantProperty", |
- "deprecated", |
- "externsValidation", |
- "globalThis", |
- "invalidCasts", |
- "missingProperties", |
- "missingReturn", |
- "nonStandardJsDocs", |
- "suspiciousCode", |
- "undefinedNames", |
- "undefinedVars", |
- "unknownDefines", |
- "uselessCode", |
- "visibility", |
- ] |
- |
- # Extra @jsDocAnnotations used when compiling polymer code. |
- _POLYMER_EXTRA_ANNOTATIONS = [ |
- "attribute", |
- "status", |
- "element", |
- "homepage", |
- "submodule", |
- "group", |
- ] |
- |
- _COMMON_CLOSURE_ARGS = [ |
- "--accept_const_keyword", |
- "--language_in=ECMASCRIPT5_STRICT", |
- "--summary_detail_level=3", |
- "--compilation_level=SIMPLE_OPTIMIZATIONS", |
- "--source_map_format=V3", |
- "--polymer_pass", |
- ] + [ |
- "--jscomp_error=%s" % err for err in _COMMON_JSCOMP_ERRORS |
- ] + [ |
- "--extra_annotation_name=%s" % a for a in _POLYMER_EXTRA_ANNOTATIONS |
- ] |
- |
- # These are the extra flags used when compiling in strict mode. |
- # Flags that are normally disabled are turned on for strict mode. |
- _STRICT_CLOSURE_ARGS = [ |
- "--jscomp_error=reportUnknownTypes", |
- "--jscomp_error=duplicate", |
- "--jscomp_error=misplacedTypeAnnotation", |
- ] |
- |
- _DISABLED_CLOSURE_ARGS = [ |
- # TODO(dbeam): happens when the same file is <include>d multiple times. |
- "--jscomp_off=duplicate", |
- # TODO(fukino): happens when cr.defineProperty() has a type annotation. |
- # Avoiding parse-time warnings needs 2 pass compiling. crbug.com/421562. |
- "--jscomp_off=misplacedTypeAnnotation", |
- ] |
- |
_JAR_COMMAND = [ |
"java", |
"-jar", |
@@ -135,12 +74,6 @@ class Checker(object): |
""" |
print >> sys.stderr, "(ERROR) %s" % msg |
- def _common_args(self): |
- """Returns an array of the common closure compiler args.""" |
- if self._strict: |
- return self._COMMON_CLOSURE_ARGS + self._STRICT_CLOSURE_ARGS |
- return self._COMMON_CLOSURE_ARGS + self._DISABLED_CLOSURE_ARGS |
- |
def _run_jar(self, jar, args): |
"""Runs a .jar from the command line with arguments. |
@@ -253,15 +186,14 @@ class Checker(object): |
return tmp_file.name |
def _run_js_check(self, sources, out_file=None, externs=None, |
- output_wrapper=None): |
+ closure_args=None): |
"""Check |sources| for type errors. |
Args: |
sources: Files to check. |
out_file: A file where the compiled output is written to. |
externs: @extern files that inform the compiler about custom globals. |
- output_wrapper: Wraps output into this string at the place denoted by the |
- marker token %output%. |
+ closure_args: Arguments passed directly to the closure compiler. |
Returns: |
(errors, stderr) A parsed list of errors (strings) found by the compiler |
@@ -279,10 +211,9 @@ class Checker(object): |
if externs: |
args += ["--externs=%s" % e for e in externs] |
- if output_wrapper: |
- args += ['--output_wrapper="%s"' % output_wrapper] |
+ args += closure_args |
- args_file_content = " %s" % " ".join(self._common_args() + args) |
+ args_file_content = " %s" % " ".join(args) |
self._log_debug("Args: %s" % args_file_content.strip()) |
args_file = self._create_temp_file(args_file_content) |
@@ -311,7 +242,7 @@ class Checker(object): |
return errors, stderr |
def check(self, source_file, out_file=None, depends=None, externs=None, |
- output_wrapper=None): |
+ closure_args=None): |
"""Closure compiler |source_file| while checking for errors. |
Args: |
@@ -319,8 +250,7 @@ class Checker(object): |
out_file: A file where the compiled output is written to. |
depends: Files that |source_file| requires to run (e.g. earlier <script>). |
externs: @extern files that inform the compiler about custom globals. |
- output_wrapper: Wraps output into this string at the place denoted by the |
- marker token %output%. |
+ closure_args: Arguments passed directly to the closure compiler. |
Returns: |
(found_errors, stderr) A boolean indicating whether errors were found and |
@@ -349,7 +279,7 @@ class Checker(object): |
errors, stderr = self._run_js_check([self._expanded_file], |
out_file=out_file, externs=externs, |
- output_wrapper=output_wrapper) |
+ closure_args=closure_args) |
filtered_errors = self._filter_errors(errors) |
cleaned_errors = map(self._clean_up_error, filtered_errors) |
output = self._format_errors(cleaned_errors) |
@@ -363,15 +293,14 @@ class Checker(object): |
self._nuke_temp_files() |
return bool(cleaned_errors), stderr |
- def check_multiple(self, sources, out_file=None, output_wrapper=None, |
+ def check_multiple(self, sources, out_file=None, closure_args=None, |
externs=None): |
"""Closure compile a set of files and check for errors. |
Args: |
sources: An array of files to check. |
out_file: A file where the compiled output is written to. |
- output_wrapper: Wraps output into this string at the place denoted by the |
- marker token %output%. |
+ closure_args: Arguments passed directly to the closure compiler. |
externs: @extern files that inform the compiler about custom globals. |
Returns: |
@@ -379,7 +308,7 @@ class Checker(object): |
the raw Closure Compiler stderr (as a string). |
""" |
errors, stderr = self._run_js_check(sources, out_file=out_file, |
- output_wrapper=output_wrapper, |
+ closure_args=closure_args, |
externs=externs) |
self._nuke_temp_files() |
return bool(errors), stderr |
@@ -401,9 +330,8 @@ if __name__ == "__main__": |
parser.add_argument("-e", "--externs", nargs=argparse.ZERO_OR_MORE) |
parser.add_argument("-o", "--out_file", |
help="A file where the compiled output is written to") |
- parser.add_argument("-w", "--output_wrapper", |
- help="Wraps output into this string at the place" |
- + " denoted by the marker token %output%") |
+ parser.add_argument("-c", "--closure_args", |
Dan Beam
2015/06/01 22:57:39
i'd say all of these args should be --dash-form fo
Theresa
2015/06/02 22:02:12
Done.
|
+ help="Arguments passed directly to the closure compiler") |
parser.add_argument("-v", "--verbose", action="store_true", |
help="Show more information as this script runs") |
parser.add_argument("--strict", action="store_true", |
Dan Beam
2015/06/01 22:57:39
kill --strict
Theresa
2015/06/02 22:02:12
Done.
|
@@ -429,14 +357,14 @@ if __name__ == "__main__": |
source, depends, externs) |
found_errors, _ = checker.check(source, out_file=opts.out_file, |
depends=depends, externs=externs, |
- output_wrapper=opts.output_wrapper) |
+ closure_args=opts.closure_args) |
if found_errors: |
sys.exit(1) |
else: |
found_errors, stderr = checker.check_multiple( |
opts.sources, |
out_file=opts.out_file, |
- output_wrapper=opts.output_wrapper, |
+ closure_args=opts.closure_args, |
externs=externs) |
if found_errors: |
print stderr |