summaryrefslogtreecommitdiffstats
path: root/third_party/closure_compiler
diff options
context:
space:
mode:
authordbeam <dbeam@chromium.org>2014-12-16 15:42:12 -0800
committerCommit bot <commit-bot@chromium.org>2014-12-16 23:42:34 +0000
commit82d0b52f01af9184255d28d8c41a0a899bd8003a (patch)
treebb95cef21659a5285c02012e616a6f934af8c987 /third_party/closure_compiler
parent587e415477f41612c5db93c39a03c4b7c15b48c8 (diff)
downloadchromium_src-82d0b52f01af9184255d28d8c41a0a899bd8003a.zip
chromium_src-82d0b52f01af9184255d28d8c41a0a899bd8003a.tar.gz
chromium_src-82d0b52f01af9184255d28d8c41a0a899bd8003a.tar.bz2
Make grit <include> de-duping clearer.
R=tbreisacher@chromium.org BUG=none TEST=code is easier to read and more thoroughly tested NOTRY=true Review URL: https://codereview.chromium.org/800043003 Cr-Commit-Position: refs/heads/master@{#308693}
Diffstat (limited to 'third_party/closure_compiler')
-rw-r--r--third_party/closure_compiler/processor.py13
-rwxr-xr-xthird_party/closure_compiler/processor_test.py10
2 files changed, 17 insertions, 6 deletions
diff --git a/third_party/closure_compiler/processor.py b/third_party/closure_compiler/processor.py
index d25f8c0..af88862 100644
--- a/third_party/closure_compiler/processor.py
+++ b/third_party/closure_compiler/processor.py
@@ -86,13 +86,14 @@ class Processor(object):
if match:
file_dir = os.path.dirname(current_line[0])
file_name = os.path.abspath(os.path.join(file_dir, match.group(1)))
- if file_name in self._included_files:
- self._lines[self._index] = self._lines[self._index][:2] + ("",)
- self._index += 1
- else:
+ if file_name not in self._included_files:
self._include_file(file_name)
- else:
- self._index += 1
+ continue # Stay on the same line.
+ else:
+ # Found a duplicate <include>. Ignore and insert a blank line to
+ # preserve line numbers.
+ self._lines[self._index] = self._lines[self._index][:2] + ("",)
+ self._index += 1
for i, line in enumerate(self._lines):
self._lines[i] = line[:2] + (re.sub(self._IF_TAGS_REG, "", line[2]),)
diff --git a/third_party/closure_compiler/processor_test.py b/third_party/closure_compiler/processor_test.py
index 942d472..f5517cc 100755
--- a/third_party/closure_compiler/processor_test.py
+++ b/third_party/closure_compiler/processor_test.py
@@ -39,6 +39,11 @@ debug(global);
// Here continues checked.js, a swell file.
""".strip()
+ FileCache._cache["/double-debug.js"] = """
+<include src="/debug.js">
+<include src="/debug.js">
+""".strip()
+
self._processor = Processor("/checked.js")
def testInline(self):
@@ -77,6 +82,11 @@ debug(global);
self.assertEquals(set(["/global.js", "/debug.js"]),
self._processor.included_files)
+ def testDoubleIncludedSkipped(self):
+ """Verify that doubly included files are skipped."""
+ processor = Processor("/double-debug.js")
+ self.assertEquals(set(["/debug.js"]), processor.included_files)
+ self.assertEquals(FileCache.read("/debug.js") + "\n", processor.contents)
class IfStrippingTest(unittest.TestCase):
"""Test that the contents of XML <if> blocks are stripped."""