Skip to content

Commit

Permalink
Add a new option to CompilerOptions to set the value of the $jscomp.A…
Browse files Browse the repository at this point in the history
…SSUME_ES6

PiperOrigin-RevId: 707308589
  • Loading branch information
Dustyn Loyda authored and lauraharker committed Dec 20, 2024
1 parent f51970c commit f465cd7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/com/google/javascript/jscomp/CompilerOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ void setDependentValuesFromYear(CompilerOptions options) {
options.languageOutIsDefaultStrict = Optional.of(true);
options.setDefineToNumberLiteral("goog.FEATURESET_YEAR", year);
options.setDefineToBooleanLiteral("$jscomp.ASSUME_ES5", year > 2012);
options.setDefineToBooleanLiteral("$jscomp.ASSUME_ES6", year > 2018);
}

FeatureSet getFeatureSet() {
Expand Down
1 change: 1 addition & 0 deletions src/com/google/javascript/jscomp/ProcessDefines.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class ProcessDefines implements CompilerPass {
"COMPILED",
"goog.DEBUG",
"$jscomp.ASSUME_ES5",
"$jscomp.ASSUME_ES6",
"$jscomp.ISOLATE_POLYFILLS",
"$jscomp.INSTRUMENT_ASYNC_CONTEXT");

Expand Down
11 changes: 11 additions & 0 deletions test/com/google/javascript/jscomp/CompilerOptionsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,17 @@ public void testBrowserFeaturesetYearOptionSetsAssumeES5() {
.isEqualTo(Token.TRUE);
}

@Test
public void testBrowserFeaturesetYearOptionSetsAssumeES6() {
CompilerOptions options = new CompilerOptions();
options.setBrowserFeaturesetYear(2018);
assertThat(options.getDefineReplacements().get("$jscomp.ASSUME_ES6").getToken())
.isEqualTo(Token.FALSE);
options.setBrowserFeaturesetYear(2019);
assertThat(options.getDefineReplacements().get("$jscomp.ASSUME_ES6").getToken())
.isEqualTo(Token.TRUE);
}

@Test
public void testMinimumBrowserFeatureSetYearRequiredFor() {
assertThat(BrowserFeaturesetYear.minimumRequiredFor(Feature.GETTER))
Expand Down

0 comments on commit f465cd7

Please sign in to comment.