def Parse(loader, module_name, module_dir_name, is_component, parser_results):
    res = module.ModuleDependencyMetadata()
    if is_component:
        return res

    if parser_results.has_decl is False:
        raise Exception('%s must have <!DOCTYPE html>' % module_name)

    # External script references..
    for href in parser_results.scripts_external:
        resource = _HRefToResource(loader,
                                   module_name,
                                   module_dir_name,
                                   href,
                                   tag_for_err_msg='<script src="%s">' % href)
        res.dependent_raw_script_relative_paths.append(
            resource.unix_style_relative_path)

    # External imports. Mostly the same as <script>, but we know its a module.
    for href in parser_results.imports:
        if not href.endswith('.html'):
            raise Exception(
                'In %s, the <link rel="import" href="%s"> must point at a '
                'file with an html suffix' % (module_name, href))

        resource = _HRefToResource(
            loader,
            module_name,
            module_dir_name,
            href,
            tag_for_err_msg='<link rel="import" href="%s">' % href)
        res.dependent_module_names.append(resource.name)

    # Validate the in-line scripts.
    for inline_script in parser_results.inline_scripts:
        stripped_text = inline_script.stripped_contents
        try:
            js_utils.ValidateUsesStrictMode('_', stripped_text)
        except:
            raise Exception('%s has an inline script tag that is missing '
                            'a \'use strict\' directive.' % module_name)

    # Style sheets
    for href in parser_results.stylesheets:
        resource = _HRefToResource(
            loader,
            module_name,
            module_dir_name,
            href,
            tag_for_err_msg='<link rel="stylesheet" href="%s">' % href)
        res.style_sheet_names.append(resource.name)

    return res
Ejemplo n.º 2
0
 def test_ValidateUsesStrictMode_catches_missing_strict_mode(self):
   text = "// blahblahblah\n\ntvcm.require('dependency1');"
   stripped_text = strip_js_comments.StripJSComments(text)
   self.assertRaises(
       lambda: js_utils.ValidateUsesStrictMode('module', stripped_text))
Ejemplo n.º 3
0
 def test_ValidateUsesStrictModeOneLiner(self):
   text = "'use strict'; tvcm.require('dependency1');"
   stripped_text = strip_js_comments.StripJSComments(text)
   self.assertIsNone(js_utils.ValidateUsesStrictMode('module', stripped_text))
Ejemplo n.º 4
0
 def test_ValidateUsesStrictMode_returns_true(self):
   text = "// blahblahblah\n\n'use strict';\n\ntvcm.require('dependency1');"
   stripped_text = strip_js_comments.StripJSComments(text)
   self.assertIsNone(js_utils.ValidateUsesStrictMode('module', stripped_text))