chromium/third_party/closure_compiler/closure_args.gni

# Copyright 2015 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//build/config/chromeos/ui_mode.gni")

strict_error_checking_closure_args = [
  "jscomp_error=accessControls",
  "jscomp_error=checkTypes",
  "jscomp_error=checkVars",
  "jscomp_error=constantProperty",
  "jscomp_error=deprecated",
  "jscomp_error=externsValidation",
  "jscomp_error=globalThis",
  "jscomp_error=invalidCasts",
  "jscomp_error=misplacedTypeAnnotation",
  "jscomp_error=missingProperties",
  "jscomp_error=missingReturn",
  "jscomp_error=nonStandardJsDocs",
  "jscomp_error=suspiciousCode",
  "jscomp_error=undefinedVars",
  "jscomp_error=unknownDefines",
  "jscomp_error=uselessCode",
  "jscomp_error=visibility",
]

# Additional closure args for performing full checks.
default_closure_args = strict_error_checking_closure_args + [
                         "compilation_level=SIMPLE_OPTIMIZATIONS",
                         "generate_exports=false",

                         "extra_annotation_name=attribute",
                         "extra_annotation_name=demo",
                         "extra_annotation_name=element",

                         "language_in=ECMASCRIPT_2020",
                         "language_out=ECMASCRIPT5_STRICT",

                         "jscomp_off=duplicate",
                       ]

js_modules_args = [
  "js_module_root=" + rebase_path("//ui/webui/resources/", root_build_dir),
  "js_module_root=gen/ui/webui/resources/",

  # chrome://resources maps to root, since both ../../ui/webui/resources and
  # gen/ui/webui/resources are js_module_roots.
  "module_resolution=BROWSER_WITH_TRANSFORMED_PREFIXES",
  "browser_resolver_prefix_replacements=\"chrome://resources/=./\"",
  "browser_resolver_prefix_replacements=\"//resources/=./\"",
]

if (is_chromeos_ash) {
  js_modules_args += [
    "js_module_root=" +
        rebase_path("//ash/webui/common/resources/", root_build_dir),
    "js_module_root=gen/ash/webui/common/resources/",
    "browser_resolver_prefix_replacements=\"chrome://resources/ash/common/=./\"",
    "browser_resolver_prefix_replacements=\"//resources/ash/common/=./\"",
    "js_module_root=" +
        rebase_path("//chrome/test/data/webui/", root_build_dir),
    "browser_resolver_prefix_replacements=\"chrome://webui-test/=./\"",
  ]
}

mojom_js_args = [
  "js_module_root=" +
      rebase_path("$root_gen_dir/mojo/public/js", root_build_dir),
  "js_module_root=" + rebase_path("$root_gen_dir/mojom-webui", root_build_dir),
  "js_module_root=" +
      rebase_path("$root_gen_dir/mojom-webui/ui/webui/resources",
                  root_build_dir),

  # Mojom WebUI JS modules load bindings.js which may be compiled and stripped
  # of type annotations. Rewrite these references to the uncompiled equivalent
  # for compilation and type-checking.
  "browser_resolver_prefix_replacements=\"//resources/mojo/mojo/public/js/bindings.js=/bindings_uncompiled.js\"",

  # Shared Mojom WebUI JS modules are by convention exposed through URLs like
  # chrome://resources/mojo/<path-to-module>. At build time these will be given
  # as gen/<path-to-module> for compilation, so we can rewrite them as absolute
  # paths.
  "browser_resolver_prefix_replacements=\"chrome://resources/mojo/=/\"",
  "browser_resolver_prefix_replacements=\"//resources/mojo/=/\"",
]

polymer3_args = [
  "browser_resolver_prefix_replacements=\"../polymer/polymer_bundled.min.js=../polymer/polymer_bundled.js\"",
  "browser_resolver_prefix_replacements=\"chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js=" + rebase_path(
          "//third_party/polymer/v3_0/components-chromium/polymer/polymer_bundled.js",
          root_build_dir) + "\"",
  "browser_resolver_prefix_replacements=\"//resources/polymer/v3_0/polymer/polymer_bundled.min.js=" + rebase_path(
          "//third_party/polymer/v3_0/components-chromium/polymer/polymer_bundled.js",
          root_build_dir) + "\"",
  "browser_resolver_prefix_replacements=\"chrome://resources/polymer/v3_0/=" +
      rebase_path("//third_party/polymer/v3_0/components-chromium/",
                  root_build_dir) + "\"",
  "browser_resolver_prefix_replacements=\"//resources/polymer/v3_0/=" +
      rebase_path("//third_party/polymer/v3_0/components-chromium/",
                  root_build_dir) + "\"",

  "hide_warnings_for=externs.zip",

  # TODO(crbug.com/1093048): Add the leading '../../' back to
  # the path once the CrOS chroot no longer uses symlinks when
  # building chrome.
  "hide_warnings_for=third_party/polymer/v3_0/components-chromium/",

  # Note: "2" is counter-intuitively the correct value to use for Polymer 3.
  "polymer_version=2",
]

default_disabled_closure_args = [ "jscomp_off=duplicate" ]