From 155a302e740bc8e36841c5d6117e11603a7af045 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Thu, 2 Nov 2023 16:47:33 +0100 Subject: [PATCH] Use even more optional chaining in the code-base --- src/display/xfa_layer.js | 2 +- test/test.mjs | 4 ++-- test/unit/xfa_tohtml_spec.js | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/display/xfa_layer.js b/src/display/xfa_layer.js index 9f713edbe..59b0dcac7 100644 --- a/src/display/xfa_layer.js +++ b/src/display/xfa_layer.js @@ -244,7 +244,7 @@ class XfaLayer { }); } - if (child.children && child.children.length > 0) { + if (child.children?.length > 0) { stack.push([child, -1, childHtml]); } else if (child.value) { const node = document.createTextNode(child.value); diff --git a/test/test.mjs b/test/test.mjs index a3dfa741b..704e5f3d4 100644 --- a/test/test.mjs +++ b/test/test.mjs @@ -460,7 +460,7 @@ function checkEq(task, results, browser, masterMode) { } const pageResult = pageResults[page]; let testSnapshot = pageResult.snapshot; - if (testSnapshot && testSnapshot.startsWith("data:image/png;base64,")) { + if (testSnapshot?.startsWith("data:image/png;base64,")) { testSnapshot = Buffer.from(testSnapshot.substring(22), "base64"); } else { console.error("Valid snapshot was not found."); @@ -759,7 +759,7 @@ function refTestPostHandler(req, res) { }); } - var isDone = taskResults.at(-1) && taskResults.at(-1)[lastPageNum - 1]; + var isDone = taskResults.at(-1)?.[lastPageNum - 1]; if (isDone) { checkRefTestResults(browser, id, taskResults); session.remaining--; diff --git a/test/unit/xfa_tohtml_spec.js b/test/unit/xfa_tohtml_spec.js index 36372e693..294573d89 100644 --- a/test/unit/xfa_tohtml_spec.js +++ b/test/unit/xfa_tohtml_spec.js @@ -20,7 +20,7 @@ describe("XFAFactory", function () { function searchHtmlNode(root, name, value, byAttributes = false, nth = [0]) { if ( (!byAttributes && root[name] === value) || - (byAttributes && root.attributes && root.attributes[name] === value) + (byAttributes && root.attributes?.[name] === value) ) { if (nth[0]-- === 0) { return root;