Commit 4d56b62 1 parent 64d9caa commit 4d56b62 Copy full SHA for 4d56b62
File tree 6 files changed +24
-6
lines changed
src/com/google/javascript/jscomp
test/com/google/javascript/jscomp
6 files changed +24
-6
lines changed Original file line number Diff line number Diff line change @@ -185,7 +185,8 @@ void setDependentValuesFromYear(CompilerOptions options) {
185
185
options .languageOutIsDefaultStrict = Optional .of (true );
186
186
options .setDefineToNumberLiteral ("goog.FEATURESET_YEAR" , year );
187
187
options .setDefineToBooleanLiteral ("$jscomp.ASSUME_ES5" , year > 2012 );
188
- options .setDefineToBooleanLiteral ("$jscomp.ASSUME_ES6" , year > 2018 );
188
+ options .setDefineToBooleanLiteral ("$jscomp.ASSUME_ES6" , year >= 2018 );
189
+ options .setDefineToBooleanLiteral ("$jscomp.ASSUME_ES2020" , year >= 2021 );
189
190
}
190
191
191
192
FeatureSet getFeatureSet () {
Original file line number Diff line number Diff line change @@ -60,6 +60,7 @@ class ProcessDefines implements CompilerPass {
60
60
"goog.DEBUG" ,
61
61
"$jscomp.ASSUME_ES5" ,
62
62
"$jscomp.ASSUME_ES6" ,
63
+ "$jscomp.ASSUME_ES2020" ,
63
64
"$jscomp.ISOLATE_POLYFILLS" ,
64
65
"$jscomp.INSTRUMENT_ASYNC_CONTEXT" );
65
66
Original file line number Diff line number Diff line change @@ -31,6 +31,15 @@ $jscomp.ASSUME_ES5 = false;
31
31
*/
32
32
$jscomp . ASSUME_ES6 = false ;
33
33
34
+ /**
35
+ * Whether to assume ES2020 is available. This enables removing several
36
+ * internal polyfills, which must otherwise be detected at runtime.
37
+ * @define {boolean}
38
+ */
39
+ $jscomp . ASSUME_ES2020 = false ;
40
+
41
+
42
+
34
43
/**
35
44
* Whether to skip the conformance check and simply use the polyfill always.
36
45
* @define {boolean}
Original file line number Diff line number Diff line change 19
19
* @suppress {uselessCode}
20
20
*/
21
21
'require base' ;
22
+ 'require util/defines' ;
22
23
23
24
/**
24
25
* Locate and return a reference to the global object.
@@ -85,4 +86,4 @@ $jscomp.getGlobal = function(passedInThis) {
85
86
* The global object.
86
87
* @const {!Global}
87
88
*/
88
- $jscomp . global = $jscomp . getGlobal ( this ) ;
89
+ $jscomp . global = $jscomp . ASSUME_ES2020 ? globalThis : $jscomp . getGlobal ( this ) ;
Original file line number Diff line number Diff line change @@ -81,12 +81,18 @@ public void testBrowserFeaturesetYearOptionSetsAssumeES5() {
81
81
@ Test
82
82
public void testBrowserFeaturesetYearOptionSetsAssumeES6 () {
83
83
CompilerOptions options = new CompilerOptions ();
84
- options .setBrowserFeaturesetYear (2018 );
84
+ options .setBrowserFeaturesetYear (2012 );
85
85
assertThat (options .getDefineReplacements ().get ("$jscomp.ASSUME_ES6" ).getToken ())
86
86
.isEqualTo (Token .FALSE );
87
- options .setBrowserFeaturesetYear (2019 );
87
+ options .setBrowserFeaturesetYear (2018 );
88
88
assertThat (options .getDefineReplacements ().get ("$jscomp.ASSUME_ES6" ).getToken ())
89
89
.isEqualTo (Token .TRUE );
90
+ options .setBrowserFeaturesetYear (2020 );
91
+ assertThat (options .getDefineReplacements ().get ("$jscomp.ASSUME_ES2020" ).getToken ())
92
+ .isEqualTo (Token .FALSE );
93
+ options .setBrowserFeaturesetYear (2021 );
94
+ assertThat (options .getDefineReplacements ().get ("$jscomp.ASSUME_ES2020" ).getToken ())
95
+ .isEqualTo (Token .TRUE );
90
96
}
91
97
92
98
@ Test
Original file line number Diff line number Diff line change @@ -113,10 +113,10 @@ public void testInjection_doesntCrashOnLibrariesWithCasts_ifTypecheckingHasNotRu
113
113
114
114
ImmutableList <Node > objectNameNodes =
115
115
findNodesNamed (this .getLastCompiler ().getRoot (), "globalThis" );
116
- assertThat (objectNameNodes ).hasSize (3 );
116
+ assertThat (objectNameNodes ).hasSize (4 );
117
117
118
118
Node injectedGlobalThisNode = objectNameNodes .get (0 );
119
- Node sourceGlobalThisNode = objectNameNodes .get (2 );
119
+ Node sourceGlobalThisNode = objectNameNodes .get (3 );
120
120
121
121
assertThat (injectedGlobalThisNode .getSourceFileName ()).contains ("util/global" );
122
122
assertThat (sourceGlobalThisNode .getSourceFileName ()).contains ("testcode" );
You can’t perform that action at this time.
0 commit comments