Skip to content

Commit e9783f7

Browse files
blicklycopybara-github
authored andcommitted
Turn on the new let/const optimization by default
PiperOrigin-RevId: 904524143
1 parent 0938bdf commit e9783f7

4 files changed

Lines changed: 20 additions & 20 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1459,7 +1459,7 @@ public CompilerOptions() {
14591459
// Optimizations
14601460
foldConstants = false;
14611461
coalesceVariableNames = false;
1462-
optimizeLetAndConst = false;
1462+
optimizeLetAndConst = true;
14631463
assumeGlobalScopeIsIsolated = false;
14641464
deadAssignmentElimination = false;
14651465
deadPropertyAssignmentElimination = Tri.UNKNOWN;

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public void testDoNotRenameOrFlattenEscapedObjects() {
177177
expected(
178178
expectedClosureUnaware(
179179
"""
180-
const a = {x: 1, y: 2};
180+
var a = {x: 1, y: 2};
181181
foo(a);
182182
return a.x;
183183
""")));
@@ -200,7 +200,7 @@ public void testAssumeAllPropertyReadsHaveSideEffects() {
200200
expectedClosureUnaware(
201201
"""
202202
return function(a) {
203-
const b = a.x;
203+
var b = a.x;
204204
a.y;
205205
console.log(b);
206206
}
@@ -222,7 +222,7 @@ public void testAssumeAllPropertyWritesHaveSideEffects() {
222222
expectedClosureUnaware(
223223
"""
224224
return function(a) {
225-
const b = a.x;
225+
var b = a.x;
226226
a.y = 0;
227227
console.log(b);
228228
}
@@ -255,7 +255,7 @@ public void doesntRenameExternRefs_shadowedLocally() {
255255
"""
256256
return function() {
257257
globalThis.foo = function() {
258-
const a = typeof External === "undefined" ? null : External;
258+
var a = typeof External === "undefined" ? null : External;
259259
console.log(a);
260260
};
261261
};

test/com/google/javascript/jscomp/integration/AdvancedOptimizationsIntegrationTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ async function foo() {
484484
if ($$jscomp$forAwait$tempResult0$$.done) {
485485
break;
486486
}
487-
const [$key$$, $value$jscomp$2$$] = $$jscomp$forAwait$tempResult0$$.value;
487+
let [$key$$, $value$jscomp$2$$] = $$jscomp$forAwait$tempResult0$$.value;
488488
console.log($key$$, $value$jscomp$2$$);
489489
}
490490
} catch ($$jscomp$forAwait$catchErrParam0$$) {
@@ -898,7 +898,7 @@ class C {
898898
class C {
899899
constructor( ) {
900900
this.elements = [];
901-
for (const element of this.elements) {
901+
for (let element of this.elements) {
902902
element.someProp = 1;
903903
}
904904
}

test/com/google/javascript/jscomp/integration/IntegrationTest.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,11 @@ function f(param) {
174174
function f(param) {
175175
if (true) {
176176
param = [];
177-
for (const [key, value] of []) {}
177+
for (let [key, value] of []) {}
178178
}
179179
if (true) {
180180
param = [];
181-
for (const kv of []) {
181+
for (let kv of []) {
182182
param = kv.key;
183183
}
184184
}
@@ -212,11 +212,11 @@ function f(param) {
212212
function f(b1_b2_key2_param) {
213213
if (true) {
214214
b1_b2_key2_param = [];
215-
for (const [key, value] of []) {}
215+
for (let [key, value] of []) {}
216216
}
217217
if (true) {
218218
b1_b2_key2_param = [];
219-
for (const kv of []) {
219+
for (let kv of []) {
220220
b1_b2_key2_param = kv.key;
221221
}
222222
}
@@ -246,7 +246,7 @@ function f(obj) {
246246
"""
247247
function f(obj) {
248248
{
249-
const {foo} = obj;
249+
let {foo} = obj;
250250
alert(foo);
251251
}
252252
{
@@ -2495,7 +2495,7 @@ class Foo {
24952495
// Note: Foo.y stayed in the chunk where it had side effects.
24962496
"""
24972497
function $getRandom$$() {
2498-
const $v$$ = Math.random();
2498+
var $v$$ = Math.random();
24992499
alert("Picked " + $v$$);
25002500
return $v$$;
25012501
}
@@ -2610,7 +2610,7 @@ class Foo {
26102610
"",
26112611
"""
26122612
function $getRandom$$() {
2613-
const $v$$ = Math.random();
2613+
var $v$$ = Math.random();
26142614
alert("Picked " + $v$$);
26152615
return $v$$;
26162616
}
@@ -3340,7 +3340,7 @@ class Foo {
33403340
}
33413341
class Baz extends Foo {
33423342
bar() {
3343-
const $jscomp$async$this$98447280$3 = this, $jscomp$async$super$get$98447280$5$bar =
3343+
var $jscomp$async$this$98447280$3 = this, $jscomp$async$super$get$98447280$5$bar =
33443344
() => super.bar;
33453345
return (0, $jscomp.asyncExecutePromiseGeneratorFunction)(function*() {
33463346
yield Promise.resolve();
@@ -3395,7 +3395,7 @@ class Foo {
33953395
}
33963396
class Baz extends Foo {
33973397
bar() {
3398-
const $jscomp$asyncIter$this$98447280$1 = this,
3398+
var $jscomp$asyncIter$this$98447280$1 = this,
33993399
$jscomp$asyncIter$super$get$bar =
34003400
() => super.bar;
34013401
return new $jscomp.AsyncGeneratorWrapper(function*() {
@@ -4987,7 +4987,7 @@ async function bar() {
49874987
+ """
49884988
async function* foo() {yield 1; await 0; yield 2}
49894989
async function bar() {
4990-
for await (const val of foo())
4990+
for await (let val of foo())
49914991
console.log(val)
49924992
}
49934993
bar()
@@ -5177,7 +5177,7 @@ public void testNewTarget() {
51775177
"""
51785178
window.a = class {
51795179
constructor() {
5180-
let b = new.target;
5180+
var b = new.target;
51815181
return Object.create(b.prototype);
51825182
}
51835183
};
@@ -5314,8 +5314,8 @@ public void performantWithAsyncStacks_doesNotRemoveAsyncAwait2() {
53145314
"class C { async f(p) { let obj = await p; return obj?.prop; } }",
53155315
"""
53165316
let C=function(){};
5317-
C.prototype.f=async function(p){let obj=await p;
5318-
let $jscomp$optchain$tmp98447280$0;
5317+
C.prototype.f=async function(p){var obj=await p;
5318+
var $jscomp$optchain$tmp98447280$0;
53195319
return($jscomp$optchain$tmp98447280$0=obj)==null?void 0:$jscomp$optchain$tmp98447280$0.prop}
53205320
""");
53215321
}

0 commit comments

Comments
 (0)