Skip to content

Commit 0060eeb

Browse files
committed
Use more logical assignment in the code-base
1 parent a9e439b commit 0060eeb

File tree

5 files changed

+12
-35
lines changed

5 files changed

+12
-35
lines changed

examples/mobile-viewer/viewer.mjs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,18 +158,15 @@ const PDFViewerApplication = {
158158
);
159159

160160
let pdfTitle;
161-
if (metadata && metadata.has("dc:title")) {
161+
if (metadata?.has("dc:title")) {
162162
const title = metadata.get("dc:title");
163163
// Ghostscript sometimes returns 'Untitled', so prevent setting the
164164
// title to 'Untitled.
165165
if (title !== "Untitled") {
166166
pdfTitle = title;
167167
}
168168
}
169-
170-
if (!pdfTitle && info && info.Title) {
171-
pdfTitle = info.Title;
172-
}
169+
pdfTitle ||= info?.Title;
173170

174171
if (pdfTitle) {
175172
this.setTitle(pdfTitle + " - " + document.title);

src/core/default_appearance.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,8 @@ function createDefaultAppearance({ fontSize, fontName, fontColor }) {
246246
}
247247

248248
class FakeUnicodeFont {
249+
static #fontNameId = 1;
250+
249251
constructor(xref, fontFamily) {
250252
this.xref = xref;
251253
this.widths = null;
@@ -256,11 +258,8 @@ class FakeUnicodeFont {
256258
const canvas = new OffscreenCanvas(1, 1);
257259
this.ctxMeasure = canvas.getContext("2d", { willReadFrequently: true });
258260

259-
if (!FakeUnicodeFont._fontNameId) {
260-
FakeUnicodeFont._fontNameId = 1;
261-
}
262261
this.fontName = Name.get(
263-
`InvalidPDFjsFont_${fontFamily}_${FakeUnicodeFont._fontNameId++}`
262+
`InvalidPDFjsFont_${fontFamily}_${FakeUnicodeFont.#fontNameId++}`
264263
);
265264
}
266265

src/core/jbig2.js

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1677,11 +1677,7 @@ class SimpleSegmentVisitor {
16771677
}
16781678

16791679
// Combines exported symbols from all referred segments
1680-
let symbols = this.symbols;
1681-
if (!symbols) {
1682-
this.symbols = symbols = {};
1683-
}
1684-
1680+
const symbols = (this.symbols ||= {});
16851681
const inputSymbols = [];
16861682
for (const referredSegment of referredSegments) {
16871683
const referredSymbols = symbols[referredSegment];
@@ -1766,10 +1762,7 @@ class SimpleSegmentVisitor {
17661762
}
17671763

17681764
onPatternDictionary(dictionary, currentSegment, data, start, end) {
1769-
let patterns = this.patterns;
1770-
if (!patterns) {
1771-
this.patterns = patterns = {};
1772-
}
1765+
const patterns = (this.patterns ||= {});
17731766
const decodingContext = new DecodingContext(data, start, end);
17741767
patterns[currentSegment] = decodePatternDictionary(
17751768
dictionary.mmr,
@@ -1811,10 +1804,7 @@ class SimpleSegmentVisitor {
18111804
}
18121805

18131806
onTables(currentSegment, data, start, end) {
1814-
let customTables = this.customTables;
1815-
if (!customTables) {
1816-
this.customTables = customTables = {};
1817-
}
1807+
const customTables = (this.customTables ||= {});
18181808
customTables[currentSegment] = decodeTablesSegment(data, start, end);
18191809
}
18201810
}
@@ -1865,10 +1855,7 @@ class HuffmanTreeNode {
18651855
this.children[bit] = new HuffmanTreeNode(line);
18661856
} else {
18671857
// Create an intermediate node and continue recursively.
1868-
let node = this.children[bit];
1869-
if (!node) {
1870-
this.children[bit] = node = new HuffmanTreeNode(null);
1871-
}
1858+
const node = (this.children[bit] ||= new HuffmanTreeNode(null));
18721859
node.buildTree(line, shift - 1);
18731860
}
18741861
}

src/core/xfa/text.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,7 @@ class FontSelector {
110110
"size",
111111
"letterSpacing",
112112
]) {
113-
if (!xfaFont[name]) {
114-
xfaFont[name] = lastFont.xfaFont[name];
115-
}
113+
xfaFont[name] ||= lastFont.xfaFont[name];
116114
}
117115

118116
for (const name of ["top", "bottom", "left", "right"]) {
@@ -127,9 +125,7 @@ class FontSelector {
127125
lineHeight || lastFont.lineHeight,
128126
this.fontFinder
129127
);
130-
if (!fontInfo.pdfFont) {
131-
fontInfo.pdfFont = lastFont.pdfFont;
132-
}
128+
fontInfo.pdfFont ||= lastFont.pdfFont;
133129

134130
this.stack.push(fontInfo);
135131
}

web/internal/canvas_context_details_view.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,7 @@ class CanvasContextDetailsView {
199199
if (type !== "2d") {
200200
return ctx;
201201
}
202-
if (!wrappedCtx) {
203-
wrappedCtx = this.wrapContext(ctx, label);
204-
}
202+
wrappedCtx ??= this.wrapContext(ctx, label);
205203
return wrappedCtx;
206204
};
207205
return canvas.getContext("2d");

0 commit comments

Comments
 (0)