diff --git a/src/core/annotation.js b/src/core/annotation.js index e642b3d83..f040738ef 100644 --- a/src/core/annotation.js +++ b/src/core/annotation.js @@ -560,10 +560,9 @@ class Annotation { * @param {AnnotationStorage} [annotationStorage] - Storage for annotation */ mustBeViewed(annotationStorage) { - const storageEntry = - annotationStorage && annotationStorage.get(this.data.id); - if (storageEntry && storageEntry.hidden !== undefined) { - return !storageEntry.hidden; + const hidden = annotationStorage?.get(this.data.id)?.hidden; + if (hidden !== undefined) { + return !hidden; } return this.viewable && !this._hasFlag(this.flags, AnnotationFlag.HIDDEN); } @@ -578,10 +577,9 @@ class Annotation { * @param {AnnotationStorage} [annotationStorage] - Storage for annotation */ mustBePrinted(annotationStorage) { - const storageEntry = - annotationStorage && annotationStorage.get(this.data.id); - if (storageEntry && storageEntry.print !== undefined) { - return storageEntry.print; + const print = annotationStorage?.get(this.data.id)?.print; + if (print !== undefined) { + return print; } return this.printable; } @@ -1566,8 +1564,7 @@ class WidgetAnnotation extends Annotation { const localResources = getInheritableProperty({ dict, key: "DR" }); const acroFormResources = params.acroForm.get("DR"); - const appearanceResources = - this.appearance && this.appearance.dict.get("Resources"); + const appearanceResources = this.appearance?.dict.get("Resources"); this._fieldResources = { localResources, @@ -1627,10 +1624,7 @@ class WidgetAnnotation extends Annotation { } getRotationMatrix(annotationStorage) { - const storageEntry = annotationStorage - ? annotationStorage.get(this.data.id) - : undefined; - let rotation = storageEntry && storageEntry.rotation; + let rotation = annotationStorage?.get(this.data.id)?.rotation; if (rotation === undefined) { rotation = this.rotation; } @@ -1646,10 +1640,7 @@ class WidgetAnnotation extends Annotation { } getBorderAndBackgroundAppearances(annotationStorage) { - const storageEntry = annotationStorage - ? annotationStorage.get(this.data.id) - : undefined; - let rotation = storageEntry && storageEntry.rotation; + let rotation = annotationStorage?.get(this.data.id)?.rotation; if (rotation === undefined) { rotation = this.rotation; } @@ -1799,11 +1790,9 @@ class WidgetAnnotation extends Annotation { amendSavedDict(annotationStorage, dict) {} async save(evaluator, task, annotationStorage) { - const storageEntry = annotationStorage - ? annotationStorage.get(this.data.id) - : undefined; - let value = storageEntry && storageEntry.value; - let rotation = storageEntry && storageEntry.rotation; + const storageEntry = annotationStorage?.get(this.data.id); + let value = storageEntry?.value, + rotation = storageEntry?.rotation; if (value === this.data.fieldValue || value === undefined) { if (!this._hasValueFromXFA && rotation === undefined) { return null; @@ -1845,7 +1834,7 @@ class WidgetAnnotation extends Annotation { } let needAppearances = false; - if (appearance && appearance.needAppearances) { + if (appearance?.needAppearances) { needAppearances = true; appearance = null; } @@ -1949,10 +1938,7 @@ class WidgetAnnotation extends Annotation { if (isPassword) { return null; } - const storageEntry = annotationStorage - ? annotationStorage.get(this.data.id) - : undefined; - + const storageEntry = annotationStorage?.get(this.data.id); let value, rotation; if (storageEntry) { value = storageEntry.formattedValue || storageEntry.value; @@ -1993,7 +1979,7 @@ class WidgetAnnotation extends Annotation { const option = this.data.options.find( ({ exportValue }) => value === exportValue ); - value = (option && option.displayValue) || value; + value = option?.displayValue || value; } if (value === "") { @@ -2383,9 +2369,7 @@ class WidgetAnnotation extends Annotation { const { localResources, appearanceResources, acroFormResources } = this._fieldResources; - const fontName = - this.data.defaultAppearanceData && - this.data.defaultAppearanceData.fontName; + const fontName = this.data.defaultAppearanceData?.fontName; if (!fontName) { return localResources || Dict.empty; } @@ -2763,8 +2747,8 @@ class ButtonWidgetAnnotation extends WidgetAnnotation { return null; } const storageEntry = annotationStorage.get(this.data.id); - let rotation = storageEntry && storageEntry.rotation; - let value = storageEntry && storageEntry.value; + let rotation = storageEntry?.rotation, + value = storageEntry?.value; if (rotation === undefined) { if (value === undefined) { @@ -2825,8 +2809,8 @@ class ButtonWidgetAnnotation extends WidgetAnnotation { return null; } const storageEntry = annotationStorage.get(this.data.id); - let rotation = storageEntry && storageEntry.rotation; - let value = storageEntry && storageEntry.value; + let rotation = storageEntry?.rotation, + value = storageEntry?.value; if (rotation === undefined) { if (value === undefined) { @@ -3239,10 +3223,7 @@ class ChoiceWidgetAnnotation extends WidgetAnnotation { if (!this.hasIndices) { return; } - const storageEntry = annotationStorage - ? annotationStorage.get(this.data.id) - : undefined; - let values = storageEntry && storageEntry.value; + let values = annotationStorage?.get(this.data.id)?.value; if (!Array.isArray(values)) { values = [values]; } @@ -3263,10 +3244,7 @@ class ChoiceWidgetAnnotation extends WidgetAnnotation { } let exportedValue, rotation; - const storageEntry = annotationStorage - ? annotationStorage.get(this.data.id) - : undefined; - + const storageEntry = annotationStorage?.get(this.data.id); if (storageEntry) { rotation = storageEntry.rotation; exportedValue = storageEntry.value; @@ -4176,10 +4154,9 @@ class HighlightAnnotation extends MarkupAnnotation { const quadPoints = (this.data.quadPoints = getQuadPoints(dict, null)); if (quadPoints) { - const resources = - this.appearance && this.appearance.dict.get("Resources"); + const resources = this.appearance?.dict.get("Resources"); - if (!this.appearance || !(resources && resources.has("ExtGState"))) { + if (!this.appearance || !resources?.has("ExtGState")) { if (this.appearance) { // Workaround for cases where there's no /ExtGState-entry directly // available, e.g. when the appearance stream contains a /XObject of diff --git a/src/core/catalog.js b/src/core/catalog.js index da4ba665e..32e3b6477 100644 --- a/src/core/catalog.js +++ b/src/core/catalog.js @@ -162,10 +162,10 @@ class Catalog { let metadata = null; try { - const suppressEncryption = !( - this.xref.encrypt && this.xref.encrypt.encryptMetadata + const stream = this.xref.fetch( + streamRef, + /* suppressEncryption = */ !this.xref.encrypt?.encryptMetadata ); - const stream = this.xref.fetch(streamRef, suppressEncryption); if (stream instanceof BaseStream && stream.dict instanceof Dict) { const type = stream.dict.get("Type"); @@ -616,7 +616,7 @@ class Catalog { */ _readDests() { const obj = this._catDict.get("Names"); - if (obj && obj.has("Dests")) { + if (obj?.has("Dests")) { return new NameTree(obj.getRaw("Dests"), this.xref); } else if (this._catDict.has("Dests")) { // Simple destination dictionary. diff --git a/src/core/ccitt.js b/src/core/ccitt.js index 7bf396a1c..5b292d62d 100644 --- a/src/core/ccitt.js +++ b/src/core/ccitt.js @@ -942,7 +942,7 @@ class CCITTFaxDecoder { if (this.eoblock) { code = this._lookBits(7); p = twoDimTable[code]; - if (p && p[0] > 0) { + if (p?.[0] > 0) { this._eatBits(p[0]); return p[1]; } diff --git a/src/core/cff_font.js b/src/core/cff_font.js index ac4534252..a03341bc2 100644 --- a/src/core/cff_font.js +++ b/src/core/cff_font.js @@ -55,7 +55,7 @@ class CFFFont { if (properties.composite) { let invCidToGidMap; - if (cidToGidMap && cidToGidMap.length > 0) { + if (cidToGidMap?.length > 0) { invCidToGidMap = Object.create(null); for (let i = 0, ii = cidToGidMap.length; i < ii; i++) { const gid = cidToGidMap[i]; @@ -74,7 +74,7 @@ class CFFFont { const cid = charsets[glyphId]; charCode = cMap.charCodeOf(cid); - if (invCidToGidMap && invCidToGidMap[charCode] !== undefined) { + if (invCidToGidMap?.[charCode] !== undefined) { // According to the PDF specification, see Table 117, it's not clear // that a /CIDToGIDMap should be used with any non-TrueType fonts, // however it's necessary to do so in order to fix issue 15559. diff --git a/src/core/cff_parser.js b/src/core/cff_parser.js index 2e31028f5..ad563e208 100644 --- a/src/core/cff_parser.js +++ b/src/core/cff_parser.js @@ -1428,7 +1428,7 @@ class CFFCompiler { } const xuid = cff.topDict.getByName("XUID"); - if (xuid && xuid.length > 16) { + if (xuid?.length > 16) { // Length of XUID array must not be greater than 16 (issue #12399). cff.topDict.removeByName("XUID"); } diff --git a/src/core/core_utils.js b/src/core/core_utils.js index 54b032bfe..4b8fa637e 100644 --- a/src/core/core_utils.js +++ b/src/core/core_utils.js @@ -505,7 +505,7 @@ function recoverJsURL(str) { ); const jsUrl = regex.exec(str); - if (jsUrl && jsUrl[2]) { + if (jsUrl?.[2]) { const url = jsUrl[2]; let newWindow = false; diff --git a/src/core/crypto.js b/src/core/crypto.js index c2bdf66a9..7e87b0253 100644 --- a/src/core/crypto.js +++ b/src/core/crypto.js @@ -1698,7 +1698,7 @@ const CipherTransformFactory = (function CipherTransformFactoryClosure() { if (cfDict instanceof Dict && streamCryptoName instanceof Name) { cfDict.suppressEncryption = true; // See comment below. const handlerDict = cfDict.get(streamCryptoName.name); - keyLength = (handlerDict && handlerDict.get("Length")) || 128; + keyLength = handlerDict?.get("Length") || 128; if (keyLength < 40) { // Sometimes it's incorrect value of bits, generators specify // bytes. diff --git a/src/core/dataset_reader.js b/src/core/dataset_reader.js index 34dce7587..ef6d52c8d 100644 --- a/src/core/dataset_reader.js +++ b/src/core/dataset_reader.js @@ -69,7 +69,7 @@ class DatasetReader { } const first = node.firstChild; - if (first && first.nodeName === "value") { + if (first?.nodeName === "value") { return node.children.map(child => decodeString(child.textContent)); } diff --git a/src/core/decode_stream.js b/src/core/decode_stream.js index a79c31a92..c87267895 100644 --- a/src/core/decode_stream.js +++ b/src/core/decode_stream.js @@ -149,7 +149,7 @@ class StreamsSequenceStream extends DecodeStream { chunk = stream.getBytes(); } catch (reason) { if (this._onError) { - this._onError(reason, stream.dict && stream.dict.objId); + this._onError(reason, stream.dict?.objId); return; } throw reason; diff --git a/src/core/decrypt_stream.js b/src/core/decrypt_stream.js index 47dbd35cf..99dfd4ffa 100644 --- a/src/core/decrypt_stream.js +++ b/src/core/decrypt_stream.js @@ -41,7 +41,7 @@ class DecryptStream extends DecodeStream { return; } this.nextChunk = this.str.getBytes(chunkSize); - const hasMoreData = this.nextChunk && this.nextChunk.length > 0; + const hasMoreData = this.nextChunk?.length > 0; const decrypt = this.decrypt; chunk = decrypt(chunk, !hasMoreData); diff --git a/src/core/document.js b/src/core/document.js index 221488e73..c659e957e 100644 --- a/src/core/document.js +++ b/src/core/document.js @@ -1421,7 +1421,7 @@ class PDFDocument { const { catalog, linearization, xref } = this; if (typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) { assert( - linearization && linearization.pageFirst === pageIndex, + linearization?.pageFirst === pageIndex, "_getLinearizationPage - invalid pageIndex argument." ); } @@ -1466,7 +1466,7 @@ class PDFDocument { let promise; if (xfaFactory) { promise = Promise.resolve([Dict.empty, null]); - } else if (linearization && linearization.pageFirst === pageIndex) { + } else if (linearization?.pageFirst === pageIndex) { promise = this._getLinearizationPage(pageIndex); } else { promise = catalog.getPageDict(pageIndex); @@ -1630,7 +1630,7 @@ class PDFDocument { this._localIdFactory, /* collectFields */ true ) - .then(annotation => annotation && annotation.getFieldObject()) + .then(annotation => annotation?.getFieldObject()) .catch(function (reason) { warn(`_collectFieldObjects: "${reason}".`); return null; diff --git a/src/core/evaluator.js b/src/core/evaluator.js index 031e051a4..43ad83877 100644 --- a/src/core/evaluator.js +++ b/src/core/evaluator.js @@ -172,11 +172,7 @@ function normalizeBlendMode(value, parsingArray = false) { } function incrementCachedImageMaskCount(data) { - if ( - data.fn === OPS.paintImageMaskXObject && - data.args[0] && - data.args[0].count > 0 - ) { + if (data.fn === OPS.paintImageMaskXObject && data.args[0]?.count > 0) { data.args[0].count++; } } @@ -517,7 +513,7 @@ class PartialEvaluator { } } - if (smask && smask.backdrop) { + if (smask?.backdrop) { colorSpace ||= ColorSpace.singletons.rgb; smask.backdrop = colorSpace.getRgb(smask.backdrop, 0); } @@ -623,7 +619,7 @@ class PartialEvaluator { width: w, height: h, imageIsFromDecodeStream: image instanceof DecodeStream, - inverseDecode: !!decode && decode[0] > 0, + inverseDecode: decode?.[0] > 0, interpolate, }); @@ -660,7 +656,7 @@ class PartialEvaluator { width: w, height: h, imageIsFromDecodeStream: image instanceof DecodeStream, - inverseDecode: !!decode && decode[0] > 0, + inverseDecode: decode?.[0] > 0, interpolate, isOffscreenCanvasSupported: this.options.isOffscreenCanvasSupported, }); @@ -991,8 +987,7 @@ class PartialEvaluator { fallbackFontDict = null, cssFontInfo = null ) { - const fontName = - fontArgs && fontArgs[0] instanceof Name ? fontArgs[0].name : null; + const fontName = fontArgs?.[0] instanceof Name ? fontArgs[0].name : null; return this.loadFont( fontName, @@ -1315,7 +1310,7 @@ class PartialEvaluator { this.fontCache.put(font.cacheKey, fontCapability.promise); } assert( - fontID && fontID.startsWith("f"), + fontID?.startsWith("f"), 'The "fontID" must be (correctly) defined.' ); @@ -2576,7 +2571,7 @@ class PartialEvaluator { let posY = currentTransform[5]; // Check if the glyph is in the viewbox. - if (textState.font && textState.font.vertical) { + if (textState.font?.vertical) { if ( posX < viewBox[0] || posX > viewBox[2] || @@ -3662,8 +3657,7 @@ class PartialEvaluator { * {ToUnicodeMap|IdentityToUnicodeMap} object. */ async buildToUnicode(properties) { - properties.hasIncludedToUnicodeMap = - !!properties.toUnicode && properties.toUnicode.length > 0; + properties.hasIncludedToUnicodeMap = properties.toUnicode?.length > 0; // Section 9.10.2 Mapping Character Codes to Unicode Values if (properties.hasIncludedToUnicodeMap) { @@ -4248,8 +4242,8 @@ class PartialEvaluator { } if (!isType3Font) { - const fontNameStr = fontName && fontName.name; - const baseFontStr = baseFont && baseFont.name; + const fontNameStr = fontName?.name; + const baseFontStr = baseFont?.name; if (fontNameStr !== baseFontStr) { info( `The FontDescriptor's FontName is "${fontNameStr}" but ` + @@ -4257,7 +4251,7 @@ class PartialEvaluator { ); // Workaround for cases where e.g. fontNameStr = 'Arial' and // baseFontStr = 'Arial,Bold' (needed when no font file is embedded). - if (fontNameStr && baseFontStr && baseFontStr.startsWith(fontNameStr)) { + if (fontNameStr && baseFontStr?.startsWith(fontNameStr)) { fontName = baseFont; } } @@ -4404,7 +4398,7 @@ class PartialEvaluator { // If the glyph has an accent we need to build a path for its // fontChar too, otherwise CanvasGraphics_paintChar will fail. const accent = glyph.accent; - if (accent && accent.fontChar) { + if (accent?.fontChar) { buildPath(accent.fontChar); } } diff --git a/src/core/font_renderer.js b/src/core/font_renderer.js index ee32c5216..c0e9cc317 100644 --- a/src/core/font_renderer.js +++ b/src/core/font_renderer.js @@ -126,11 +126,8 @@ function parseCff(data, start, end, seacAnalysisEnabled) { const cff = parser.parse(); return { glyphs: cff.charStrings.objects, - subrs: - cff.topDict.privateDict && - cff.topDict.privateDict.subrsIndex && - cff.topDict.privateDict.subrsIndex.objects, - gsubrs: cff.globalSubrIndex && cff.globalSubrIndex.objects, + subrs: cff.topDict.privateDict?.subrsIndex?.objects, + gsubrs: cff.globalSubrIndex?.objects, isCFFCIDFont: cff.isCIDFont, fdSelect: cff.fdSelect, fdArray: cff.fdArray, @@ -452,7 +449,7 @@ function compileCharString(charStringCode, cmds, font, glyphId) { if (fdIndex >= 0 && fdIndex < font.fdArray.length) { const fontDict = font.fdArray[fdIndex]; let subrs; - if (fontDict.privateDict && fontDict.privateDict.subrsIndex) { + if (fontDict.privateDict?.subrsIndex) { subrs = fontDict.privateDict.subrsIndex.objects; } if (subrs) { diff --git a/src/core/fonts.js b/src/core/fonts.js index 5fbacdba3..e6a38da6b 100644 --- a/src/core/fonts.js +++ b/src/core/fonts.js @@ -1424,8 +1424,7 @@ class Font { for (let j = 0, jj = nameTable.length; j < jj; j++) { for (let k = 0, kk = nameTable[j].length; k < kk; k++) { - const nameEntry = - nameTable[j][k] && nameTable[j][k].replaceAll(/\s/g, ""); + const nameEntry = nameTable[j][k]?.replaceAll(/\s/g, ""); if (!nameEntry) { continue; } @@ -1503,9 +1502,8 @@ class Font { // Sometimes there are multiple of the same type of table. Default // to choosing the first table and skip the rest. if ( - potentialTable && - potentialTable.platformId === platformId && - potentialTable.encodingId === encodingId + potentialTable?.platformId === platformId && + potentialTable?.encodingId === encodingId ) { continue; } @@ -2627,11 +2625,7 @@ class Font { const version = font.getInt32(); const numGlyphs = font.getUint16(); - if ( - properties.scaleFactors && - properties.scaleFactors.length === numGlyphs && - isTrueType - ) { + if (properties.scaleFactors?.length === numGlyphs && isTrueType) { const { scaleFactors } = properties; const isGlyphLocationsLong = int16( tables.head.data[50], @@ -2779,7 +2773,7 @@ class Font { this.descent = metricsOverride.descent / metricsOverride.unitsPerEm; this.lineGap = metricsOverride.lineGap / metricsOverride.unitsPerEm; - if (this.cssFontInfo && this.cssFontInfo.lineHeight) { + if (this.cssFontInfo?.lineHeight) { this.lineHeight = this.cssFontInfo.metrics.lineHeight; this.lineGap = this.cssFontInfo.metrics.lineGap; } else { @@ -3114,7 +3108,7 @@ class Font { } const seacs = font.seacs; - if (newMapping && SEAC_ANALYSIS_ENABLED && seacs && seacs.length) { + if (newMapping && SEAC_ANALYSIS_ENABLED && seacs?.length) { const matrix = properties.fontMatrix || FONT_IDENTITY_MATRIX; const charset = font.getCharset(); const seacMap = Object.create(null); @@ -3298,13 +3292,13 @@ class Font { let glyph = this._glyphCache[charcode]; // All `Glyph`-properties, except `isSpace` in multi-byte strings, // depend indirectly on the `charcode`. - if (glyph && glyph.isSpace === isSpace) { + if (glyph?.isSpace === isSpace) { return glyph; } let fontCharCode, width, operatorListId; let widthCode = charcode; - if (this.cMap && this.cMap.contains(charcode)) { + if (this.cMap?.contains(charcode)) { widthCode = this.cMap.lookup(charcode); if (typeof widthCode === "string") { @@ -3315,7 +3309,7 @@ class Font { if (typeof width !== "number") { width = this.defaultWidth; } - const vmetric = this.vmetrics && this.vmetrics[widthCode]; + const vmetric = this.vmetrics?.[widthCode]; let unicode = this.toUnicode.get(charcode) || charcode; if (typeof unicode === "number") { @@ -3346,7 +3340,7 @@ class Font { } let accent = null; - if (this.seacMap && this.seacMap[charcode]) { + if (this.seacMap?.[charcode]) { isInFont = true; const seac = this.seacMap[charcode]; fontCharCode = seac.baseFontCharCode; diff --git a/src/core/function.js b/src/core/function.js index c6564f541..c7d4c7dd8 100644 --- a/src/core/function.js +++ b/src/core/function.js @@ -72,7 +72,7 @@ class PDFFunctionFactory { } else if (cacheKey instanceof Dict) { fnRef = cacheKey.objId; } else if (cacheKey instanceof BaseStream) { - fnRef = cacheKey.dict && cacheKey.dict.objId; + fnRef = cacheKey.dict?.objId; } if (fnRef) { const localFunction = this._localFunctionCache.getByRef(fnRef); @@ -98,7 +98,7 @@ class PDFFunctionFactory { } else if (cacheKey instanceof Dict) { fnRef = cacheKey.objId; } else if (cacheKey instanceof BaseStream) { - fnRef = cacheKey.dict && cacheKey.dict.objId; + fnRef = cacheKey.dict?.objId; } if (fnRef) { this._localFunctionCache.set(/* name = */ null, fnRef, parsedFunction); diff --git a/src/core/image.js b/src/core/image.js index b457a2666..3519cc688 100644 --- a/src/core/image.js +++ b/src/core/image.js @@ -221,7 +221,7 @@ class PDFImage { const max = (1 << bitsPerComponent) - 1; this.decodeCoefficients = []; this.decodeAddends = []; - const isIndexed = this.colorSpace && this.colorSpace.name === "Indexed"; + const isIndexed = this.colorSpace?.name === "Indexed"; for (let i = 0, j = 0; i < this.decode.length; i += 2, ++j) { const dmin = this.decode[i]; const dmax = this.decode[i + 1]; @@ -428,18 +428,14 @@ class PDFImage { } get drawWidth() { - return Math.max( - this.width, - (this.smask && this.smask.width) || 0, - (this.mask && this.mask.width) || 0 - ); + return Math.max(this.width, this.smask?.width || 0, this.mask?.width || 0); } get drawHeight() { return Math.max( this.height, - (this.smask && this.smask.height) || 0, - (this.mask && this.mask.height) || 0 + this.smask?.height || 0, + this.mask?.height || 0 ); } @@ -640,7 +636,7 @@ class PDFImage { 'PDFImage.undoPreblend: Unsupported "buffer" type.' ); } - const matte = this.smask && this.smask.matte; + const matte = this.smask?.matte; if (!matte) { return; } diff --git a/src/core/image_utils.js b/src/core/image_utils.js index c85933e90..021f4373f 100644 --- a/src/core/image_utils.js +++ b/src/core/image_utils.js @@ -26,7 +26,7 @@ class BaseLocalCache { if (this.constructor === BaseLocalCache) { unreachable("Cannot initialize BaseLocalCache."); } - this._onlyRefs = (options && options.onlyRefs) === true; + this._onlyRefs = options?.onlyRefs === true; if (!this._onlyRefs) { this._nameRefMap = new Map(); diff --git a/src/core/jpg.js b/src/core/jpg.js index 777aa145f..71e7b7f9e 100644 --- a/src/core/jpg.js +++ b/src/core/jpg.js @@ -759,7 +759,7 @@ class JpegImage { let endOffset = offset + length - 2; const fileMarker = findNextFileMarker(data, endOffset, offset); - if (fileMarker && fileMarker.invalid) { + if (fileMarker?.invalid) { warn( "readDataBlock - incorrect length, current marker is: " + fileMarker.invalid @@ -1052,7 +1052,7 @@ class JpegImage { /* currentPos = */ offset - 2, /* startPos = */ offset - 3 ); - if (nextFileMarker && nextFileMarker.invalid) { + if (nextFileMarker?.invalid) { warn( "JpegImage.parse - unexpected data, current marker is: " + nextFileMarker.invalid diff --git a/src/core/operator_list.js b/src/core/operator_list.js index df35a0f8e..6791b2401 100644 --- a/src/core/operator_list.js +++ b/src/core/operator_list.js @@ -693,11 +693,7 @@ class OperatorList { case OPS.paintInlineImageXObjectGroup: case OPS.paintImageMaskXObject: const arg = argsArray[i][0]; // First parameter in imgData. - if ( - !arg.cached && - arg.data && - arg.data.buffer instanceof ArrayBuffer - ) { + if (!arg.cached && arg.data?.buffer instanceof ArrayBuffer) { transfers.push(arg.data.buffer); } break; diff --git a/src/core/parser.js b/src/core/parser.js index 94b32d9b2..371eed242 100644 --- a/src/core/parser.js +++ b/src/core/parser.js @@ -1251,7 +1251,7 @@ class Lexer { } } const knownCommands = this.knownCommands; - let knownCommandFound = knownCommands && knownCommands[str] !== undefined; + let knownCommandFound = knownCommands?.[str] !== undefined; while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) { // Stop if a known command is found and next character does not make // the string a command. @@ -1263,7 +1263,7 @@ class Lexer { throw new FormatError(`Command token too long: ${str.length}`); } str = possibleCommand; - knownCommandFound = knownCommands && knownCommands[str] !== undefined; + knownCommandFound = knownCommands?.[str] !== undefined; } if (str === "true") { return true; diff --git a/src/core/primitives.js b/src/core/primitives.js index 76ec4231a..f19976c3a 100644 --- a/src/core/primitives.js +++ b/src/core/primitives.js @@ -297,7 +297,7 @@ class RefSet { ) { unreachable('RefSet: Invalid "parent" value.'); } - this._set = new Set(parent && parent._set); + this._set = new Set(parent?._set); } has(ref) { diff --git a/src/core/struct_tree.js b/src/core/struct_tree.js index 173da5e82..218aeba7d 100644 --- a/src/core/struct_tree.js +++ b/src/core/struct_tree.js @@ -271,7 +271,7 @@ class StructTreePage { let save = false; for (let i = 0; i < obj.length; i++) { const kidRef = obj[i]; - if (kidRef && kidRef.toString() === dict.objId) { + if (kidRef?.toString() === dict.objId) { this.nodes[i] = element; save = true; } diff --git a/src/core/unicode.js b/src/core/unicode.js index f01e0f42c..c631fd3ed 100644 --- a/src/core/unicode.js +++ b/src/core/unicode.js @@ -252,9 +252,9 @@ function getCharUnicodeCategory(char) { } const groups = char.match(SpecialCharRegExp); const category = { - isWhitespace: !!(groups && groups[1]), - isZeroWidthDiacritic: !!(groups && groups[2]), - isInvisibleFormatMark: !!(groups && groups[3]), + isWhitespace: !!groups?.[1], + isZeroWidthDiacritic: !!groups?.[2], + isInvisibleFormatMark: !!groups?.[3], }; CategoryCache.set(char, category); return category; diff --git a/src/core/xfa/template.js b/src/core/xfa/template.js index 367ccd627..924f9fdc2 100644 --- a/src/core/xfa/template.js +++ b/src/core/xfa/template.js @@ -5481,8 +5481,7 @@ class Template extends XFAObject { breakBeforeTarget = breakBefore.beforeTarget; } else if ( root.subform.children.length >= 1 && - root.subform.children[0].break && - root.subform.children[0].break.beforeTarget + root.subform.children[0].break?.beforeTarget ) { breakBefore = root.subform.children[0].break; breakBeforeTarget = breakBefore.beforeTarget; diff --git a/src/core/xml_parser.js b/src/core/xml_parser.js index 31648e23e..a8cae401d 100644 --- a/src/core/xml_parser.js +++ b/src/core/xml_parser.js @@ -302,7 +302,7 @@ class SimpleDOMNode { } get firstChild() { - return this.childNodes && this.childNodes[0]; + return this.childNodes?.[0]; } get nextSibling() { @@ -333,7 +333,7 @@ class SimpleDOMNode { } hasChildNodes() { - return this.childNodes && this.childNodes.length > 0; + return this.childNodes?.length > 0; } /** @@ -383,7 +383,7 @@ class SimpleDOMNode { } } - if (node.childNodes && node.childNodes.length !== 0) { + if (node.childNodes?.length > 0) { stack.push([node, 0]); node = node.childNodes[0]; } else if (stack.length === 0) { diff --git a/src/core/xref.js b/src/core/xref.js index 0606f814a..1194725b8 100644 --- a/src/core/xref.js +++ b/src/core/xref.js @@ -98,7 +98,7 @@ class XRef { } if (encrypt instanceof Dict) { const ids = trailerDict.get("ID"); - const fileId = ids && ids.length ? ids[0] : ""; + const fileId = ids?.length ? ids[0] : ""; // The 'Encrypt' dictionary itself should not be encrypted, and by // setting `suppressEncryption` we can prevent an infinite loop inside // of `XRef_fetchUncompressed` if the dictionary contains indirect diff --git a/web/app.js b/web/app.js index 15795f723..b92ba9090 100644 --- a/web/app.js +++ b/web/app.js @@ -2299,8 +2299,8 @@ function webViewerPageRendered({ pageNumber, error }) { const thumbnailView = PDFViewerApplication.pdfThumbnailViewer?.getThumbnail( /* index = */ pageNumber - 1 ); - if (pageView && thumbnailView) { - thumbnailView.setImage(pageView); + if (pageView) { + thumbnailView?.setImage(pageView); } }