diff --git a/src/core/annotation.js b/src/core/annotation.js index 715ed567d..551f429e4 100644 --- a/src/core/annotation.js +++ b/src/core/annotation.js @@ -839,8 +839,7 @@ class Annotation { setRotation(mk, dict) { this.rotation = 0; - let angle; - angle = mk instanceof Dict ? mk.get("R") || 0 : dict.get("Rotate") || 0; + let angle = mk instanceof Dict ? mk.get("R") || 0 : dict.get("Rotate") || 0; if (Number.isInteger(angle) && angle !== 0) { angle %= 360; if (angle < 0) { diff --git a/src/core/cff_parser.js b/src/core/cff_parser.js index f3f2faaea..446764f0d 100644 --- a/src/core/cff_parser.js +++ b/src/core/cff_parser.js @@ -558,8 +558,7 @@ class CFFParser { stackSize %= 2; validationCommand = CharstringValidationData[value]; } else if (value === 10 || value === 29) { - let subrsIndex; - subrsIndex = value === 10 ? localSubrIndex : globalSubrIndex; + const subrsIndex = value === 10 ? localSubrIndex : globalSubrIndex; if (!subrsIndex) { validationCommand = CharstringValidationData[value]; warn("Missing subrsIndex for " + validationCommand.id); diff --git a/src/core/colorspace.js b/src/core/colorspace.js index 9a0266bde..0da3430ad 100644 --- a/src/core/colorspace.js +++ b/src/core/colorspace.js @@ -1305,9 +1305,7 @@ const CalRGBCS = (function CalRGBCSClosure() { const LabCS = (function LabCSClosure() { // Function g(x) from spec function fn_g(x) { - let result; - result = x >= 6 / 29 ? x ** 3 : (108 / 841) * (x - 4 / 29); - return result; + return x >= 6 / 29 ? x ** 3 : (108 / 841) * (x - 4 / 29); } function decode(value, high1, low2, high2) { diff --git a/src/core/crypto.js b/src/core/crypto.js index 1f14179ac..26c22d80b 100644 --- a/src/core/crypto.js +++ b/src/core/crypto.js @@ -1445,8 +1445,7 @@ const CipherTransformFactory = (function CipherTransformFactoryClosure() { } else { password = []; } - let pdfAlgorithm; - pdfAlgorithm = revision === 6 ? new PDF20() : new PDF17(); + const pdfAlgorithm = revision === 6 ? new PDF20() : new PDF17(); if ( pdfAlgorithm.checkUserPassword(password, userValidationSalt, userPassword) diff --git a/src/core/evaluator.js b/src/core/evaluator.js index 600c0d13c..b380c8960 100644 --- a/src/core/evaluator.js +++ b/src/core/evaluator.js @@ -793,8 +793,7 @@ class PartialEvaluator { ); if (cacheKey && imageRef && cacheGlobally) { - let length = 0; - length = imgData.bitmap + const length = imgData.bitmap ? imgData.width * imgData.height * 4 : imgData.data.length; this.globalImageCache.addByteSize(imageRef, length); diff --git a/src/core/fonts_utils.js b/src/core/fonts_utils.js index f1bbf6762..e5067d8e6 100644 --- a/src/core/fonts_utils.js +++ b/src/core/fonts_utils.js @@ -116,11 +116,7 @@ function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) { baseEncoding = builtInEncoding; for (charCode = 0; charCode < baseEncoding.length; charCode++) { glyphId = glyphNames.indexOf(baseEncoding[charCode]); - if (glyphId >= 0) { - charCodeToGlyphId[charCode] = glyphId; - } else { - charCodeToGlyphId[charCode] = 0; // notdef - } + charCodeToGlyphId[charCode] = glyphId >= 0 ? glyphId : /* notdef = */ 0; } } else if (properties.baseEncodingName) { // If a valid base encoding name was used, the mapping is initialized with @@ -128,11 +124,7 @@ function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) { baseEncoding = getEncoding(properties.baseEncodingName); for (charCode = 0; charCode < baseEncoding.length; charCode++) { glyphId = glyphNames.indexOf(baseEncoding[charCode]); - if (glyphId >= 0) { - charCodeToGlyphId[charCode] = glyphId; - } else { - charCodeToGlyphId[charCode] = 0; // notdef - } + charCodeToGlyphId[charCode] = glyphId >= 0 ? glyphId : /* notdef = */ 0; } } else if (isSymbolicFont) { // For a symbolic font the encoding should be the fonts built-in encoding. @@ -145,11 +137,7 @@ function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) { baseEncoding = StandardEncoding; for (charCode = 0; charCode < baseEncoding.length; charCode++) { glyphId = glyphNames.indexOf(baseEncoding[charCode]); - if (glyphId >= 0) { - charCodeToGlyphId[charCode] = glyphId; - } else { - charCodeToGlyphId[charCode] = 0; // notdef - } + charCodeToGlyphId[charCode] = glyphId >= 0 ? glyphId : /* notdef = */ 0; } } @@ -170,11 +158,7 @@ function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) { glyphId = glyphNames.indexOf(standardGlyphName); } } - if (glyphId >= 0) { - charCodeToGlyphId[charCode] = glyphId; - } else { - charCodeToGlyphId[charCode] = 0; // notdef - } + charCodeToGlyphId[charCode] = glyphId >= 0 ? glyphId : /* notdef = */ 0; } } return charCodeToGlyphId; diff --git a/src/core/jpg.js b/src/core/jpg.js index 9761b67e4..de3673879 100644 --- a/src/core/jpg.js +++ b/src/core/jpg.js @@ -385,8 +385,7 @@ function decodeScan( let mcu = 0, fileMarker; - let mcuExpected; - mcuExpected = + const mcuExpected = componentsLength === 1 ? components[0].blocksPerLine * components[0].blocksPerColumn : mcusPerLine * frame.mcusPerColumn; diff --git a/src/core/xfa/bind.js b/src/core/xfa/bind.js index 462fa89be..4c6752160 100644 --- a/src/core/xfa/bind.js +++ b/src/core/xfa/bind.js @@ -55,9 +55,8 @@ class Binder { constructor(root) { this.root = root; this.datasets = root.datasets; - this.data = root.datasets?.data - ? root.datasets.data - : new XmlObject(NamespaceIds.datasets.id, "data"); + this.data = + root.datasets?.data || new XmlObject(NamespaceIds.datasets.id, "data"); this.emptyMerge = this.data[$getChildren]().length === 0; this.root.form = this.form = root.template[$clone](); diff --git a/src/core/xfa_fonts.js b/src/core/xfa_fonts.js index 5904004d7..7f58a99f7 100644 --- a/src/core/xfa_fonts.js +++ b/src/core/xfa_fonts.js @@ -224,8 +224,7 @@ function getXfaFontWidths(name) { } const { baseWidths, baseMapping, factors } = info; - let rescaledBaseWidths; - rescaledBaseWidths = !factors + const rescaledBaseWidths = !factors ? baseWidths : baseWidths.map((w, i) => w * factors[i]); diff --git a/src/display/canvas.js b/src/display/canvas.js index 39dff0ce9..bae1da84f 100644 --- a/src/display/canvas.js +++ b/src/display/canvas.js @@ -854,8 +854,7 @@ function genericComposeSMask( const g0 = hasBackdrop ? backdrop[1] : 0; const b0 = hasBackdrop ? backdrop[2] : 0; - let composeFn; - composeFn = + const composeFn = subtype === "Luminosity" ? composeSMaskLuminosity : composeSMaskAlpha; // processing image in chunks to save memory @@ -2254,8 +2253,7 @@ class CanvasGraphics { } } - let charWidth; - charWidth = vertical + const charWidth = vertical ? width * widthAdvanceScale - spacing * fontDirection : width * widthAdvanceScale + spacing * fontDirection; x += charWidth; diff --git a/src/display/pattern_helper.js b/src/display/pattern_helper.js index 7a7b5154e..ba3e7f93d 100644 --- a/src/display/pattern_helper.js +++ b/src/display/pattern_helper.js @@ -200,8 +200,7 @@ function drawTriangle(data, context, p1, p2, p3, c1, c2, c3) { let xb, cbr, cbg, cbb; for (let y = minY; y <= maxY; y++) { if (y < y2) { - let k; - k = y < y1 ? 0 : (y1 - y) / (y1 - y2); + const k = y < y1 ? 0 : (y1 - y) / (y1 - y2); xa = x1 - (x1 - x2) * k; car = c1r - (c1r - c2r) * k; cag = c1g - (c1g - c2g) * k; diff --git a/src/display/svg.js b/src/display/svg.js index a20aa88d9..c81084071 100644 --- a/src/display/svg.js +++ b/src/display/svg.js @@ -152,14 +152,9 @@ const convertImgDataToPng = (function () { // Node v0.11.12 zlib.deflateSync is introduced (and returns a Buffer). // Node v3.0.0 Buffer inherits from Uint8Array. // Node v8.0.0 zlib.deflateSync accepts Uint8Array as input. - let input; - // eslint-disable-next-line no-undef - if (parseInt(process.versions.node) >= 8) { - input = literals; - } else { + const input = // eslint-disable-next-line no-undef - input = Buffer.from(literals); - } + parseInt(process.versions.node) >= 8 ? literals : Buffer.from(literals); const output = __non_webpack_require__("zlib").deflateSync(input, { level: 9, }); @@ -857,8 +852,7 @@ class SVGGraphics { // might actually map to a different glyph. } - let charWidth; - charWidth = vertical + const charWidth = vertical ? width * widthAdvanceScale - spacing * fontDirection : width * widthAdvanceScale + spacing * fontDirection; diff --git a/src/display/xfa_layer.js b/src/display/xfa_layer.js index 0ca518483..b5c94327f 100644 --- a/src/display/xfa_layer.js +++ b/src/display/xfa_layer.js @@ -212,8 +212,7 @@ class XfaLayer { continue; } - let childHtml; - childHtml = child?.attributes?.xmlns + const childHtml = child?.attributes?.xmlns ? document.createElementNS(child.attributes.xmlns, name) : document.createElement(name);