Skip to content

Commit 0ae96ea

Browse files
committed
Base support for coalescing & logical assignment
Base PR for #20531.
1 parent df5b37d commit 0ae96ea

File tree

5 files changed

+36
-9
lines changed

5 files changed

+36
-9
lines changed

src/settings.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1768,10 +1768,10 @@ var AUTO_NATIVE_LIBRARIES = true;
17681768
// versions >= MIN_FIREFOX_VERSION
17691769
// are desired to work. Pass -sMIN_FIREFOX_VERSION=majorVersion to drop support
17701770
// for Firefox versions older than < majorVersion.
1771-
// Firefox ESR 68 was released on July 9, 2019.
1771+
// Firefox 79 was released on 2020-07-28.
17721772
// MAX_INT (0x7FFFFFFF, or -1) specifies that target is not supported.
17731773
// [link]
1774-
var MIN_FIREFOX_VERSION = 68;
1774+
var MIN_FIREFOX_VERSION = 79;
17751775

17761776
// Specifies the oldest version of desktop Safari to target. Version is encoded
17771777
// in MMmmVV, e.g. 70101 denotes Safari 7.1.1.
@@ -1810,10 +1810,10 @@ var MIN_EDGE_VERSION = 0x7FFFFFFF;
18101810

18111811
// Specifies the oldest version of Chrome. E.g. pass -sMIN_CHROME_VERSION=58 to
18121812
// drop support for Chrome 57 and older.
1813-
// Chrome 75.0.3770 was released on 2019-06-04
1813+
// Chrome 85 was released on 2020-08-25.
18141814
// MAX_INT (0x7FFFFFFF, or -1) specifies that target is not supported.
18151815
// [link]
1816-
var MIN_CHROME_VERSION = 75;
1816+
var MIN_CHROME_VERSION = 85;
18171817

18181818
// Specifies minimum node version to target for the generated code. This is
18191819
// distinct from the minimum version required run the emscripten compiler.

test/test_other.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12945,14 +12945,16 @@ def test_es5_transpile(self, args):
1294512945
# - arrow funcs
1294612946
# - for..of
1294712947
# - object.assign
12948+
# - nullish coalescing & chaining
12949+
# - logical assignment
1294812950
create_file('es6_library.js', '''\
1294912951
addToLibrary({
1295012952
foo: function(arg="hello") {
1295112953
// Object.assign + let
1295212954
let obj = Object.assign({}, {prop:1});
1295312955
err('prop: ' + obj.prop);
1295412956

12955-
// arror funcs + const
12957+
// arrow funcs + const
1295612958
const bar = () => 2;
1295712959
err('bar: ' + bar());
1295812960

@@ -12969,6 +12971,22 @@ def test_es5_transpile(self, args):
1296912971
};
1297012972
global['foo'] = obj3;
1297112973
err('value2: ' + obj3.myMethod());
12974+
12975+
// Nullish coalescing
12976+
var definitely = global['maybe'] ?? {};
12977+
12978+
// Optional chaining
12979+
global['maybe']
12980+
?.subObj
12981+
?.[key]
12982+
?.func
12983+
?.();
12984+
12985+
// Logical assignment
12986+
var obj4 = null;
12987+
obj4 ??= 0;
12988+
obj4 ||= 1;
12989+
obj4 &&= 2;
1297212990
}
1297312991
});
1297412992
''')
@@ -12983,13 +13001,22 @@ def check_for_es6(filename, expect):
1298313001
self.assertContained(['() => 2', '()=>2'], js)
1298413002
self.assertContained('const ', js)
1298513003
self.assertContained('let ', js)
13004+
self.assertContained('?.[', js)
13005+
self.assertContained('?.(', js)
13006+
self.assertContained('??=', js)
13007+
self.assertContained('||=', js)
13008+
self.assertContained('&&=', js)
1298613009
else:
1298713010
self.verify_es5(filename)
1298813011
self.assertNotContained('foo(arg=', js)
1298913012
self.assertNotContained('() => 2', js)
1299013013
self.assertNotContained('()=>2', js)
1299113014
self.assertNotContained('const ', js)
1299213015
self.assertNotContained('let ', js)
13016+
self.assertNotContained('??', js)
13017+
self.assertNotContained('?.', js)
13018+
self.assertNotContained('||=', js)
13019+
self.assertNotContained('&&=', js)
1299313020

1299413021
# Check that under normal circumstances none of these features get
1299513022
# removed / transpiled.

tools/acorn-optimizer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,7 +1044,7 @@ function applyDCEGraphRemovals(ast) {
10441044

10451045
// Need a parser to pass to acorn.Node constructor.
10461046
// Create it once and reuse it.
1047-
const stubParser = new acorn.Parser({ecmaVersion: 2020});
1047+
const stubParser = new acorn.Parser({ecmaVersion: 2021});
10481048

10491049
function createNode(props) {
10501050
const node = new acorn.Node(stubParser);
@@ -2008,7 +2008,7 @@ let ast;
20082008
try {
20092009
ast = acorn.parse(input, {
20102010
// Keep in sync with --language_in that we pass to closure in building.py
2011-
ecmaVersion: 2020,
2011+
ecmaVersion: 2021,
20122012
preserveParens: closureFriendly,
20132013
onComment: closureFriendly ? sourceComments : undefined,
20142014
sourceType: exportES6 ? 'module' : 'script',

tools/building.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ def closure_compiler(filename, advanced=True, extra_closure_args=None):
567567

568568
args = ['--compilation_level', 'ADVANCED_OPTIMIZATIONS' if advanced else 'SIMPLE_OPTIMIZATIONS']
569569
# Keep in sync with ecmaVersion in tools/acorn-optimizer.js
570-
args += ['--language_in', 'ECMASCRIPT_2020']
570+
args += ['--language_in', 'ECMASCRIPT_2021']
571571
# Tell closure not to do any transpiling or inject any polyfills.
572572
# At some point we may want to look into using this as way to convert to ES5 but
573573
# babel is perhaps a better tool for that.

tools/unsafe_optimizations.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ function optPassMergeVarInitializationAssignments(ast) {
223223
}
224224

225225
function runOnJsText(js, pretty = false) {
226-
const ast = acorn.parse(js, {ecmaVersion: 2020});
226+
const ast = acorn.parse(js, {ecmaVersion: 2021});
227227

228228
optPassSimplifyModuleInitialization(ast);
229229
optPassRemoveRedundantOperatorNews(ast);

0 commit comments

Comments
 (0)