Skip to content

Commit f465cd7

Browse files
Dustyn Loydalauraharker
Dustyn Loyda
authored andcommitted
Add a new option to CompilerOptions to set the value of the $jscomp.ASSUME_ES6
PiperOrigin-RevId: 707308589
1 parent f51970c commit f465cd7

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

src/com/google/javascript/jscomp/CompilerOptions.java

+1
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ void setDependentValuesFromYear(CompilerOptions options) {
183183
options.languageOutIsDefaultStrict = Optional.of(true);
184184
options.setDefineToNumberLiteral("goog.FEATURESET_YEAR", year);
185185
options.setDefineToBooleanLiteral("$jscomp.ASSUME_ES5", year > 2012);
186+
options.setDefineToBooleanLiteral("$jscomp.ASSUME_ES6", year > 2018);
186187
}
187188

188189
FeatureSet getFeatureSet() {

src/com/google/javascript/jscomp/ProcessDefines.java

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class ProcessDefines implements CompilerPass {
5959
"COMPILED",
6060
"goog.DEBUG",
6161
"$jscomp.ASSUME_ES5",
62+
"$jscomp.ASSUME_ES6",
6263
"$jscomp.ISOLATE_POLYFILLS",
6364
"$jscomp.INSTRUMENT_ASYNC_CONTEXT");
6465

test/com/google/javascript/jscomp/CompilerOptionsTest.java

+11
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,17 @@ public void testBrowserFeaturesetYearOptionSetsAssumeES5() {
7575
.isEqualTo(Token.TRUE);
7676
}
7777

78+
@Test
79+
public void testBrowserFeaturesetYearOptionSetsAssumeES6() {
80+
CompilerOptions options = new CompilerOptions();
81+
options.setBrowserFeaturesetYear(2018);
82+
assertThat(options.getDefineReplacements().get("$jscomp.ASSUME_ES6").getToken())
83+
.isEqualTo(Token.FALSE);
84+
options.setBrowserFeaturesetYear(2019);
85+
assertThat(options.getDefineReplacements().get("$jscomp.ASSUME_ES6").getToken())
86+
.isEqualTo(Token.TRUE);
87+
}
88+
7889
@Test
7990
public void testMinimumBrowserFeatureSetYearRequiredFor() {
8091
assertThat(BrowserFeaturesetYear.minimumRequiredFor(Feature.GETTER))

0 commit comments

Comments
 (0)