
Problem/Motivation
As discovered in #3305706-23: Uncaught TypeError: this.$pluginSelect.find(...)[0] is undefined our scripts/dev/commit-code-check.sh
doesn't allow optional chaining in JavaScript.
So for example, this this.$pluginSelect.find('option')[0]?.value;
is being rejected by the script with the following output:
----------------------------------------------------------------------------------------------------
Checking core/modules/field_ui/field_ui.js
/var/www/html/core/modules/field_ui/field_ui.js
371:52 error Parsing error: Unexpected token .
✖ 1 problem (1 error, 0 warnings)
----------------------------------------------------------------------------------------------------
(https://www.drupal.org/pift-ci-job/2561443)
Since we dropped support for IE10 in Drupal 10.x, we should allow for ?
to come before a .
from 10.0.x-dev
upwards
Steps to reproduce
Allow for ?
to come before a .
from 10.0.x-dev
upwards
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
ESLint now allows ES11/ECMAScript 2020 syntax to be used in JavaScript as it is supported by all modern browsers.
Comment | File | Size | Author |
---|---|---|---|
#6 | 3335653-with-example.patch | 812 bytes | mherchel |
#6 | 3335653.patch | 322 bytes | mherchel |
#5 | optional-chaning-example.patch | 490 bytes | mherchel |
Comments
Comment #2
spokjeComment #3
spokjeComment #4
spokjeComment #5
mherchel+💯 on getting this fixed. Optional chaining has the opportunity to reduce a lot of unnecessary
if
statementsComment #6
mherchelComment #7
smustgrave commentedShould the example failed?
Comment #8
mherchelComment #9
smustgrave commentedAh thanks for explaining. LGTM!
Comment #10
longwaveConfirmed with caniuse.com that all ES11/ECMAScript 2020 features can be used in modern browsers that we support; see "Feature support list" at https://caniuse.com/sr_es11
Backported to 10.1.x to allow us to keep JavaScript changes in sync more easily if needed.
Committed and pushed 91c7840 to 11.x and 0372205 to 10.1.x. Thanks!
Also added a release note in case others are using our ESLint config.