1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-26 10:08:06 +02:00

Enable the ESLint prefer-const rule globally (PR 11450 follow-up)

Please find additional details about the ESLint rule at https://eslint.org/docs/rules/prefer-const

With the recent introduction of Prettier this sort of mass enabling of ESLint rules becomes a lot easier, since the code will be automatically reformatted as necessary to account for e.g. changed line lengths.

Note that this patch is generated automatically, by using the ESLint `--fix` argument, and will thus require some additional clean-up (which is done separately).
This commit is contained in:
Jonas Jenwald 2020-01-24 09:48:21 +01:00
parent d2d9441373
commit 9e262ae7fa
54 changed files with 676 additions and 661 deletions

View file

@ -267,7 +267,7 @@ class Catalog {
dests = Object.create(null);
if (obj instanceof NameTree) {
const names = obj.getAll();
for (let name in names) {
for (const name in names) {
dests[name] = fetchDestination(names[name]);
}
} else if (obj instanceof Dict) {
@ -1527,11 +1527,11 @@ var XRef = (function XRefClosure() {
// we won't skip over a new 'obj' operator in corrupt files where
// 'endobj' operators are missing (fixes issue9105_reduced.pdf).
while (startPos < buffer.length) {
let endPos = startPos + skipUntil(buffer, startPos, objBytes) + 4;
const endPos = startPos + skipUntil(buffer, startPos, objBytes) + 4;
contentLength = endPos - position;
let checkPos = Math.max(endPos - CHECK_CONTENT_LENGTH, startPos);
let tokenStr = bytesToString(buffer.subarray(checkPos, endPos));
const checkPos = Math.max(endPos - CHECK_CONTENT_LENGTH, startPos);
const tokenStr = bytesToString(buffer.subarray(checkPos, endPos));
// Check if the current object ends with an 'endobj' operator.
if (endobjRegExp.test(tokenStr)) {
@ -1539,7 +1539,7 @@ var XRef = (function XRefClosure() {
} else {
// Check if an "obj" occurrence is actually a new object,
// i.e. the current object is missing the 'endobj' operator.
let objToken = nestedObjRegExp.exec(tokenStr);
const objToken = nestedObjRegExp.exec(tokenStr);
if (objToken && objToken[1]) {
warn(
@ -1552,7 +1552,7 @@ var XRef = (function XRefClosure() {
}
startPos = endPos;
}
let content = buffer.subarray(position, position + contentLength);
const content = buffer.subarray(position, position + contentLength);
// checking XRef stream suspect
// (it shall have '/XRef' and next char is not a letter)
@ -1597,7 +1597,7 @@ var XRef = (function XRefClosure() {
continue;
}
// read the trailer dictionary
let dict = parser.getObj();
const dict = parser.getObj();
if (!isDict(dict)) {
continue;
}
@ -1634,7 +1634,7 @@ var XRef = (function XRefClosure() {
// Keep track of already parsed XRef tables, to prevent an infinite loop
// when parsing corrupt PDF files where e.g. the /Prev entries create a
// circular dependency between tables (fixes bug1393476.pdf).
let startXRefParsedCache = Object.create(null);
const startXRefParsedCache = Object.create(null);
try {
while (this.startXRefQueue.length) {
@ -2178,7 +2178,7 @@ var FileSpec = (function FileSpecClosure() {
* that have references to the catalog or other pages since that will cause the
* entire PDF document object graph to be traversed.
*/
let ObjectLoader = (function() {
const ObjectLoader = (function() {
function mayHaveChildren(value) {
return (
value instanceof Ref ||
@ -2190,17 +2190,17 @@ let ObjectLoader = (function() {
function addChildren(node, nodesToVisit) {
if (node instanceof Dict || isStream(node)) {
let dict = node instanceof Dict ? node : node.dict;
let dictKeys = dict.getKeys();
const dict = node instanceof Dict ? node : node.dict;
const dictKeys = dict.getKeys();
for (let i = 0, ii = dictKeys.length; i < ii; i++) {
let rawValue = dict.getRaw(dictKeys[i]);
const rawValue = dict.getRaw(dictKeys[i]);
if (mayHaveChildren(rawValue)) {
nodesToVisit.push(rawValue);
}
}
} else if (Array.isArray(node)) {
for (let i = 0, ii = node.length; i < ii; i++) {
let value = node[i];
const value = node[i];
if (mayHaveChildren(value)) {
nodesToVisit.push(value);
}
@ -2226,12 +2226,12 @@ let ObjectLoader = (function() {
return undefined;
}
let { keys, dict } = this;
const { keys, dict } = this;
this.refSet = new RefSet();
// Setup the initial nodes to visit.
let nodesToVisit = [];
const nodesToVisit = [];
for (let i = 0, ii = keys.length; i < ii; i++) {
let rawValue = dict.getRaw(keys[i]);
const rawValue = dict.getRaw(keys[i]);
// Skip nodes that are guaranteed to be empty.
if (rawValue !== undefined) {
nodesToVisit.push(rawValue);
@ -2241,8 +2241,8 @@ let ObjectLoader = (function() {
},
async _walk(nodesToVisit) {
let nodesToRevisit = [];
let pendingRequests = [];
const nodesToRevisit = [];
const pendingRequests = [];
// DFS walk of the object graph.
while (nodesToVisit.length) {
let currentNode = nodesToVisit.pop();
@ -2265,10 +2265,10 @@ let ObjectLoader = (function() {
}
}
if (currentNode && currentNode.getBaseStreams) {
let baseStreams = currentNode.getBaseStreams();
const baseStreams = currentNode.getBaseStreams();
let foundMissingData = false;
for (let i = 0, ii = baseStreams.length; i < ii; i++) {
let stream = baseStreams[i];
const stream = baseStreams[i];
if (stream.allChunksLoaded && !stream.allChunksLoaded()) {
foundMissingData = true;
pendingRequests.push({ begin: stream.start, end: stream.end });
@ -2286,7 +2286,7 @@ let ObjectLoader = (function() {
await this.xref.stream.manager.requestRanges(pendingRequests);
for (let i = 0, ii = nodesToRevisit.length; i < ii; i++) {
let node = nodesToRevisit[i];
const node = nodesToRevisit[i];
// Remove any reference nodes from the current `RefSet` so they
// aren't skipped when we revist them.
if (node instanceof Ref) {