Remove variable shadowing from the JavaScript files in the web/ folder

*This is part of a series of patches that will try to split PR 11566 into smaller chunks, to make reviewing more feasible.*

Once all the code has been fixed, we'll be able to eventually enable the ESLint `no-shadow` rule; see https://eslint.org/docs/rules/no-shadow
This commit is contained in:
Jonas Jenwald 2020-03-13 12:55:00 +01:00
parent a23ce6b483
commit 886b256ada
6 changed files with 25 additions and 30 deletions

View File

@ -1741,7 +1741,7 @@ if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
"http://mozilla.github.io", "http://mozilla.github.io",
"https://mozilla.github.io", "https://mozilla.github.io",
]; ];
validateFileURL = function validateFileURL(file) { validateFileURL = function(file) {
if (file === undefined) { if (file === undefined) {
return; return;
} }
@ -1917,7 +1917,7 @@ function webViewerInitialized() {
let webViewerOpenFileViaURL; let webViewerOpenFileViaURL;
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) { if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
webViewerOpenFileViaURL = function webViewerOpenFileViaURL(file) { webViewerOpenFileViaURL = function(file) {
if (file && file.lastIndexOf("file:", 0) === 0) { if (file && file.lastIndexOf("file:", 0) === 0) {
// file:-scheme. Load the contents in the main thread because QtWebKit // file:-scheme. Load the contents in the main thread because QtWebKit
// cannot load file:-URLs in a Web Worker. file:-URLs are usually loaded // cannot load file:-URLs in a Web Worker. file:-URLs are usually loaded
@ -1938,12 +1938,12 @@ if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
} }
}; };
} else if (PDFJSDev.test("MOZCENTRAL || CHROME")) { } else if (PDFJSDev.test("MOZCENTRAL || CHROME")) {
webViewerOpenFileViaURL = function webViewerOpenFileViaURL(file) { webViewerOpenFileViaURL = function(file) {
PDFViewerApplication.setTitleUsingUrl(file); PDFViewerApplication.setTitleUsingUrl(file);
PDFViewerApplication.initPassiveLoading(); PDFViewerApplication.initPassiveLoading();
}; };
} else { } else {
webViewerOpenFileViaURL = function webViewerOpenFileViaURL(file) { webViewerOpenFileViaURL = function(file) {
if (file) { if (file) {
throw new Error("Not implemented: webViewerOpenFileViaURL"); throw new Error("Not implemented: webViewerOpenFileViaURL");
} }
@ -2149,7 +2149,7 @@ function webViewerHashchange(evt) {
let webViewerFileInputChange; let webViewerFileInputChange;
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) { if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
webViewerFileInputChange = function webViewerFileInputChange(evt) { webViewerFileInputChange = function(evt) {
if ( if (
PDFViewerApplication.pdfViewer && PDFViewerApplication.pdfViewer &&
PDFViewerApplication.pdfViewer.isInPresentationMode PDFViewerApplication.pdfViewer.isInPresentationMode
@ -2168,8 +2168,8 @@ if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
PDFViewerApplication.setTitleUsingUrl(file.name); PDFViewerApplication.setTitleUsingUrl(file.name);
// Read the local file into a Uint8Array. // Read the local file into a Uint8Array.
const fileReader = new FileReader(); const fileReader = new FileReader();
fileReader.onload = function webViewerChangeFileReaderOnload(evt) { fileReader.onload = function webViewerChangeFileReaderOnload(event) {
const buffer = evt.target.result; const buffer = event.target.result;
PDFViewerApplication.open(new Uint8Array(buffer)); PDFViewerApplication.open(new Uint8Array(buffer));
}; };
fileReader.readAsArrayBuffer(file); fileReader.readAsArrayBuffer(file);

View File

@ -109,7 +109,7 @@ var FontInspector = (function FontInspectorClosure() {
return moreInfo; return moreInfo;
} }
var moreInfo = properties(fontObj, ["name", "type"]); var moreInfo = properties(fontObj, ["name", "type"]);
var fontName = fontObj.loadedName; const fontName = fontObj.loadedName;
var font = document.createElement("div"); var font = document.createElement("div");
var name = document.createElement("span"); var name = document.createElement("span");
name.textContent = fontName; name.textContent = fontName;
@ -130,17 +130,12 @@ var FontInspector = (function FontInspectorClosure() {
event.preventDefault(); event.preventDefault();
console.log(fontObj); console.log(fontObj);
}); });
var select = document.createElement("input"); const select = document.createElement("input");
select.setAttribute("type", "checkbox"); select.setAttribute("type", "checkbox");
select.dataset.fontName = fontName; select.dataset.fontName = fontName;
select.addEventListener( select.addEventListener("click", function() {
"click", selectFont(fontName, select.checked);
(function(select, fontName) { });
return function() {
selectFont(fontName, select.checked);
};
})(select, fontName)
);
font.appendChild(select); font.appendChild(select);
font.appendChild(name); font.appendChild(name);
font.appendChild(document.createTextNode(" ")); font.appendChild(document.createTextNode(" "));
@ -476,7 +471,7 @@ var Stats = (function Stats() {
} }
var statsIndex = getStatIndex(pageNumber); var statsIndex = getStatIndex(pageNumber);
if (statsIndex !== false) { if (statsIndex !== false) {
var b = stats[statsIndex]; const b = stats[statsIndex];
this.panel.removeChild(b.div); this.panel.removeChild(b.div);
stats.splice(statsIndex, 1); stats.splice(statsIndex, 1);
} }

View File

@ -338,12 +338,12 @@ class PDFDocumentProperties {
}; };
let pageName = null; let pageName = null;
let name = let rawName =
getPageName(sizeInches, isPortrait, US_PAGE_NAMES) || getPageName(sizeInches, isPortrait, US_PAGE_NAMES) ||
getPageName(sizeMillimeters, isPortrait, METRIC_PAGE_NAMES); getPageName(sizeMillimeters, isPortrait, METRIC_PAGE_NAMES);
if ( if (
!name && !rawName &&
!( !(
Number.isInteger(sizeMillimeters.width) && Number.isInteger(sizeMillimeters.width) &&
Number.isInteger(sizeMillimeters.height) Number.isInteger(sizeMillimeters.height)
@ -366,8 +366,8 @@ class PDFDocumentProperties {
Math.abs(exactMillimeters.width - intMillimeters.width) < 0.1 && Math.abs(exactMillimeters.width - intMillimeters.width) < 0.1 &&
Math.abs(exactMillimeters.height - intMillimeters.height) < 0.1 Math.abs(exactMillimeters.height - intMillimeters.height) < 0.1
) { ) {
name = getPageName(intMillimeters, isPortrait, METRIC_PAGE_NAMES); rawName = getPageName(intMillimeters, isPortrait, METRIC_PAGE_NAMES);
if (name) { if (rawName) {
// Update *both* sizes, computed above, to ensure that the displayed // Update *both* sizes, computed above, to ensure that the displayed
// dimensions always correspond to the detected page name. // dimensions always correspond to the detected page name.
sizeInches = { sizeInches = {
@ -378,11 +378,11 @@ class PDFDocumentProperties {
} }
} }
} }
if (name) { if (rawName) {
pageName = this.l10n.get( pageName = this.l10n.get(
"document_properties_page_size_name_" + name.toLowerCase(), "document_properties_page_size_name_" + rawName.toLowerCase(),
null, null,
name rawName
); );
} }

View File

@ -277,7 +277,7 @@ class PDFFindController {
* the `matches` and keeps elements with a longer match length. * the `matches` and keeps elements with a longer match length.
*/ */
_prepareMatches(matchesWithLength, matches, matchesLength) { _prepareMatches(matchesWithLength, matches, matchesLength) {
function isSubTerm(matchesWithLength, currentIndex) { function isSubTerm(currentIndex) {
const currentElem = matchesWithLength[currentIndex]; const currentElem = matchesWithLength[currentIndex];
const nextElem = matchesWithLength[currentIndex + 1]; const nextElem = matchesWithLength[currentIndex + 1];
@ -318,7 +318,7 @@ class PDFFindController {
: a.match - b.match; : a.match - b.match;
}); });
for (let i = 0, len = matchesWithLength.length; i < len; i++) { for (let i = 0, len = matchesWithLength.length; i < len; i++) {
if (isSubTerm(matchesWithLength, i)) { if (isSubTerm(i)) {
continue; continue;
} }
matches.push(matchesWithLength[i].match); matches.push(matchesWithLength[i].match);

View File

@ -218,7 +218,7 @@ PDFPrintService.prototype = {
}; };
const print = window.print; const print = window.print;
window.print = function print() { window.print = function() {
if (activeService) { if (activeService) {
console.warn("Ignored window.print() because of a pending print job."); console.warn("Ignored window.print() because of a pending print job.");
return; return;

View File

@ -367,8 +367,8 @@ class PDFSidebar {
return; return;
} }
const removeNotification = view => { const removeNotification = sidebarView => {
switch (view) { switch (sidebarView) {
case SidebarView.OUTLINE: case SidebarView.OUTLINE:
this.outlineButton.classList.remove(UI_NOTIFICATION_CLASS); this.outlineButton.classList.remove(UI_NOTIFICATION_CLASS);
break; break;