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
3# found in the LICENSE file.
4
5
6def EscapeJSIfNeeded(js):
7  return js.replace('</script>', '<\/script>')
8
9
10def ValidateUsesStrictMode(module_name, stripped_text):
11  """Check that the first non-empty line is 'use strict';.
12
13  Args:
14    stripped_text: JavaScript source code with comments stripped out.
15
16  Raises:
17    DepsException: This file doesn't use strict mode.
18  """
19  lines = stripped_text.split('\n')
20  for line in lines:
21    line = line.strip()
22    if len(line.strip()) == 0:
23      continue
24    if """'use strict';""" in line.strip():
25      break
26    # FIXME: module is used but not imported. But, importing tvcm.module
27    # leads to an import cycle since tvcm.module imports js_utils.
28    raise module.DepsException('%s must use strict mode' % module_name)
29