Skip to content

Commit b0005bd

Browse files
committed
Allow optional chaining in JS library code
This change verifies that closure can successfully lower the optional chaining away on older browsers. This also requires bumping of chrome and safari minimum versions.. so maybe its not worth it?
1 parent 3134b14 commit b0005bd

File tree

4 files changed

+19
-4
lines changed

4 files changed

+19
-4
lines changed

emcc.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2311,6 +2311,8 @@ def phase_linker_setup(options, state, newargs):
23112311
settings.MIN_CHROME_VERSION < 49 or
23122312
settings.MIN_SAFARI_VERSION < 110000 or
23132313
settings.MIN_IE_VERSION != 0x7FFFFFFF)
2314+
if not feature_matrix.caniuse(feature_matrix.Feature.OPTIONAL_CHAINING):
2315+
settings.TRANSPILE_TO_ES5 = True
23142316

23152317
if options.use_closure_compiler is None and settings.TRANSPILE_TO_ES5:
23162318
diagnostics.warning('transpile', 'enabling transpilation via closure due to browser version settings. This warning can be suppressed by passing `--closure=1` or `--closure=0` to opt into our explicitly.')

src/settings.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1764,10 +1764,10 @@ var AUTO_NATIVE_LIBRARIES = true;
17641764
// versions >= MIN_FIREFOX_VERSION
17651765
// are desired to work. Pass -sMIN_FIREFOX_VERSION=majorVersion to drop support
17661766
// for Firefox versions older than < majorVersion.
1767-
// Firefox ESR 68 was released on July 9, 2019.
1767+
// Firefox ESR 74 was released on March 10, 2020
17681768
// MAX_INT (0x7FFFFFFF, or -1) specifies that target is not supported.
17691769
// [link]
1770-
var MIN_FIREFOX_VERSION = 68;
1770+
var MIN_FIREFOX_VERSION = 74;
17711771

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

18071807
// Specifies the oldest version of Chrome. E.g. pass -sMIN_CHROME_VERSION=58 to
18081808
// drop support for Chrome 57 and older.
1809-
// Chrome 75.0.3770 was released on 2019-06-04
1809+
// Chrome 80 was released on February 4, 2020
18101810
// MAX_INT (0x7FFFFFFF, or -1) specifies that target is not supported.
18111811
// [link]
1812-
var MIN_CHROME_VERSION = 75;
1812+
var MIN_CHROME_VERSION = 80;
18131813

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

test/test_other.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12802,6 +12802,10 @@ def test_es5_transpile(self, args):
1280212802
};
1280312803
global['foo'] = obj3;
1280412804
err('value2: ' + obj3.myMethod());
12805+
12806+
// optional chaining
12807+
let result = Module.foo?.doSomething();
12808+
err('result: ' + result);
1280512809
}
1280612810
});
1280712811
''')
@@ -12816,13 +12820,15 @@ def check_for_es6(filename, expect):
1281612820
self.assertContained(['() => 2', '()=>2'], js)
1281712821
self.assertContained('const ', js)
1281812822
self.assertContained('let ', js)
12823+
self.assertContained('foo?.doSomething()', js)
1281912824
else:
1282012825
self.verify_es5(filename)
1282112826
self.assertNotContained('foo(arg=', js)
1282212827
self.assertNotContained('() => 2', js)
1282312828
self.assertNotContained('()=>2', js)
1282412829
self.assertNotContained('const ', js)
1282512830
self.assertNotContained('let ', js)
12831+
self.assertNotContained('foo?.doSomething()', js)
1282612832

1282712833
# Check that under normal circumstances none of these features get
1282812834
# removed / transpiled.

tools/feature_matrix.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class Feature(IntEnum):
2323
THREADS = auto()
2424
GLOBALTHIS = auto()
2525
PROMISE_ANY = auto()
26+
OPTIONAL_CHAINING = auto()
2627

2728

2829
default_features = {Feature.SIGN_EXT, Feature.MUTABLE_GLOBALS}
@@ -71,6 +72,12 @@ class Feature(IntEnum):
7172
'safari': 140000,
7273
'node': 150000,
7374
},
75+
Feature.OPTIONAL_CHAINING: {
76+
'chrome': 80,
77+
'firefox': 74,
78+
'safari': 130400,
79+
'node': 140000,
80+
},
7481
}
7582

7683

0 commit comments

Comments
 (0)