diff --git a/src/core/annotation.js b/src/core/annotation.js index 1c6877972..c87f99f4b 100644 --- a/src/core/annotation.js +++ b/src/core/annotation.js @@ -1686,12 +1686,12 @@ class MarkupAnnotation extends Annotation { buffer.push(`${fillColor[0]} ${fillColor[1]} ${fillColor[2]} rg`); } - let pointsArray = this.data.quadPoints; - if (!pointsArray) { - // If there are no quadpoints, the rectangle should be used instead. - // Convert the rectangle definition to a points array similar to how the - // quadpoints are defined. - pointsArray = Float32Array.from([ + // If there are no quadpoints, the rectangle should be used instead. + // Convert the rectangle definition to a points array similar to how the + // quadpoints are defined. + const pointsArray = + this.data.quadPoints || + Float32Array.from([ this.rectangle[0], this.rectangle[3], this.rectangle[2], @@ -1701,7 +1701,6 @@ class MarkupAnnotation extends Annotation { this.rectangle[2], this.rectangle[1], ]); - } for (let i = 0, ii = pointsArray.length; i < ii; i += 8) { const [mX, MX, mY, MY] = pointsCallback( @@ -1755,11 +1754,8 @@ class MarkupAnnotation extends Annotation { } static async createNewAnnotation(xref, annotation, changes, params) { - if (!annotation.ref) { - annotation.ref = xref.getNewTemporaryRef(); - } + const annotationRef = (annotation.ref ||= xref.getNewTemporaryRef()); - const annotationRef = annotation.ref; const ap = await this.createNewAppearanceStream(annotation, xref, params); let annotationDict; diff --git a/src/core/catalog.js b/src/core/catalog.js index 00524c32e..a38be8f9a 100644 --- a/src/core/catalog.js +++ b/src/core/catalog.js @@ -567,10 +567,7 @@ class Catalog { const onParsed = []; if (Array.isArray(refs)) { for (const value of refs) { - if (!(value instanceof Ref)) { - continue; - } - if (groupRefCache.has(value)) { + if (value instanceof Ref && groupRefCache.has(value)) { onParsed.push(value.toString()); } } @@ -629,7 +626,7 @@ class Catalog { return null; } const nestedOrder = parseOrder(value.slice(1), nestedLevels); - if (!nestedOrder || !nestedOrder.length) { + if (!nestedOrder?.length) { return null; } return { name: stringToPDFString(nestedName), order: nestedOrder }; diff --git a/src/core/ccitt.js b/src/core/ccitt.js index ac204bd80..8a57a5dbe 100644 --- a/src/core/ccitt.js +++ b/src/core/ccitt.js @@ -466,7 +466,7 @@ const blackTable3 = [ */ class CCITTFaxDecoder { constructor(source, options = {}) { - if (!source || typeof source.next !== "function") { + if (typeof source?.next !== "function") { throw new Error('CCITTFaxDecoder - invalid "source" parameter.'); } this.source = source; diff --git a/src/core/decrypt_stream.js b/src/core/decrypt_stream.js index 99dfd4ffa..ee2fff21f 100644 --- a/src/core/decrypt_stream.js +++ b/src/core/decrypt_stream.js @@ -36,7 +36,7 @@ class DecryptStream extends DecodeStream { chunk = this.str.getBytes(chunkSize); this.initialized = true; } - if (!chunk || chunk.length === 0) { + if (!chunk?.length) { this.eof = true; return; } diff --git a/src/core/font_renderer.js b/src/core/font_renderer.js index 37342fc30..271f7302c 100644 --- a/src/core/font_renderer.js +++ b/src/core/font_renderer.js @@ -818,7 +818,7 @@ class CompiledFont { } compileGlyph(code, glyphId) { - if (!code || code.length === 0 || code[0] === 14) { + if (!code?.length || code[0] === 14) { return NOOP; } diff --git a/src/core/xref.js b/src/core/xref.js index 75e5d1626..669af0ed8 100644 --- a/src/core/xref.js +++ b/src/core/xref.js @@ -310,18 +310,15 @@ class XRef { if (!("streamState" in this)) { // Stores state of the stream as we process it so we can resume // from middle of stream in case of missing data error - const streamParameters = stream.dict; - const byteWidths = streamParameters.get("W"); - let range = streamParameters.get("Index"); - if (!range) { - range = [0, streamParameters.get("Size")]; - } + const { dict, pos } = stream; + const byteWidths = dict.get("W"); + const range = dict.get("Index") || [0, dict.get("Size")]; this.streamState = { entryRanges: range, byteWidths, entryNum: 0, - streamPos: stream.pos, + streamPos: pos, }; } this.readXRefStream(stream);