Skip to content

Commit 6353ace

Browse files
Merge pull request #21508 from Snuffleupagus/optional-chaining-not-length
Use more optional chaining in the `src/` and `web/` folders
2 parents 8bdd159 + b7b3a4c commit 6353ace

6 files changed

Lines changed: 8 additions & 8 deletions

File tree

‎src/core/editor/pdf_editor.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2688,7 +2688,7 @@ class PDFEditor {
26882688
*/
26892689
#makePageLabelsTree() {
26902690
const { pageLabels } = this;
2691-
if (!pageLabels || pageLabels.length === 0) {
2691+
if (!pageLabels?.length) {
26922692
return;
26932693
}
26942694
const { rootDict } = this;
@@ -2776,7 +2776,7 @@ class PDFEditor {
27762776

27772777
#makeStructTree() {
27782778
const { structTreeKids } = this;
2779-
if (!structTreeKids || structTreeKids.length === 0) {
2779+
if (!structTreeKids?.length) {
27802780
return;
27812781
}
27822782
const { rootDict } = this;

‎src/display/editor/drawers/inkdraw.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class InkDrawOutliner {
7272
}
7373

7474
isEmpty() {
75-
return !this.#lines || this.#lines.length === 0;
75+
return !this.#lines?.length;
7676
}
7777

7878
isCancellable() {

‎src/display/editor/freetext.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,7 @@ class FreeTextEditor extends AnnotationEditor {
800800
} = data;
801801
// textContent is supposed to be an array of strings containing each line
802802
// of text. However, it can be null or empty.
803-
if (!textContent || textContent.length === 0) {
803+
if (!textContent?.length) {
804804
// Empty annotation.
805805
return null;
806806
}

‎web/app.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,7 @@ const PDFViewerApplication = {
846846

847847
fileInput.addEventListener("change", function (evt) {
848848
const { files } = evt.target;
849-
if (!files || files.length === 0) {
849+
if (!files?.length) {
850850
return;
851851
}
852852
eventBus.dispatch("fileinputchange", {

‎web/internal/draw_ops_view.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ class DrawOpDetailView {
237237
header.textContent = name;
238238
argsContainer.append(header);
239239

240-
if (!args || args.length === 0) {
240+
if (!args?.length) {
241241
const none = document.createElement("div");
242242
none.className = "detail-empty";
243243
none.textContent = "(no arguments)";

‎web/text_accessibility.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ class TextAccessibilityManager {
138138
}
139139

140140
const children = this.#textChildren;
141-
if (!children || children.length === 0) {
141+
if (!children?.length) {
142142
return;
143143
}
144144

@@ -198,7 +198,7 @@ class TextAccessibilityManager {
198198
}
199199

200200
const children = this.#textChildren;
201-
if (!children || children.length === 0) {
201+
if (!children?.length) {
202202
return null;
203203
}
204204

0 commit comments

Comments
 (0)