Example #1
0
def Parse(loader,
          module_name,
          module_dir_name,
          is_component,
          parser_results,
          exclude_scripts=None):
    res = module.ModuleDependencyMetadata()
    if is_component:
        return res

    # External script references.
    for href in parser_results.scripts_external:
        if exclude_scripts and any(
                re.match(pattern, href) for pattern in exclude_scripts):
            continue

        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 exclude_scripts and any(
                re.match(pattern, href) for pattern in exclude_scripts):
            continue

        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)

    # 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
Example #2
0
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