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:
parent
fb78604383
commit
06494ccdac
60
external/builder/builder.js
vendored
60
external/builder/builder.js
vendored
@ -1,6 +1,6 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var fs = require("fs"),
|
const fs = require("fs"),
|
||||||
path = require("path"),
|
path = require("path"),
|
||||||
vm = require("vm");
|
vm = require("vm");
|
||||||
|
|
||||||
@ -34,17 +34,17 @@ var fs = require("fs"),
|
|||||||
*/
|
*/
|
||||||
function preprocess(inFilename, outFilename, defines) {
|
function preprocess(inFilename, outFilename, defines) {
|
||||||
// TODO make this really read line by line.
|
// TODO make this really read line by line.
|
||||||
var lines = fs.readFileSync(inFilename).toString().split("\n");
|
const lines = fs.readFileSync(inFilename).toString().split("\n");
|
||||||
var totalLines = lines.length;
|
const totalLines = lines.length;
|
||||||
var out = "";
|
let out = "";
|
||||||
var i = 0;
|
let i = 0;
|
||||||
function readLine() {
|
function readLine() {
|
||||||
if (i < totalLines) {
|
if (i < totalLines) {
|
||||||
return lines[i++];
|
return lines[i++];
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
var writeLine =
|
const writeLine =
|
||||||
typeof outFilename === "function"
|
typeof outFilename === "function"
|
||||||
? outFilename
|
? outFilename
|
||||||
: function (line) {
|
: function (line) {
|
||||||
@ -70,10 +70,10 @@ function preprocess(inFilename, outFilename, defines) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
function include(file) {
|
function include(file) {
|
||||||
var realPath = fs.realpathSync(inFilename);
|
const realPath = fs.realpathSync(inFilename);
|
||||||
var dir = path.dirname(realPath);
|
const dir = path.dirname(realPath);
|
||||||
try {
|
try {
|
||||||
var fullpath;
|
let fullpath;
|
||||||
if (file.indexOf("$ROOT/") === 0) {
|
if (file.indexOf("$ROOT/") === 0) {
|
||||||
fullpath = path.join(
|
fullpath = path.join(
|
||||||
__dirname,
|
__dirname,
|
||||||
@ -103,28 +103,28 @@ function preprocess(inFilename, outFilename, defines) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// not inside if or else (process lines)
|
// not inside if or else (process lines)
|
||||||
var STATE_NONE = 0;
|
const STATE_NONE = 0;
|
||||||
// inside if, condition false (ignore until #else or #endif)
|
// 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)
|
// 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)
|
// 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
|
// inside else or elif, #if/#elif was true, so following #else or #elif is
|
||||||
// false (ignore lines until #endif)
|
// false (ignore lines until #endif)
|
||||||
var STATE_ELSE_FALSE = 4;
|
const STATE_ELSE_FALSE = 4;
|
||||||
|
|
||||||
var line;
|
let line;
|
||||||
var state = STATE_NONE;
|
let state = STATE_NONE;
|
||||||
var stack = [];
|
const stack = [];
|
||||||
var control = /^(?:\/\/|<!--)\s*#(if|elif|else|endif|expand|include|error)\b(?:\s+(.*?)(?:-->)?$)?/;
|
const control = /^(?:\/\/|<!--)\s*#(if|elif|else|endif|expand|include|error)\b(?:\s+(.*?)(?:-->)?$)?/;
|
||||||
var lineNumber = 0;
|
let lineNumber = 0;
|
||||||
var loc = function () {
|
var loc = function () {
|
||||||
return fs.realpathSync(inFilename) + ":" + lineNumber;
|
return fs.realpathSync(inFilename) + ":" + lineNumber;
|
||||||
};
|
};
|
||||||
while ((line = readLine()) !== null) {
|
while ((line = readLine()) !== null) {
|
||||||
++lineNumber;
|
++lineNumber;
|
||||||
var m = control.exec(line);
|
const m = control.exec(line);
|
||||||
if (m) {
|
if (m) {
|
||||||
switch (m[1]) {
|
switch (m[1]) {
|
||||||
case "if":
|
case "if":
|
||||||
@ -205,27 +205,27 @@ function preprocessCSS(mode, source, destination) {
|
|||||||
return content.replace(
|
return content.replace(
|
||||||
/^\s*@import\s+url\(([^)]+)\);\s*$/gm,
|
/^\s*@import\s+url\(([^)]+)\);\s*$/gm,
|
||||||
function (all, url) {
|
function (all, url) {
|
||||||
var file = path.join(path.dirname(baseUrl), url);
|
const file = path.join(path.dirname(baseUrl), url);
|
||||||
var imported = fs.readFileSync(file, "utf8").toString();
|
const imported = fs.readFileSync(file, "utf8").toString();
|
||||||
return expandImports(imported, file);
|
return expandImports(imported, file);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function removePrefixed(content, hasPrefixedFilter) {
|
function removePrefixed(content, hasPrefixedFilter) {
|
||||||
var lines = content.split(/\r?\n/g);
|
const lines = content.split(/\r?\n/g);
|
||||||
var i = 0;
|
let i = 0;
|
||||||
while (i < lines.length) {
|
while (i < lines.length) {
|
||||||
var line = lines[i];
|
const line = lines[i];
|
||||||
if (!hasPrefixedFilter(line)) {
|
if (!hasPrefixedFilter(line)) {
|
||||||
i++;
|
i++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (/\{\s*$/.test(line)) {
|
if (/\{\s*$/.test(line)) {
|
||||||
var bracketLevel = 1;
|
let bracketLevel = 1;
|
||||||
var j = i + 1;
|
let j = i + 1;
|
||||||
while (j < lines.length && bracketLevel > 0) {
|
while (j < lines.length && bracketLevel > 0) {
|
||||||
var checkBracket = /([{}])\s*$/.exec(lines[j]);
|
const checkBracket = /([{}])\s*$/.exec(lines[j]);
|
||||||
if (checkBracket) {
|
if (checkBracket) {
|
||||||
if (checkBracket[1] === "{") {
|
if (checkBracket[1] === "{") {
|
||||||
bracketLevel++;
|
bracketLevel++;
|
||||||
@ -263,7 +263,7 @@ function preprocessCSS(mode, source, destination) {
|
|||||||
throw new Error("Invalid CSS preprocessor mode");
|
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);
|
content = expandImports(content, source);
|
||||||
if (mode === "mozcentral") {
|
if (mode === "mozcentral") {
|
||||||
content = removePrefixed(content, hasPrefixedMozcentral);
|
content = removePrefixed(content, hasPrefixedMozcentral);
|
||||||
@ -277,7 +277,7 @@ exports.preprocessCSS = preprocessCSS;
|
|||||||
* the first.
|
* the first.
|
||||||
*/
|
*/
|
||||||
function merge(defaults, defines) {
|
function merge(defaults, defines) {
|
||||||
var ret = {};
|
const ret = {};
|
||||||
for (var key in defaults) {
|
for (var key in defaults) {
|
||||||
ret[key] = defaults[key];
|
ret[key] = defaults[key];
|
||||||
}
|
}
|
||||||
|
44
external/builder/preprocessor2.js
vendored
44
external/builder/preprocessor2.js
vendored
@ -1,13 +1,13 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var acorn = require("acorn");
|
const acorn = require("acorn");
|
||||||
var escodegen = require("escodegen");
|
const escodegen = require("escodegen");
|
||||||
var vm = require("vm");
|
const vm = require("vm");
|
||||||
var fs = require("fs");
|
const fs = require("fs");
|
||||||
var path = require("path");
|
const path = require("path");
|
||||||
|
|
||||||
var PDFJS_PREPROCESSOR_NAME = "PDFJSDev";
|
const PDFJS_PREPROCESSOR_NAME = "PDFJSDev";
|
||||||
var ROOT_PREFIX = "$ROOT/";
|
const ROOT_PREFIX = "$ROOT/";
|
||||||
const ACORN_ECMA_VERSION = 2021;
|
const ACORN_ECMA_VERSION = 2021;
|
||||||
|
|
||||||
function isLiteral(obj, value) {
|
function isLiteral(obj, value) {
|
||||||
@ -27,7 +27,7 @@ function evalWithDefines(code, defines, loc) {
|
|||||||
|
|
||||||
function handlePreprocessorAction(ctx, actionName, args, loc) {
|
function handlePreprocessorAction(ctx, actionName, args, loc) {
|
||||||
try {
|
try {
|
||||||
var arg;
|
let arg;
|
||||||
switch (actionName) {
|
switch (actionName) {
|
||||||
case "test":
|
case "test":
|
||||||
arg = args[0];
|
arg = args[0];
|
||||||
@ -103,7 +103,7 @@ function postprocessNode(ctx, node) {
|
|||||||
ctx.map &&
|
ctx.map &&
|
||||||
ctx.map[node.source.value]
|
ctx.map[node.source.value]
|
||||||
) {
|
) {
|
||||||
var newValue = ctx.map[node.source.value];
|
const newValue = ctx.map[node.source.value];
|
||||||
node.source.value = node.source.raw = newValue;
|
node.source.value = node.source.raw = newValue;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -193,7 +193,7 @@ function postprocessNode(ctx, node) {
|
|||||||
node.callee.property.type === "Identifier"
|
node.callee.property.type === "Identifier"
|
||||||
) {
|
) {
|
||||||
// PDFJSDev.xxxx(arg1, arg2, ...) => transform
|
// PDFJSDev.xxxx(arg1, arg2, ...) => transform
|
||||||
var action = node.callee.property.name;
|
const action = node.callee.property.name;
|
||||||
return handlePreprocessorAction(ctx, action, node.arguments, node.loc);
|
return handlePreprocessorAction(ctx, action, node.arguments, node.loc);
|
||||||
}
|
}
|
||||||
// require('string')
|
// require('string')
|
||||||
@ -205,7 +205,7 @@ function postprocessNode(ctx, node) {
|
|||||||
ctx.map &&
|
ctx.map &&
|
||||||
ctx.map[node.arguments[0].value]
|
ctx.map[node.arguments[0].value]
|
||||||
) {
|
) {
|
||||||
var requireName = node.arguments[0];
|
const requireName = node.arguments[0];
|
||||||
requireName.value = requireName.raw = ctx.map[requireName.value];
|
requireName.value = requireName.raw = ctx.map[requireName.value];
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -262,14 +262,14 @@ function fixComments(ctx, node) {
|
|||||||
delete node.trailingComments;
|
delete node.trailingComments;
|
||||||
// Removes ESLint and other service comments.
|
// Removes ESLint and other service comments.
|
||||||
if (node.leadingComments) {
|
if (node.leadingComments) {
|
||||||
var CopyrightRegExp = /\bcopyright\b/i;
|
const CopyrightRegExp = /\bcopyright\b/i;
|
||||||
var BlockCommentRegExp = /^\s*(globals|eslint|falls through)\b/;
|
const BlockCommentRegExp = /^\s*(globals|eslint|falls through)\b/;
|
||||||
var LineCommentRegExp = /^\s*eslint\b/;
|
const LineCommentRegExp = /^\s*eslint\b/;
|
||||||
|
|
||||||
var i = 0;
|
let i = 0;
|
||||||
while (i < node.leadingComments.length) {
|
while (i < node.leadingComments.length) {
|
||||||
var type = node.leadingComments[i].type;
|
const type = node.leadingComments[i].type;
|
||||||
var value = node.leadingComments[i].value;
|
const value = node.leadingComments[i].value;
|
||||||
|
|
||||||
if (ctx.saveComments === "copyright") {
|
if (ctx.saveComments === "copyright") {
|
||||||
// Remove all comments, except Copyright notices and License headers.
|
// Remove all comments, except Copyright notices and License headers.
|
||||||
@ -291,7 +291,7 @@ function fixComments(ctx, node) {
|
|||||||
|
|
||||||
function traverseTree(ctx, node) {
|
function traverseTree(ctx, node) {
|
||||||
// generic node processing
|
// generic node processing
|
||||||
for (var i in node) {
|
for (const i in node) {
|
||||||
var child = node[i];
|
var child = node[i];
|
||||||
if (typeof child === "object" && child !== null && child.type) {
|
if (typeof child === "object" && child !== null && child.type) {
|
||||||
const result = traverseTree(ctx, child);
|
const result = traverseTree(ctx, child);
|
||||||
@ -321,18 +321,18 @@ function traverseTree(ctx, node) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function preprocessPDFJSCode(ctx, code) {
|
function preprocessPDFJSCode(ctx, code) {
|
||||||
var format = ctx.format || {
|
const format = ctx.format || {
|
||||||
indent: {
|
indent: {
|
||||||
style: " ",
|
style: " ",
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
var parseOptions = {
|
const parseOptions = {
|
||||||
ecmaVersion: ACORN_ECMA_VERSION,
|
ecmaVersion: ACORN_ECMA_VERSION,
|
||||||
locations: true,
|
locations: true,
|
||||||
sourceFile: ctx.sourceFile,
|
sourceFile: ctx.sourceFile,
|
||||||
sourceType: "module",
|
sourceType: "module",
|
||||||
};
|
};
|
||||||
var codegenOptions = {
|
const codegenOptions = {
|
||||||
format,
|
format,
|
||||||
parse(input) {
|
parse(input) {
|
||||||
return acorn.parse(input, { ecmaVersion: ACORN_ECMA_VERSION });
|
return acorn.parse(input, { ecmaVersion: ACORN_ECMA_VERSION });
|
||||||
@ -340,7 +340,7 @@ function preprocessPDFJSCode(ctx, code) {
|
|||||||
sourceMap: ctx.sourceMap,
|
sourceMap: ctx.sourceMap,
|
||||||
sourceMapWithCode: ctx.sourceMap,
|
sourceMapWithCode: ctx.sourceMap,
|
||||||
};
|
};
|
||||||
var syntax = acorn.parse(code, parseOptions);
|
const syntax = acorn.parse(code, parseOptions);
|
||||||
traverseTree(ctx, syntax);
|
traverseTree(ctx, syntax);
|
||||||
return escodegen.generate(syntax, codegenOptions);
|
return escodegen.generate(syntax, codegenOptions);
|
||||||
}
|
}
|
||||||
|
24
external/builder/test-fixtures.js
vendored
24
external/builder/test-fixtures.js
vendored
@ -1,13 +1,13 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var builder = require("./builder");
|
const builder = require("./builder");
|
||||||
var fs = require("fs");
|
const fs = require("fs");
|
||||||
var path = require("path");
|
const path = require("path");
|
||||||
|
|
||||||
var errors = 0;
|
let errors = 0;
|
||||||
|
|
||||||
var baseDir = path.join(__dirname, "fixtures");
|
const baseDir = path.join(__dirname, "fixtures");
|
||||||
var files = fs
|
const files = fs
|
||||||
.readdirSync(baseDir)
|
.readdirSync(baseDir)
|
||||||
.filter(function (name) {
|
.filter(function (name) {
|
||||||
return /-expected\./.test(name);
|
return /-expected\./.test(name);
|
||||||
@ -16,22 +16,22 @@ var files = fs
|
|||||||
return path.join(baseDir, name);
|
return path.join(baseDir, name);
|
||||||
});
|
});
|
||||||
files.forEach(function (expectationFilename) {
|
files.forEach(function (expectationFilename) {
|
||||||
var inFilename = expectationFilename.replace("-expected", "");
|
const inFilename = expectationFilename.replace("-expected", "");
|
||||||
var expectation = fs
|
const expectation = fs
|
||||||
.readFileSync(expectationFilename)
|
.readFileSync(expectationFilename)
|
||||||
.toString()
|
.toString()
|
||||||
.trim()
|
.trim()
|
||||||
.replace(/__filename/g, fs.realpathSync(inFilename));
|
.replace(/__filename/g, fs.realpathSync(inFilename));
|
||||||
var outLines = [];
|
const outLines = [];
|
||||||
|
|
||||||
var outFilename = function (line) {
|
const outFilename = function (line) {
|
||||||
outLines.push(line);
|
outLines.push(line);
|
||||||
};
|
};
|
||||||
var defines = {
|
const defines = {
|
||||||
TRUE: true,
|
TRUE: true,
|
||||||
FALSE: false,
|
FALSE: false,
|
||||||
};
|
};
|
||||||
var out;
|
let out;
|
||||||
try {
|
try {
|
||||||
builder.preprocess(inFilename, outFilename, defines);
|
builder.preprocess(inFilename, outFilename, defines);
|
||||||
out = outLines.join("\n").trim();
|
out = outLines.join("\n").trim();
|
||||||
|
26
external/builder/test-fixtures_esprima.js
vendored
26
external/builder/test-fixtures_esprima.js
vendored
@ -1,13 +1,13 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var p2 = require("./preprocessor2.js");
|
const p2 = require("./preprocessor2.js");
|
||||||
var fs = require("fs");
|
const fs = require("fs");
|
||||||
var path = require("path");
|
const path = require("path");
|
||||||
|
|
||||||
var errors = 0;
|
let errors = 0;
|
||||||
|
|
||||||
var baseDir = path.join(__dirname, "fixtures_esprima");
|
const baseDir = path.join(__dirname, "fixtures_esprima");
|
||||||
var files = fs
|
const files = fs
|
||||||
.readdirSync(baseDir)
|
.readdirSync(baseDir)
|
||||||
.filter(function (name) {
|
.filter(function (name) {
|
||||||
return /-expected\./.test(name);
|
return /-expected\./.test(name);
|
||||||
@ -16,29 +16,29 @@ var files = fs
|
|||||||
return path.join(baseDir, name);
|
return path.join(baseDir, name);
|
||||||
});
|
});
|
||||||
files.forEach(function (expectationFilename) {
|
files.forEach(function (expectationFilename) {
|
||||||
var inFilename = expectationFilename.replace("-expected", "");
|
const inFilename = expectationFilename.replace("-expected", "");
|
||||||
var expectation = fs
|
const expectation = fs
|
||||||
.readFileSync(expectationFilename)
|
.readFileSync(expectationFilename)
|
||||||
.toString()
|
.toString()
|
||||||
.trim()
|
.trim()
|
||||||
.replace(/__filename/g, fs.realpathSync(inFilename));
|
.replace(/__filename/g, fs.realpathSync(inFilename));
|
||||||
var input = fs.readFileSync(inFilename).toString();
|
const input = fs.readFileSync(inFilename).toString();
|
||||||
|
|
||||||
var defines = {
|
const defines = {
|
||||||
TRUE: true,
|
TRUE: true,
|
||||||
FALSE: false,
|
FALSE: false,
|
||||||
OBJ: { obj: { i: 1 }, j: 2 },
|
OBJ: { obj: { i: 1 }, j: 2 },
|
||||||
TEXT: "text",
|
TEXT: "text",
|
||||||
};
|
};
|
||||||
var map = {
|
const map = {
|
||||||
"import-alias": "import-name",
|
"import-alias": "import-name",
|
||||||
};
|
};
|
||||||
var ctx = {
|
const ctx = {
|
||||||
defines,
|
defines,
|
||||||
map,
|
map,
|
||||||
rootPath: __dirname + "/../..",
|
rootPath: __dirname + "/../..",
|
||||||
};
|
};
|
||||||
var out;
|
let out;
|
||||||
try {
|
try {
|
||||||
out = p2.preprocessPDFJSCode(ctx, input);
|
out = p2.preprocessPDFJSCode(ctx, input);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
Loading…
Reference in New Issue
Block a user