Issue #3487449 by tom konda: Prefer to replace some of typeof obj !== 'undefined' with optional chaining

merge-requests/10251/head
nod_ 2024-11-19 14:36:46 +01:00
parent e116e04506
commit 1c33460a8c
No known key found for this signature in database
GPG Key ID: 76624892606FA197
4 changed files with 6 additions and 22 deletions

View File

@ -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}`);
}
};

View File

@ -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;
}

View File

@ -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(

View File

@ -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;
}