示例#1
0
 def test_strip_comments(self):
     self.assertEquals('A ', strip_js_comments.StripJSComments('A // foo'))
     self.assertEquals('A bar',
                       strip_js_comments.StripJSComments('A // foo\nbar'))
     self.assertEquals('A  b',
                       strip_js_comments.StripJSComments('A /* foo */ b'))
     self.assertEquals('A  b',
                       strip_js_comments.StripJSComments('A /* foo\n */ b'))
示例#2
0
def _FirstStatement(contents):
    """Extracts the first statement in some JS source code."""
    stripped_contents = strip_js_comments.StripJSComments(contents).strip()
    matches = re.match('^(.*?);', stripped_contents, re.DOTALL)
    if not matches:
        return ''
    return matches.group(1).strip()
示例#3
0
    def GetStrippedJSForFilename(self, filename, early_out_if_no_py_vulcanize):
        if filename in self.stripped_js_by_filename:
            return self.stripped_js_by_filename[filename]

        with open(filename, 'r') as f:
            contents = f.read(4096)
        if early_out_if_no_py_vulcanize and ('py_vulcanize' not in contents):
            return None

        s = strip_js_comments.StripJSComments(contents)
        self.stripped_js_by_filename[filename] = s
        return s
示例#4
0
 def stripped_contents(self):
     if not self._stripped_contents:
         self._stripped_contents = strip_js_comments.StripJSComments(
             self.contents)
     return self._stripped_contents
示例#5
0
 def test_ValidateUsesStrictMode_catches_missing_strict_mode(self):
     text = "// blahblahblah\n\npy_vulcanize.require('dependency1');"
     stripped_text = strip_js_comments.StripJSComments(text)
     self.assertRaises(
         lambda: js_utils.ValidateUsesStrictMode('module', stripped_text))
示例#6
0
 def test_ValidateUsesStrictModeOneLiner(self):
     text = "'use strict'; py_vulcanize.require('dependency1');"
     stripped_text = strip_js_comments.StripJSComments(text)
     self.assertIsNone(
         js_utils.ValidateUsesStrictMode('module', stripped_text))
示例#7
0
 def test_ValidateUsesStrictMode_returns_true(self):
     text = "// blahblahblah\n\n'use strict';\n\npy_vulcanize.require('dependency1');"
     stripped_text = strip_js_comments.StripJSComments(text)
     self.assertIsNone(
         js_utils.ValidateUsesStrictMode('module', stripped_text))