OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright 2014 The Chromium Authors. All rights reserved. | 2 # Copyright 2014 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Runs Closure compiler on a JavaScript file to check for errors.""" | 6 """Runs Closure compiler on a JavaScript file to check for errors.""" |
7 | 7 |
8 import argparse | 8 import argparse |
9 import os | 9 import os |
10 import re | 10 import re |
(...skipping 14 matching lines...) Expand all Loading... |
25 "--jscomp_error=accessControls", | 25 "--jscomp_error=accessControls", |
26 "--jscomp_error=ambiguousFunctionDecl", | 26 "--jscomp_error=ambiguousFunctionDecl", |
27 "--jscomp_error=checkStructDictInheritance", | 27 "--jscomp_error=checkStructDictInheritance", |
28 "--jscomp_error=checkTypes", | 28 "--jscomp_error=checkTypes", |
29 "--jscomp_error=checkVars", | 29 "--jscomp_error=checkVars", |
30 "--jscomp_error=constantProperty", | 30 "--jscomp_error=constantProperty", |
31 "--jscomp_error=deprecated", | 31 "--jscomp_error=deprecated", |
32 "--jscomp_error=externsValidation", | 32 "--jscomp_error=externsValidation", |
33 "--jscomp_error=globalThis", | 33 "--jscomp_error=globalThis", |
34 "--jscomp_error=invalidCasts", | 34 "--jscomp_error=invalidCasts", |
35 "--jscomp_error=misplacedTypeAnnotation", | |
36 "--jscomp_error=missingProperties", | 35 "--jscomp_error=missingProperties", |
37 "--jscomp_error=missingReturn", | 36 "--jscomp_error=missingReturn", |
38 "--jscomp_error=nonStandardJsDocs", | 37 "--jscomp_error=nonStandardJsDocs", |
39 "--jscomp_error=suspiciousCode", | 38 "--jscomp_error=suspiciousCode", |
40 "--jscomp_error=undefinedNames", | 39 "--jscomp_error=undefinedNames", |
41 "--jscomp_error=undefinedVars", | 40 "--jscomp_error=undefinedVars", |
42 "--jscomp_error=unknownDefines", | 41 "--jscomp_error=unknownDefines", |
43 "--jscomp_error=uselessCode", | 42 "--jscomp_error=uselessCode", |
44 "--jscomp_error=visibility", | 43 "--jscomp_error=visibility", |
45 # TODO(dbeam): happens when the same file is <include>d multiple times. | 44 # TODO(dbeam): happens when the same file is <include>d multiple times. |
46 "--jscomp_off=duplicate", | 45 "--jscomp_off=duplicate", |
| 46 # TODO(fukino): happens when cr.defineProperty() has a type annotation. |
| 47 # Avoiding parse-time warnings needs 2 pass compiling. crbug.com/421562. |
| 48 "--jscomp_off=misplacedTypeAnnotation", |
47 "--language_in=ECMASCRIPT5_STRICT", | 49 "--language_in=ECMASCRIPT5_STRICT", |
48 "--summary_detail_level=3", | 50 "--summary_detail_level=3", |
49 ] | 51 ] |
50 | 52 |
51 _JAR_COMMAND = [ | 53 _JAR_COMMAND = [ |
52 "java", | 54 "java", |
53 "-jar", | 55 "-jar", |
54 "-Xms1024m", | 56 "-Xms1024m", |
55 "-client", | 57 "-client", |
56 "-XX:+TieredCompilation" | 58 "-XX:+TieredCompilation" |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 match: A re.MatchObject from matching against a line number regex. | 124 match: A re.MatchObject from matching against a line number regex. |
123 | 125 |
124 Returns: | 126 Returns: |
125 The fixed up /file and :line number. | 127 The fixed up /file and :line number. |
126 """ | 128 """ |
127 real_file = self._processor.get_file_from_line(match.group(1)) | 129 real_file = self._processor.get_file_from_line(match.group(1)) |
128 return "%s:%d" % (os.path.abspath(real_file.file), real_file.line_number) | 130 return "%s:%d" % (os.path.abspath(real_file.file), real_file.line_number) |
129 | 131 |
130 def _fix_up_error(self, error): | 132 def _fix_up_error(self, error): |
131 """Filter out irrelevant errors or fix line numbers. | 133 """Filter out irrelevant errors or fix line numbers. |
132 | 134 |
133 Args: | 135 Args: |
134 error: A Closure compiler error (2 line string with error and source). | 136 error: A Closure compiler error (2 line string with error and source). |
135 | 137 |
136 Return: | 138 Return: |
137 The fixed up erorr string (blank if it should be ignored). | 139 The fixed up erorr string (blank if it should be ignored). |
138 """ | 140 """ |
139 if " first declared in " in error: | 141 if " first declared in " in error: |
140 # Ignore "Variable x first declared in /same/file". | 142 # Ignore "Variable x first declared in /same/file". |
141 return "" | 143 return "" |
142 | 144 |
143 expanded_file = self._expanded_file | 145 expanded_file = self._expanded_file |
144 fixed = re.sub("%s:(\d+)" % expanded_file, self._fix_line_number, error) | 146 fixed = re.sub("%s:(\d+)" % expanded_file, self._fix_line_number, error) |
145 return fixed.replace(expanded_file, os.path.abspath(self._file_arg)) | 147 return fixed.replace(expanded_file, os.path.abspath(self._file_arg)) |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 exit, _ = checker.check(source, depends=depends, externs=externs) | 244 exit, _ = checker.check(source, depends=depends, externs=externs) |
243 if exit != 0: | 245 if exit != 0: |
244 sys.exit(exit) | 246 sys.exit(exit) |
245 | 247 |
246 if opts.out_file: | 248 if opts.out_file: |
247 out_dir = os.path.dirname(opts.out_file) | 249 out_dir = os.path.dirname(opts.out_file) |
248 if not os.path.exists(out_dir): | 250 if not os.path.exists(out_dir): |
249 os.makedirs(out_dir) | 251 os.makedirs(out_dir) |
250 # TODO(dbeam): write compiled file to |opts.out_file|. | 252 # TODO(dbeam): write compiled file to |opts.out_file|. |
251 open(opts.out_file, "w").write("") | 253 open(opts.out_file, "w").write("") |
OLD | NEW |