Fix remaining linting errors, from enabling the prefer-const
ESLint rule globally
This covers cases that the `--fix` command couldn't deal with, and in a few cases (notably `src/core/jbig2.js`) the code was changed to use block-scoped variables instead.
This commit is contained in:
parent
9e262ae7fa
commit
83bdb525a4
@ -240,8 +240,8 @@ class CMap {
|
||||
}
|
||||
|
||||
mapBfRangeToArray(low, high, array) {
|
||||
let i = 0,
|
||||
ii = array.length;
|
||||
const ii = array.length;
|
||||
let i = 0;
|
||||
while (low <= high && i < ii) {
|
||||
this._map[low] = array[i++];
|
||||
++low;
|
||||
|
@ -110,8 +110,8 @@ function toRomanNumerals(number, lowerCase = false) {
|
||||
Number.isInteger(number) && number > 0,
|
||||
"The number should be a positive integer."
|
||||
);
|
||||
let pos,
|
||||
romanBuf = [];
|
||||
const romanBuf = [];
|
||||
let pos;
|
||||
// Thousands
|
||||
while (number >= 1000) {
|
||||
number -= 1000;
|
||||
|
@ -996,8 +996,8 @@ class AESBaseCipher {
|
||||
const sourceLength = data.length;
|
||||
let buffer = this.buffer,
|
||||
bufferLength = this.bufferPosition;
|
||||
let result = [],
|
||||
iv = this.iv;
|
||||
const result = [];
|
||||
let iv = this.iv;
|
||||
|
||||
for (let i = 0; i < sourceLength; ++i) {
|
||||
buffer[bufferLength] = data[i];
|
||||
@ -1050,8 +1050,8 @@ class AESBaseCipher {
|
||||
|
||||
decryptBlock(data, finalize, iv = null) {
|
||||
const sourceLength = data.length;
|
||||
let buffer = this.buffer,
|
||||
bufferLength = this.bufferPosition;
|
||||
const buffer = this.buffer;
|
||||
let bufferLength = this.bufferPosition;
|
||||
// If an IV is not supplied, wait for IV values. They are at the start
|
||||
// of the stream.
|
||||
if (iv) {
|
||||
|
@ -2284,8 +2284,8 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
||||
baseDict,
|
||||
properties
|
||||
) {
|
||||
let xref = this.xref,
|
||||
cidToGidBytes;
|
||||
const xref = this.xref;
|
||||
let cidToGidBytes;
|
||||
// 9.10.2
|
||||
var toUnicode = dict.get("ToUnicode") || baseDict.get("ToUnicode");
|
||||
var toUnicodePromise = toUnicode
|
||||
@ -2413,15 +2413,13 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
||||
_buildSimpleFontToUnicode(properties, forceGlyphs = false) {
|
||||
assert(!properties.composite, "Must be a simple font.");
|
||||
|
||||
let toUnicode = [],
|
||||
charcode,
|
||||
glyphName;
|
||||
const toUnicode = [];
|
||||
const encoding = properties.defaultEncoding.slice();
|
||||
const baseEncodingName = properties.baseEncodingName;
|
||||
// Merge in the differences array.
|
||||
const differences = properties.differences;
|
||||
for (charcode in differences) {
|
||||
glyphName = differences[charcode];
|
||||
for (const charcode in differences) {
|
||||
const glyphName = differences[charcode];
|
||||
if (glyphName === ".notdef") {
|
||||
// Skip .notdef to prevent rendering errors, e.g. boxes appearing
|
||||
// where there should be spaces (fixes issue5256.pdf).
|
||||
@ -2430,9 +2428,9 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
||||
encoding[charcode] = glyphName;
|
||||
}
|
||||
const glyphsUnicodeMap = getGlyphsUnicode();
|
||||
for (charcode in encoding) {
|
||||
for (const charcode in encoding) {
|
||||
// a) Map the character code to a character name.
|
||||
glyphName = encoding[charcode];
|
||||
let glyphName = encoding[charcode];
|
||||
// b) Look up the character name in the Adobe Glyph List (see the
|
||||
// Bibliography) to obtain the corresponding Unicode value.
|
||||
if (glyphName === "") {
|
||||
|
@ -427,8 +427,8 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
|
||||
if (font.isCFFCIDFont) {
|
||||
const fdIndex = font.fdSelect.getFDIndex(glyphId);
|
||||
if (fdIndex >= 0 && fdIndex < font.fdArray.length) {
|
||||
let fontDict = font.fdArray[fdIndex],
|
||||
subrs;
|
||||
const fontDict = font.fdArray[fdIndex];
|
||||
let subrs;
|
||||
if (fontDict.privateDict && fontDict.privateDict.subrsIndex) {
|
||||
subrs = fontDict.privateDict.subrsIndex.objects;
|
||||
}
|
||||
|
@ -987,21 +987,15 @@ var Jbig2Image = (function Jbig2ImageClosure() {
|
||||
decodingContext
|
||||
);
|
||||
// Divide collective bitmap into patterns.
|
||||
let patterns = [],
|
||||
i = 0,
|
||||
patternBitmap,
|
||||
xMin,
|
||||
xMax,
|
||||
y;
|
||||
while (i <= maxPatternIndex) {
|
||||
patternBitmap = [];
|
||||
xMin = patternWidth * i;
|
||||
xMax = xMin + patternWidth;
|
||||
for (y = 0; y < patternHeight; y++) {
|
||||
const patterns = [];
|
||||
for (let i = 0; i <= maxPatternIndex; i++) {
|
||||
const patternBitmap = [];
|
||||
const xMin = patternWidth * i;
|
||||
const xMax = xMin + patternWidth;
|
||||
for (let y = 0; y < patternHeight; y++) {
|
||||
patternBitmap.push(collectiveBitmap[y].subarray(xMin, xMax));
|
||||
}
|
||||
patterns.push(patternBitmap);
|
||||
i++;
|
||||
}
|
||||
return patterns;
|
||||
}
|
||||
@ -1075,9 +1069,8 @@ var Jbig2Image = (function Jbig2ImageClosure() {
|
||||
}
|
||||
}
|
||||
// Annex C. Gray-scale Image Decoding Procedure.
|
||||
let grayScaleBitPlanes = [],
|
||||
mmrInput,
|
||||
bitmap;
|
||||
const grayScaleBitPlanes = [];
|
||||
let mmrInput, bitmap;
|
||||
if (mmr) {
|
||||
// MMR bit planes are in one continuous stream. Only EOFB codes indicate
|
||||
// the end of each bitmap, so EOFBs must be decoded.
|
||||
@ -1523,8 +1516,8 @@ var Jbig2Image = (function Jbig2ImageClosure() {
|
||||
}
|
||||
|
||||
function parseJbig2(data) {
|
||||
let position = 0,
|
||||
end = data.length;
|
||||
const end = data.length;
|
||||
let position = 0;
|
||||
|
||||
if (
|
||||
data[position] !== 0x97 ||
|
||||
@ -1899,11 +1892,8 @@ var Jbig2Image = (function Jbig2ImageClosure() {
|
||||
}
|
||||
// Create Huffman tree.
|
||||
this.rootNode = new HuffmanTreeNode(null);
|
||||
let i,
|
||||
ii = lines.length,
|
||||
line;
|
||||
for (i = 0; i < ii; i++) {
|
||||
line = lines[i];
|
||||
for (let i = 0, ii = lines.length; i < ii; i++) {
|
||||
const line = lines[i];
|
||||
if (line.prefixLength > 0) {
|
||||
this.rootNode.buildTree(line, line.prefixLength - 1);
|
||||
}
|
||||
@ -1916,15 +1906,14 @@ var Jbig2Image = (function Jbig2ImageClosure() {
|
||||
},
|
||||
assignPrefixCodes(lines) {
|
||||
// Annex B.3 Assigning the prefix codes.
|
||||
let linesLength = lines.length,
|
||||
prefixLengthMax = 0,
|
||||
i;
|
||||
for (i = 0; i < linesLength; i++) {
|
||||
const linesLength = lines.length;
|
||||
let prefixLengthMax = 0;
|
||||
for (let i = 0; i < linesLength; i++) {
|
||||
prefixLengthMax = Math.max(prefixLengthMax, lines[i].prefixLength);
|
||||
}
|
||||
|
||||
const histogram = new Uint32Array(prefixLengthMax + 1);
|
||||
for (i = 0; i < linesLength; i++) {
|
||||
for (let i = 0; i < linesLength; i++) {
|
||||
histogram[lines[i].prefixLength]++;
|
||||
}
|
||||
let currentLength = 1,
|
||||
@ -2253,9 +2242,7 @@ var Jbig2Image = (function Jbig2ImageClosure() {
|
||||
throw new Jbig2Error(`standard table B.${number} does not exist`);
|
||||
}
|
||||
|
||||
let length = lines.length,
|
||||
i;
|
||||
for (i = 0; i < length; i++) {
|
||||
for (let i = 0, ii = lines.length; i < ii; i++) {
|
||||
lines[i] = new HuffmanLine(lines[i]);
|
||||
}
|
||||
table = new HuffmanTable(lines, true);
|
||||
@ -2310,12 +2297,9 @@ var Jbig2Image = (function Jbig2ImageClosure() {
|
||||
function getCustomHuffmanTable(index, referredTo, customTables) {
|
||||
// Returns a Tables segment that has been earlier decoded.
|
||||
// See 7.4.2.1.6 (symbol dictionary) or 7.4.3.1.6 (text region).
|
||||
let currentIndex = 0,
|
||||
i,
|
||||
ii = referredTo.length,
|
||||
table;
|
||||
for (i = 0; i < ii; i++) {
|
||||
table = customTables[referredTo[i]];
|
||||
let currentIndex = 0;
|
||||
for (let i = 0, ii = referredTo.length; i < ii; i++) {
|
||||
const table = customTables[referredTo[i]];
|
||||
if (table) {
|
||||
if (index === currentIndex) {
|
||||
return table;
|
||||
@ -2336,11 +2320,9 @@ var Jbig2Image = (function Jbig2ImageClosure() {
|
||||
// 7.4.3.1.7 Symbol ID Huffman table decoding
|
||||
|
||||
// Read code lengths for RUNCODEs 0...34.
|
||||
let codes = [],
|
||||
i,
|
||||
codeLength;
|
||||
for (i = 0; i <= 34; i++) {
|
||||
codeLength = reader.readBits(4);
|
||||
const codes = [];
|
||||
for (let i = 0; i <= 34; i++) {
|
||||
const codeLength = reader.readBits(4);
|
||||
codes.push(new HuffmanLine([i, codeLength, 0, 0]));
|
||||
}
|
||||
// Assign Huffman codes for RUNCODEs.
|
||||
@ -2349,8 +2331,8 @@ var Jbig2Image = (function Jbig2ImageClosure() {
|
||||
// Read a Huffman code using the assignment above.
|
||||
// Interpret the RUNCODE codes and the additional bits (if any).
|
||||
codes.length = 0;
|
||||
for (i = 0; i < numberOfSymbols; ) {
|
||||
codeLength = runCodesTable.decode(reader);
|
||||
for (let i = 0; i < numberOfSymbols; ) {
|
||||
const codeLength = runCodesTable.decode(reader);
|
||||
if (codeLength >= 32) {
|
||||
let repeatedLength, numberOfRepeats, j;
|
||||
switch (codeLength) {
|
||||
@ -2532,14 +2514,11 @@ var Jbig2Image = (function Jbig2ImageClosure() {
|
||||
}
|
||||
|
||||
function readUncompressedBitmap(reader, width, height) {
|
||||
let bitmap = [],
|
||||
x,
|
||||
y,
|
||||
row;
|
||||
for (y = 0; y < height; y++) {
|
||||
row = new Uint8Array(width);
|
||||
const bitmap = [];
|
||||
for (let y = 0; y < height; y++) {
|
||||
const row = new Uint8Array(width);
|
||||
bitmap.push(row);
|
||||
for (x = 0; x < width; x++) {
|
||||
for (let x = 0; x < width; x++) {
|
||||
row[x] = reader.readBit();
|
||||
}
|
||||
reader.byteAlign();
|
||||
@ -2558,19 +2537,15 @@ var Jbig2Image = (function Jbig2ImageClosure() {
|
||||
EndOfBlock: endOfBlock,
|
||||
};
|
||||
const decoder = new CCITTFaxDecoder(input, params);
|
||||
let bitmap = [],
|
||||
x,
|
||||
y,
|
||||
row,
|
||||
currentByte,
|
||||
shift,
|
||||
const bitmap = [];
|
||||
let currentByte,
|
||||
eof = false;
|
||||
|
||||
for (y = 0; y < height; y++) {
|
||||
row = new Uint8Array(width);
|
||||
for (let y = 0; y < height; y++) {
|
||||
const row = new Uint8Array(width);
|
||||
bitmap.push(row);
|
||||
shift = -1;
|
||||
for (x = 0; x < width; x++) {
|
||||
let shift = -1;
|
||||
for (let x = 0; x < width; x++) {
|
||||
if (shift < 0) {
|
||||
currentByte = decoder.readNextChar();
|
||||
if (currentByte === -1) {
|
||||
|
@ -207,8 +207,8 @@ class Parser {
|
||||
CR = 0xd;
|
||||
const n = 10,
|
||||
NUL = 0x0;
|
||||
let startPos = stream.pos,
|
||||
state = 0,
|
||||
const startPos = stream.pos;
|
||||
let state = 0,
|
||||
ch,
|
||||
maybeEIPos;
|
||||
while ((ch = stream.getByte()) !== -1) {
|
||||
@ -282,11 +282,10 @@ class Parser {
|
||||
* @returns {number} The inline stream length.
|
||||
*/
|
||||
findDCTDecodeInlineStreamEnd(stream) {
|
||||
let startPos = stream.pos,
|
||||
foundEOI = false,
|
||||
const startPos = stream.pos;
|
||||
let foundEOI = false,
|
||||
b,
|
||||
markerLength,
|
||||
length;
|
||||
markerLength;
|
||||
while ((b = stream.getByte()) !== -1) {
|
||||
if (b !== 0xff) {
|
||||
// Not a valid marker.
|
||||
@ -367,7 +366,7 @@ class Parser {
|
||||
break;
|
||||
}
|
||||
}
|
||||
length = stream.pos - startPos;
|
||||
const length = stream.pos - startPos;
|
||||
if (b === -1) {
|
||||
warn(
|
||||
"Inline DCTDecode image stream: " +
|
||||
@ -387,9 +386,8 @@ class Parser {
|
||||
findASCII85DecodeInlineStreamEnd(stream) {
|
||||
const TILDE = 0x7e,
|
||||
GT = 0x3e;
|
||||
let startPos = stream.pos,
|
||||
ch,
|
||||
length;
|
||||
const startPos = stream.pos;
|
||||
let ch;
|
||||
while ((ch = stream.getByte()) !== -1) {
|
||||
if (ch === TILDE) {
|
||||
const tildePos = stream.pos;
|
||||
@ -415,7 +413,7 @@ class Parser {
|
||||
}
|
||||
}
|
||||
}
|
||||
length = stream.pos - startPos;
|
||||
const length = stream.pos - startPos;
|
||||
if (ch === -1) {
|
||||
warn(
|
||||
"Inline ASCII85Decode image stream: " +
|
||||
@ -434,15 +432,14 @@ class Parser {
|
||||
*/
|
||||
findASCIIHexDecodeInlineStreamEnd(stream) {
|
||||
const GT = 0x3e;
|
||||
let startPos = stream.pos,
|
||||
ch,
|
||||
length;
|
||||
const startPos = stream.pos;
|
||||
let ch;
|
||||
while ((ch = stream.getByte()) !== -1) {
|
||||
if (ch === GT) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
length = stream.pos - startPos;
|
||||
const length = stream.pos - startPos;
|
||||
if (ch === -1) {
|
||||
warn(
|
||||
"Inline ASCIIHexDecode image stream: " +
|
||||
|
@ -116,13 +116,13 @@ function getFilenameFromContentDispositionHeader(contentDisposition) {
|
||||
return value;
|
||||
}
|
||||
function rfc2231getparam(contentDisposition) {
|
||||
let matches = [],
|
||||
match;
|
||||
const matches = [];
|
||||
let match;
|
||||
// Iterate over all filename*n= and filename*n*= with n being an integer
|
||||
// of at least zero. Any non-zero number must not start with '0'.
|
||||
const iter = toParamRegExp("filename\\*((?!0\\d)\\d+)(\\*?)", "ig");
|
||||
while ((match = iter.exec(contentDisposition)) !== null) {
|
||||
let [, n, quot, part] = match;
|
||||
let [, n, quot, part] = match; // eslint-disable-line prefer-const
|
||||
n = parseInt(n, 10);
|
||||
if (n in matches) {
|
||||
// Ignore anything after the invalid second filename*0.
|
||||
@ -139,7 +139,7 @@ function getFilenameFromContentDispositionHeader(contentDisposition) {
|
||||
// Numbers must be consecutive. Truncate when there is a hole.
|
||||
break;
|
||||
}
|
||||
let [quot, part] = matches[n];
|
||||
let [quot, part] = matches[n]; // eslint-disable-line prefer-const
|
||||
part = rfc2616unquote(part);
|
||||
if (quot) {
|
||||
part = unescape(part);
|
||||
|
@ -461,8 +461,8 @@ class StatTimer {
|
||||
|
||||
toString() {
|
||||
// Find the longest name for padding purposes.
|
||||
let outBuf = [],
|
||||
longest = 0;
|
||||
const outBuf = [];
|
||||
let longest = 0;
|
||||
for (const time of this.times) {
|
||||
const name = time.name;
|
||||
if (name.length > longest) {
|
||||
|
@ -67,9 +67,8 @@ class XMLParserBase {
|
||||
}
|
||||
|
||||
_parseContent(s, start) {
|
||||
let pos = start,
|
||||
name,
|
||||
attributes = [];
|
||||
const attributes = [];
|
||||
let pos = start;
|
||||
|
||||
function skipWs() {
|
||||
while (pos < s.length && isWhitespace(s, pos)) {
|
||||
@ -85,7 +84,7 @@ class XMLParserBase {
|
||||
) {
|
||||
++pos;
|
||||
}
|
||||
name = s.substring(start, pos);
|
||||
const name = s.substring(start, pos);
|
||||
skipWs();
|
||||
while (
|
||||
pos < s.length &&
|
||||
@ -130,9 +129,7 @@ class XMLParserBase {
|
||||
}
|
||||
|
||||
_parseProcessingInstruction(s, start) {
|
||||
let pos = start,
|
||||
name,
|
||||
value;
|
||||
let pos = start;
|
||||
|
||||
function skipWs() {
|
||||
while (pos < s.length && isWhitespace(s, pos)) {
|
||||
@ -148,13 +145,13 @@ class XMLParserBase {
|
||||
) {
|
||||
++pos;
|
||||
}
|
||||
name = s.substring(start, pos);
|
||||
const name = s.substring(start, pos);
|
||||
skipWs();
|
||||
const attrStart = pos;
|
||||
while (pos < s.length && (s[pos] !== "?" || s[pos + 1] !== ">")) {
|
||||
++pos;
|
||||
}
|
||||
value = s.substring(attrStart, pos);
|
||||
const value = s.substring(attrStart, pos);
|
||||
return {
|
||||
name,
|
||||
value,
|
||||
|
Loading…
x
Reference in New Issue
Block a user