diff --git a/packages/yoastseo/src/parse/build/build.js b/packages/yoastseo/src/parse/build/build.js index b96bab84afd..0720d71797e 100644 --- a/packages/yoastseo/src/parse/build/build.js +++ b/packages/yoastseo/src/parse/build/build.js @@ -25,7 +25,7 @@ export default function build( paper, languageProcessor, shortcodes ) { html = html.replace( htmlEntitiesRegex, "#$1" ); let tree = adapt( parseFragment( html, { sourceCodeLocationInfo: true } ) ); - if ( tree.childNodes && tree.childNodes.length > 0 ) { + if ( tree.childNodes?.length > 0 ) { parseBlocks( paper, tree ); } diff --git a/packages/yoastseo/src/parse/build/private/adapt.js b/packages/yoastseo/src/parse/build/private/adapt.js index 1f76f1d9391..6882dadb4e1 100644 --- a/packages/yoastseo/src/parse/build/private/adapt.js +++ b/packages/yoastseo/src/parse/build/private/adapt.js @@ -65,7 +65,7 @@ function isBlockElement( nodeName ) { function isOverarchingParagraph( nodeName, children ) { return isParagraph( nodeName ) && children.some( ( node, index, childNodes ) => { const nextNode = childNodes.length - 1 !== index && childNodes[ index + 1 ]; - return node.name === "br" && nextNode && nextNode.name === "br"; + return node.name === "br" && nextNode?.name === "br"; } ); } diff --git a/packages/yoastseo/src/parse/build/private/combineIntoImplicitParagraphs.js b/packages/yoastseo/src/parse/build/private/combineIntoImplicitParagraphs.js index 5157f0c8e08..3b4938654e0 100644 --- a/packages/yoastseo/src/parse/build/private/combineIntoImplicitParagraphs.js +++ b/packages/yoastseo/src/parse/build/private/combineIntoImplicitParagraphs.js @@ -24,7 +24,7 @@ function isInterElementWhitespace( node ) { * @returns {boolean} Whether the node has any children. */ function hasChildren( node ) { - return node && node.childNodes.length > 0; + return node?.childNodes.length > 0; } /** diff --git a/packages/yoastseo/src/parse/build/private/filterHelpers.js b/packages/yoastseo/src/parse/build/private/filterHelpers.js index 2873042daa7..8fb6e7a460a 100644 --- a/packages/yoastseo/src/parse/build/private/filterHelpers.js +++ b/packages/yoastseo/src/parse/build/private/filterHelpers.js @@ -26,7 +26,7 @@ export function elementHasName( name ) { */ export function elementHasClass( className ) { return ( blockElement ) => { - return !! blockElement.attributes.class && blockElement.attributes.class.has( className ); + return !! blockElement.attributes.class?.has( className ); }; } diff --git a/packages/yoastseo/src/parse/build/private/parseBlocks.js b/packages/yoastseo/src/parse/build/private/parseBlocks.js index 300a41850d5..b0919a69dc7 100644 --- a/packages/yoastseo/src/parse/build/private/parseBlocks.js +++ b/packages/yoastseo/src/parse/build/private/parseBlocks.js @@ -1,4 +1,3 @@ -import { isUndefined } from "lodash"; const blockTokenizer = /)[^])*)\5|[^]*?)}\s+)?(\/)?-->/g; /** @@ -67,7 +66,7 @@ export function updateBlocksOffset( blocks, text ) { currentBlock.contentOffset = startedAt + length + 1; } - if ( currentBlock.innerBlocks && currentBlock.innerBlocks.length > 0 ) { + if ( currentBlock.innerBlocks?.length > 0 ) { updateBlocksOffset( currentBlock.innerBlocks, text ); } } ); @@ -90,7 +89,7 @@ function updateClientIdAndAttrIdForSubtree( rootNode, blocks, clientId ) { } let currentClientId = clientId; - if ( rootNode.sourceCodeLocation && ! isUndefined( rootNode.sourceCodeLocation.startOffset ) ) { + if ( rootNode.sourceCodeLocation?.startOffset ) { const foundBlock = blocks.find( block => block.contentOffset === rootNode.sourceCodeLocation.startOffset ); if ( foundBlock ) { currentClientId = foundBlock.clientId; @@ -104,7 +103,7 @@ function updateClientIdAndAttrIdForSubtree( rootNode, blocks, clientId ) { // If the node has children, update the clientId for them. ( rootNode.childNodes || [] ).forEach( ( node ) => { - if ( node.attributes && node.attributes.id ) { + if ( node.attributes?.id ) { /* * If the node's child has an attribute with 'id' key, also set this id to the first and third child node. * This step is specifically for parsing the Yoast blocks. @@ -118,7 +117,7 @@ function updateClientIdAndAttrIdForSubtree( rootNode, blocks, clientId ) { * - For example, in Yoast FAQ block, the second child node would represent the "answer" section. * 4. The fourth child node of the sub-block, only contains a new line. */ - if ( node.childNodes && node.childNodes.length > 3 ) { + if ( node.childNodes?.length > 3 ) { node.childNodes[ 0 ].attributeId = node.attributes.id; node.childNodes[ 0 ].isFirstSection = true;