Refactoring so that the ts_library module format doesn't depend on target.
This was confusing since "--target=es6" and "--target=es2015" are equivalent in TypeScript.
PiperOrigin-RevId: 200486018
diff --git a/internal/build_defs.bzl b/internal/build_defs.bzl
index 359bd38..b41d367 100644
--- a/internal/build_defs.bzl
+++ b/internal/build_defs.bzl
@@ -112,14 +112,6 @@
"node_modules"
] if p])
- if config["compilerOptions"]["target"] == "es6":
- config["compilerOptions"]["module"] = "es2015"
- else:
- # The "typescript.es5_sources" provider is expected to work
- # in both nodejs and in browsers.
- # NOTE: tsc-wrapped will always name the enclosed AMD modules
- config["compilerOptions"]["module"] = "umd"
-
# If the user gives a tsconfig attribute, the generated file should extend
# from the user's tsconfig.
# See https://github.com/Microsoft/TypeScript/issues/9876
diff --git a/internal/common/tsconfig.bzl b/internal/common/tsconfig.bzl
index c2d4d4d..92639a3 100644
--- a/internal/common/tsconfig.bzl
+++ b/internal/common/tsconfig.bzl
@@ -161,7 +161,19 @@
# Keep these options in sync with those in playground/playground.ts.
compiler_options = {
# De-sugar to this language level
- "target": "es5" if devmode_manifest or ctx.attr.runtime == "nodejs" else "es6",
+ "target": "es5" if devmode_manifest or ctx.attr.runtime == "nodejs" else "es2015",
+
+ # The "typescript.es5_sources" provider is expected to work
+ # in both nodejs and in browsers, so we use umd in devmode.
+ # NOTE: tsc-wrapped will always name the enclosed AMD modules
+ # For production mode, we leave the module syntax at ES2015 and let the
+ # bundler handle it.
+ # TODO(alexeagle): production mode should use "esnext" allowing the bundler
+ # to see dynamic import statements.
+ # Note, in google3 we override this option with "commonjs" since Tsickle
+ # will convert that to goog.module syntax.
+ "module": "umd" if devmode_manifest or ctx.attr.runtime == "nodejs" else "es2015",
+
# Has no effect in closure/ES2015 mode. Always true just for simplicity.
"downlevelIteration": True,