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.

Comments

Spokje created an issue. See original summary.

spokje’s picture

spokje’s picture

Issue summary: View changes
spokje’s picture

Issue summary: View changes
mherchel’s picture

Version: 10.0.x-dev » 11.x-dev
StatusFileSize
new490 bytes

+💯 on getting this fixed. Optional chaining has the opportunity to reduce a lot of unnecessary if statements

mherchel’s picture

Status: Active » Needs review
StatusFileSize
new322 bytes
new812 bytes
smustgrave’s picture

Should the example failed?

mherchel’s picture

Should the example failed?

  • The example in #5 fails because it has optional chaining (but not the fix).
  • The example file in #6 passes because in addition to the file with optional chaining, it contains the fix. This demonstrates that the patch works as intended!
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Ah thanks for explaining. LGTM!

longwave’s picture

Version: 11.x-dev » 10.1.x-dev
Issue summary: View changes
Status: Reviewed & tested by the community » Fixed
Issue tags: +10.2.0 release notes, +10.1.4 release notes

Confirmed 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.

  • longwave committed 03722059 on 10.1.x
    Issue #3335653 by mherchel, Spokje: commit-code-check.sh doesn't allow...

  • longwave committed 91c7840b on 11.x
    Issue #3335653 by mherchel, Spokje: commit-code-check.sh doesn't allow...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.