diff options
author | Michael Zhou <zhoumotongxue008@gmail.com> | 2016-02-16 01:21:47 -0500 |
---|---|---|
committer | Michael Zhou <zhoumotongxue008@gmail.com> | 2016-02-17 16:07:41 -0500 |
commit | 33573dca2c41d78a12a76cde0c3c3613668bb918 (patch) | |
tree | 0e33b0616984c517429d656cd3ce97b0b23fd601 | |
parent | af1d67f5c7239721eb813e8d2857d4c3507687c8 (diff) |
Add "--language_in" and "--language_out" to closure_js_binary.bzl
With these flags users can transpile their closure_js_binary() from
ES6 to ES3.
Change "--manage_closure_dependencies" to "--dependency_mode=LOOSE"
because the former has been deprecated in Closure Compiler v20160208.
-rw-r--r-- | tools/build_rules/closure/closure_js_binary.bzl | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/tools/build_rules/closure/closure_js_binary.bzl b/tools/build_rules/closure/closure_js_binary.bzl index 89af6721d4..447dd09cee 100644 --- a/tools/build_rules/closure/closure_js_binary.bzl +++ b/tools/build_rules/closure/closure_js_binary.bzl @@ -27,6 +27,8 @@ Example: closure_js_binary( name = "hello", compilation_level = "simple", + language_in = "ecmascript6", + language_out = "ecmascript3", externs = ["//third_party/javascript/google_cast/cast.js"], deps = [ "@closure_library//:closure_library", @@ -46,6 +48,21 @@ _COMPILATION_LEVELS = { "advanced": ["--compilation_level=ADVANCED"] } +_SUPPORTED_LANGUAGES = { + "es3": ["ES3"], + "ecmascript3": ["ECMASCRIPT3"], + "es5": ["ES5"], + "ecmascript5": ["ECMASCRIPT5"], + "es5_strict": ["ES5_STRICT"], + "ecmascript5_strict": ["ECMASCRIPT5_STRICT"], + "es6": ["ES6"], + "ecmascript6": ["ECMASCRIPT6"], + "es6_strict": ["ES6_STRICT"], + "ecmascript6_strict": ["ECMASCRIPT6_STRICT"], + "es6_typed": ["ES6_TYPED"], + "ecmascript6_typed": ["ECMASCRIPT6_TYPED"], +} + def _impl(ctx): externs = set(order="compile") srcs = set(order="compile") @@ -57,7 +74,7 @@ def _impl(ctx): "--closure_entry_point=%s" % ctx.attr.main, "--js_output_file=%s" % ctx.outputs.out.path, "--language_in=ECMASCRIPT5_STRICT", - "--manage_closure_dependencies", + "--dependency_mode=LOOSE", "--warning_level=VERBOSE", ] + (["--js=%s" % src.path for src in srcs] + ["--externs=%s" % extern.path for extern in externs]) @@ -69,6 +86,20 @@ def _impl(ctx): fail("Invalid compilation_level '%s', expected one of %s" % (ctx.attr.compilation_level, _COMPILATION_LEVELS.keys())) + # Set the language in. + if ctx.attr.language_in in _SUPPORTED_LANGUAGES: + args += "--language_in=" + _SUPPORTED_LANGUAGES[ctx.attr.language_in] + else: + fail("Invalid language_in '%s', expected one of %s" % + (ctx.attr.language_in, _SUPPORTED_LANGUAGES.keys())) + + # Set the language out. + if ctx.attr.language_out in _SUPPORTED_LANGUAGES: + args += "--language_out=" + _SUPPORTED_LANGUAGES[ctx.attr.language_out] + else: + fail("Invalid language_out '%s', expected one of %s" % + (ctx.attr.language_out, _SUPPORTED_LANGUAGES.keys())) + ctx.action( inputs=list(srcs) + list(externs), outputs=[ctx.outputs.out], @@ -85,6 +116,8 @@ closure_js_binary = rule( providers=["transitive_js_externs", "transitive_js_srcs"]), "main": attr.string(default="%{name}"), "compilation_level": attr.string(default="advanced"), + "language_in": attr.string(default="ecmascript6"), + "language_out": attr.string(default="ecmascript3"), "_closure_compiler": attr.label( default=Label("//external:closure_compiler_"), executable=True), |