Skip to content

Commit 894e0ae

Browse files
committed
Base support for coalescing & logical assignment
Base PR for #20531.
1 parent afa27ab commit 894e0ae

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
@@ -12966,14 +12966,16 @@ def test_es5_transpile(self, args):
1296612966
# - arrow funcs
1296712967
# - for..of
1296812968
# - object.assign
12969+
# - nullish coalescing & chaining
12970+
# - logical assignment
1296912971
create_file('es6_library.js', '''\
1297012972
addToLibrary({
1297112973
foo: function(arg="hello") {
1297212974
// Object.assign + let
1297312975
let obj = Object.assign({}, {prop:1});
1297412976
err('prop: ' + obj.prop);
1297512977

12976-
// arror funcs + const
12978+
// arrow funcs + const
1297712979
const bar = () => 2;
1297812980
err('bar: ' + bar());
1297912981

@@ -12990,6 +12992,22 @@ def test_es5_transpile(self, args):
1299012992
};
1299112993
global['foo'] = obj3;
1299212994
err('value2: ' + obj3.myMethod());
12995+
12996+
// Nullish coalescing
12997+
var definitely = global['maybe'] ?? {};
12998+
12999+
// Optional chaining
13000+
global['maybe']
13001+
?.subObj
13002+
?.[key]
13003+
?.func
13004+
?.();
13005+
13006+
// Logical assignment
13007+
var obj4 = null;
13008+
obj4 ??= 0;
13009+
obj4 ||= 1;
13010+
obj4 &&= 2;
1299313011
}
1299413012
});
1299513013
''')
@@ -13004,13 +13022,22 @@ def check_for_es6(filename, expect):
1300413022
self.assertContained(['() => 2', '()=>2'], js)
1300513023
self.assertContained('const ', js)
1300613024
self.assertContained('let ', js)
13025+
self.assertContained('?.[', js)
13026+
self.assertContained('?.(', js)
13027+
self.assertContained('??=', js)
13028+
self.assertContained('||=', js)
13029+
self.assertContained('&&=', js)
1300713030
else:
1300813031
self.verify_es5(filename)
1300913032
self.assertNotContained('foo(arg=', js)
1301013033
self.assertNotContained('() => 2', js)
1301113034
self.assertNotContained('()=>2', js)
1301213035
self.assertNotContained('const ', js)
1301313036
self.assertNotContained('let ', js)
13037+
self.assertNotContained('??', js)
13038+
self.assertNotContained('?.', js)
13039+
self.assertNotContained('||=', js)
13040+
self.assertNotContained('&&=', js)
1301413041

1301513042
# Check that under normal circumstances none of these features get
1301613043
# 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)