1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-25 17:48:07 +02:00

Replace *most* cases of var with let/const in the external/builder/ folder

These changes were done automatically, by using the `gulp lint --fix` command, in preparation for the next patch.
This commit is contained in:
Jonas Jenwald 2021-03-13 17:37:27 +01:00
parent fb78604383
commit 06494ccdac
4 changed files with 77 additions and 77 deletions

View file

@ -1,6 +1,6 @@
"use strict";
var fs = require("fs"),
const fs = require("fs"),
path = require("path"),
vm = require("vm");
@ -34,17 +34,17 @@ var fs = require("fs"),
*/
function preprocess(inFilename, outFilename, defines) {
// TODO make this really read line by line.
var lines = fs.readFileSync(inFilename).toString().split("\n");
var totalLines = lines.length;
var out = "";
var i = 0;
const lines = fs.readFileSync(inFilename).toString().split("\n");
const totalLines = lines.length;
let out = "";
let i = 0;
function readLine() {
if (i < totalLines) {
return lines[i++];
}
return null;
}
var writeLine =
const writeLine =
typeof outFilename === "function"
? outFilename
: function (line) {
@ -70,10 +70,10 @@ function preprocess(inFilename, outFilename, defines) {
}
}
function include(file) {
var realPath = fs.realpathSync(inFilename);
var dir = path.dirname(realPath);
const realPath = fs.realpathSync(inFilename);
const dir = path.dirname(realPath);
try {
var fullpath;
let fullpath;
if (file.indexOf("$ROOT/") === 0) {
fullpath = path.join(
__dirname,
@ -103,28 +103,28 @@ function preprocess(inFilename, outFilename, defines) {
}
// not inside if or else (process lines)
var STATE_NONE = 0;
const STATE_NONE = 0;
// inside if, condition false (ignore until #else or #endif)
var STATE_IF_FALSE = 1;
const STATE_IF_FALSE = 1;
// inside else, #if was false, so #else is true (process lines until #endif)
var STATE_ELSE_TRUE = 2;
const STATE_ELSE_TRUE = 2;
// inside if, condition true (process lines until #else or #endif)
var STATE_IF_TRUE = 3;
const STATE_IF_TRUE = 3;
// inside else or elif, #if/#elif was true, so following #else or #elif is
// false (ignore lines until #endif)
var STATE_ELSE_FALSE = 4;
const STATE_ELSE_FALSE = 4;
var line;
var state = STATE_NONE;
var stack = [];
var control = /^(?:\/\/|<!--)\s*#(if|elif|else|endif|expand|include|error)\b(?:\s+(.*?)(?:-->)?$)?/;
var lineNumber = 0;
let line;
let state = STATE_NONE;
const stack = [];
const control = /^(?:\/\/|<!--)\s*#(if|elif|else|endif|expand|include|error)\b(?:\s+(.*?)(?:-->)?$)?/;
let lineNumber = 0;
var loc = function () {
return fs.realpathSync(inFilename) + ":" + lineNumber;
};
while ((line = readLine()) !== null) {
++lineNumber;
var m = control.exec(line);
const m = control.exec(line);
if (m) {
switch (m[1]) {
case "if":
@ -205,27 +205,27 @@ function preprocessCSS(mode, source, destination) {
return content.replace(
/^\s*@import\s+url\(([^)]+)\);\s*$/gm,
function (all, url) {
var file = path.join(path.dirname(baseUrl), url);
var imported = fs.readFileSync(file, "utf8").toString();
const file = path.join(path.dirname(baseUrl), url);
const imported = fs.readFileSync(file, "utf8").toString();
return expandImports(imported, file);
}
);
}
function removePrefixed(content, hasPrefixedFilter) {
var lines = content.split(/\r?\n/g);
var i = 0;
const lines = content.split(/\r?\n/g);
let i = 0;
while (i < lines.length) {
var line = lines[i];
const line = lines[i];
if (!hasPrefixedFilter(line)) {
i++;
continue;
}
if (/\{\s*$/.test(line)) {
var bracketLevel = 1;
var j = i + 1;
let bracketLevel = 1;
let j = i + 1;
while (j < lines.length && bracketLevel > 0) {
var checkBracket = /([{}])\s*$/.exec(lines[j]);
const checkBracket = /([{}])\s*$/.exec(lines[j]);
if (checkBracket) {
if (checkBracket[1] === "{") {
bracketLevel++;
@ -263,7 +263,7 @@ function preprocessCSS(mode, source, destination) {
throw new Error("Invalid CSS preprocessor mode");
}
var content = fs.readFileSync(source, "utf8").toString();
let content = fs.readFileSync(source, "utf8").toString();
content = expandImports(content, source);
if (mode === "mozcentral") {
content = removePrefixed(content, hasPrefixedMozcentral);
@ -277,7 +277,7 @@ exports.preprocessCSS = preprocessCSS;
* the first.
*/
function merge(defaults, defines) {
var ret = {};
const ret = {};
for (var key in defaults) {
ret[key] = defaults[key];
}