Verified Commit 1c33460a authored by Théodore Biadala's avatar Théodore Biadala
Browse files

Issue #3487449 by tom konda: Prefer to replace some of typeof obj !==...

Issue #3487449 by tom konda: Prefer to replace some of typeof obj !== 'undefined' with optional chaining
parent e116e045
Loading
Loading
Loading
Loading
Loading
+3 −15
Original line number Diff line number Diff line
@@ -370,12 +370,7 @@ window.Drupal = { behaviors: {}, locale: {} };
    options.context = options.context || '';

    // Fetch the localized version of the string.
    if (
      typeof drupalTranslations !== 'undefined' &&
      drupalTranslations.strings &&
      drupalTranslations.strings[options.context] &&
      drupalTranslations.strings[options.context][str]
    ) {
    if (drupalTranslations?.strings?.[options.context]?.[str]) {
      str = drupalTranslations.strings[options.context][str];
    }

@@ -518,10 +513,7 @@ window.Drupal = { behaviors: {}, locale: {} };
    let index = 0;

    // Determine the index of the plural form.
    if (
      typeof drupalTranslations !== 'undefined' &&
      drupalTranslations.pluralFormula
    ) {
    if (drupalTranslations?.pluralFormula) {
      index =
        count in drupalTranslations.pluralFormula
          ? drupalTranslations.pluralFormula[count]
@@ -562,11 +554,7 @@ window.Drupal = { behaviors: {}, locale: {} };
   * @see https://www.drupal.org/core/deprecation#javascript
   */
  Drupal.deprecationError = ({ message }) => {
    if (
      drupalSettings.suppressDeprecationErrors === false &&
      typeof console !== 'undefined' &&
      console.warn
    ) {
    if (drupalSettings.suppressDeprecationErrors === false && console?.warn) {
      console.warn(`[Deprecation] ${message}`);
    }
  };
+1 −4
Original line number Diff line number Diff line
@@ -78,10 +78,7 @@
  Drupal.behaviors.blockDrag = {
    attach(context, settings) {
      // tableDrag is required and we should be on the blocks admin page.
      if (
        typeof Drupal.tableDrag === 'undefined' ||
        typeof Drupal.tableDrag.blocks === 'undefined'
      ) {
      if (typeof Drupal?.tableDrag?.blocks === 'undefined') {
        return;
      }

+1 −1
Original line number Diff line number Diff line
@@ -3,7 +3,7 @@
 *  Support code for testing JavaScript error handling in functional tests.
 */
(function () {
  if (typeof console !== 'undefined' && console.warn) {
  if (console?.warn) {
    const originalWarnFunction = console.warn;
    console.warn = (warning) => {
      const warnings = JSON.parse(
+1 −2
Original line number Diff line number Diff line
@@ -1332,8 +1332,7 @@
    attach(context) {
      // Only act on the rearrange filter form.
      if (
        typeof Drupal.tableDrag === 'undefined' ||
        typeof Drupal.tableDrag['views-rearrange-filters'] === 'undefined'
        typeof Drupal?.tableDrag?.['views-rearrange-filters'] === 'undefined'
      ) {
        return;
      }