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

Side by Side Diff: third_party/closure_compiler/checker.py

Issue 435053002: Remove <if> statements before checking JS code by checker.py (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@B_define
Patch Set: inline replace_if function Created 6 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 unified diff | Download patch
« no previous file with comments | « no previous file | third_party/closure_compiler/checker_test.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 from collections import defaultdict 5 from collections import defaultdict
6 import os 6 import os
7 import re 7 import re
8 import subprocess 8 import subprocess
9 import sys 9 import sys
10 import tempfile 10 import tempfile
(...skipping 13 matching lines...) Expand all
24 file = os.path.abspath(file) 24 file = os.path.abspath(file)
25 self._cache[file] = self._cache[file] or open(file, "r").read() 25 self._cache[file] = self._cache[file] or open(file, "r").read()
26 return self._cache[file] 26 return self._cache[file]
27 27
28 @staticmethod 28 @staticmethod
29 def read(file): 29 def read(file):
30 return FileCache()._read(file) 30 return FileCache()._read(file)
31 31
32 32
33 class Flattener(object): 33 class Flattener(object):
34 _IF_TAGS_REG = "</?if[^>]*?>"
34 _INCLUDE_REG = "<include[^>]+src=['\"]([^>]*)['\"]>" 35 _INCLUDE_REG = "<include[^>]+src=['\"]([^>]*)['\"]>"
35 36
36 def __init__(self, file): 37 def __init__(self, file):
37 self.index = 0 38 self.index = 0
38 self.lines = self._get_file(file) 39 self.lines = self._get_file(file)
39 40
40 while self.index < len(self.lines): 41 while self.index < len(self.lines):
41 current_line = self.lines[self.index] 42 current_line = self.lines[self.index]
42 match = re.search(self._INCLUDE_REG, current_line[2]) 43 match = re.search(self._INCLUDE_REG, current_line[2])
43 if match: 44 if match:
44 file_dir = os.path.dirname(current_line[0]) 45 file_dir = os.path.dirname(current_line[0])
45 self._inline_file(os.path.join(file_dir, match.group(1))) 46 self._inline_file(os.path.join(file_dir, match.group(1)))
46 else: 47 else:
47 self.index += 1 48 self.index += 1
48 49
50 # Replace every occurrence of tags like <if expr="..."> and </if>
51 # with an empty string.
Dan Beam 2014/08/02 00:04:56 ^ i think the code pretty clearly shows this, but
52 for i, line in enumerate(self.lines):
53 self.lines[i] = line[:2] + (re.sub(self._IF_TAGS_REG, "", line[2]),)
54
49 self.contents = "\n".join(l[2] for l in self.lines) 55 self.contents = "\n".join(l[2] for l in self.lines)
50 56
51 # Returns a list of tuples in the format: (file, line number, line contents). 57 # Returns a list of tuples in the format: (file, line number, line contents).
52 def _get_file(self, file): 58 def _get_file(self, file):
53 lines = FileCache.read(file).splitlines() 59 lines = FileCache.read(file).splitlines()
54 return [(file, lnum + 1, line) for lnum, line in enumerate(lines)] 60 return [(file, lnum + 1, line) for lnum, line in enumerate(lines)]
55 61
56 def _inline_file(self, file): 62 def _inline_file(self, file):
57 lines = self._get_file(file) 63 lines = self._get_file(file)
58 self.lines = self.lines[:self.index] + lines + self.lines[self.index + 1:] 64 self.lines = self.lines[:self.index] + lines + self.lines[self.index + 1:]
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 output = self._format_errors(map(self._fix_up_error, errors)) 222 output = self._format_errors(map(self._fix_up_error, errors))
217 223
218 if runner_cmd.returncode: 224 if runner_cmd.returncode:
219 self._error("Error in: " + file + ("\n" + output if output else "")) 225 self._error("Error in: " + file + ("\n" + output if output else ""))
220 elif output: 226 elif output:
221 self._debug("Output: " + output) 227 self._debug("Output: " + output)
222 228
223 self._clean_up() 229 self._clean_up()
224 230
225 return runner_cmd.returncode, output 231 return runner_cmd.returncode, output
OLDNEW
« no previous file with comments | « no previous file | third_party/closure_compiler/checker_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698