Merge pull request #13093 from Snuffleupagus/eslint-no-var-builder
Enable the ESLint `no-var` rule in the `external/builder/` folder
This commit is contained in:
		
						commit
						c86f44f423
					
				
							
								
								
									
										10
									
								
								external/builder/.eslintrc
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								external/builder/.eslintrc
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @ -0,0 +1,10 @@ | |||||||
|  | { | ||||||
|  |   "extends": [ | ||||||
|  |     "../.eslintrc" | ||||||
|  |   ], | ||||||
|  | 
 | ||||||
|  |   "rules": { | ||||||
|  |     // ECMAScript 6 | ||||||
|  |     "no-var": "error", | ||||||
|  |   }, | ||||||
|  | } | ||||||
							
								
								
									
										72
									
								
								external/builder/builder.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										72
									
								
								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"); | ||||||
| 
 | 
 | ||||||
| @ -33,18 +33,23 @@ var fs = require("fs"), | |||||||
|  * //#endif
 |  * //#endif
 | ||||||
|  */ |  */ | ||||||
| function preprocess(inFilename, outFilename, defines) { | function preprocess(inFilename, outFilename, defines) { | ||||||
|  |   let lineNumber = 0; | ||||||
|  |   function loc() { | ||||||
|  |     return fs.realpathSync(inFilename) + ":" + lineNumber; | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|   // 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 +75,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 +108,25 @@ 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; | ||||||
|  | 
 | ||||||
|  |   let line; | ||||||
|  |   let state = STATE_NONE; | ||||||
|  |   const stack = []; | ||||||
|  |   const control = /^(?:\/\/|<!--)\s*#(if|elif|else|endif|expand|include|error)\b(?:\s+(.*?)(?:-->)?$)?/; | ||||||
| 
 | 
 | ||||||
|   var line; |  | ||||||
|   var state = STATE_NONE; |  | ||||||
|   var stack = []; |  | ||||||
|   var control = /^(?:\/\/|<!--)\s*#(if|elif|else|endif|expand|include|error)\b(?:\s+(.*?)(?:-->)?$)?/; |  | ||||||
|   var lineNumber = 0; |  | ||||||
|   var loc = function () { |  | ||||||
|     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 +207,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 +265,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,11 +279,11 @@ exports.preprocessCSS = preprocessCSS; | |||||||
|  * the first. |  * the first. | ||||||
|  */ |  */ | ||||||
| function merge(defaults, defines) { | function merge(defaults, defines) { | ||||||
|   var ret = {}; |   const ret = Object.create(null); | ||||||
|   for (var key in defaults) { |   for (const key in defaults) { | ||||||
|     ret[key] = defaults[key]; |     ret[key] = defaults[key]; | ||||||
|   } |   } | ||||||
|   for (key in defines) { |   for (const key in defines) { | ||||||
|     ret[key] = defines[key]; |     ret[key] = defines[key]; | ||||||
|   } |   } | ||||||
|   return ret; |   return ret; | ||||||
|  | |||||||
							
								
								
									
										62
									
								
								external/builder/preprocessor2.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										62
									
								
								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,21 +27,21 @@ 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]; | ||||||
|         if (!arg || arg.type !== "Literal" || typeof arg.value !== "string") { |         if (!arg || arg.type !== "Literal" || typeof arg.value !== "string") { | ||||||
|           throw new Error("No code for testing is given"); |           throw new Error("No code for testing is given"); | ||||||
|         } |         } | ||||||
|         var isTrue = !!evalWithDefines(arg.value, ctx.defines); |         const isTrue = !!evalWithDefines(arg.value, ctx.defines); | ||||||
|         return { type: "Literal", value: isTrue, loc }; |         return { type: "Literal", value: isTrue, loc }; | ||||||
|       case "eval": |       case "eval": | ||||||
|         arg = args[0]; |         arg = args[0]; | ||||||
|         if (!arg || arg.type !== "Literal" || typeof arg.value !== "string") { |         if (!arg || arg.type !== "Literal" || typeof arg.value !== "string") { | ||||||
|           throw new Error("No code for eval is given"); |           throw new Error("No code for eval is given"); | ||||||
|         } |         } | ||||||
|         var result = evalWithDefines(arg.value, ctx.defines); |         const result = evalWithDefines(arg.value, ctx.defines); | ||||||
|         if ( |         if ( | ||||||
|           typeof result === "boolean" || |           typeof result === "boolean" || | ||||||
|           typeof result === "string" || |           typeof result === "string" || | ||||||
| @ -62,14 +62,14 @@ function handlePreprocessorAction(ctx, actionName, args, loc) { | |||||||
|         if (!arg || arg.type !== "Literal" || typeof arg.value !== "string") { |         if (!arg || arg.type !== "Literal" || typeof arg.value !== "string") { | ||||||
|           throw new Error("Path to JSON is not provided"); |           throw new Error("Path to JSON is not provided"); | ||||||
|         } |         } | ||||||
|         var jsonPath = arg.value; |         let jsonPath = arg.value; | ||||||
|         if (jsonPath.indexOf(ROOT_PREFIX) === 0) { |         if (jsonPath.indexOf(ROOT_PREFIX) === 0) { | ||||||
|           jsonPath = path.join( |           jsonPath = path.join( | ||||||
|             ctx.rootPath, |             ctx.rootPath, | ||||||
|             jsonPath.substring(ROOT_PREFIX.length) |             jsonPath.substring(ROOT_PREFIX.length) | ||||||
|           ); |           ); | ||||||
|         } |         } | ||||||
|         var jsonContent = fs.readFileSync(jsonPath).toString(); |         const jsonContent = fs.readFileSync(jsonPath).toString(); | ||||||
|         const parsedJSON = acorn.parse("(" + jsonContent + ")", { |         const parsedJSON = acorn.parse("(" + jsonContent + ")", { | ||||||
|           ecmaVersion: ACORN_ECMA_VERSION, |           ecmaVersion: ACORN_ECMA_VERSION, | ||||||
|         }); |         }); | ||||||
| @ -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; | ||||||
| @ -175,7 +175,7 @@ function postprocessNode(ctx, node) { | |||||||
|               case "string": |               case "string": | ||||||
|               case "boolean": |               case "boolean": | ||||||
|               case "number": |               case "number": | ||||||
|                 var equal = node.left.value === node.right.value; |                 const equal = node.left.value === node.right.value; | ||||||
|                 return { |                 return { | ||||||
|                   type: "Literal", |                   type: "Literal", | ||||||
|                   value: (node.operator[0] === "=") === equal, |                   value: (node.operator[0] === "=") === equal, | ||||||
| @ -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,12 +205,12 @@ 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; | ||||||
|     case "BlockStatement": |     case "BlockStatement": | ||||||
|       var subExpressionIndex = 0; |       let subExpressionIndex = 0; | ||||||
|       while (subExpressionIndex < node.body.length) { |       while (subExpressionIndex < node.body.length) { | ||||||
|         switch (node.body[subExpressionIndex].type) { |         switch (node.body[subExpressionIndex].type) { | ||||||
|           case "EmptyStatement": |           case "EmptyStatement": | ||||||
| @ -219,7 +219,7 @@ function postprocessNode(ctx, node) { | |||||||
|             continue; |             continue; | ||||||
|           case "BlockStatement": |           case "BlockStatement": | ||||||
|             // Block statements inside a block are moved to the parent one.
 |             // Block statements inside a block are moved to the parent one.
 | ||||||
|             var subChildren = node.body[subExpressionIndex].body; |             const subChildren = node.body[subExpressionIndex].body; | ||||||
|             Array.prototype.splice.apply( |             Array.prototype.splice.apply( | ||||||
|               node.body, |               node.body, | ||||||
|               [subExpressionIndex, 1].concat(subChildren) |               [subExpressionIndex, 1].concat(subChildren) | ||||||
| @ -240,7 +240,7 @@ function postprocessNode(ctx, node) { | |||||||
|       break; |       break; | ||||||
|     case "FunctionDeclaration": |     case "FunctionDeclaration": | ||||||
|     case "FunctionExpression": |     case "FunctionExpression": | ||||||
|       var block = node.body; |       const block = node.body; | ||||||
|       if ( |       if ( | ||||||
|         block.body.length > 0 && |         block.body.length > 0 && | ||||||
|         block.body[block.body.length - 1].type === "ReturnStatement" && |         block.body[block.body.length - 1].type === "ReturnStatement" && | ||||||
| @ -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,8 +291,8 @@ 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]; |     const 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); | ||||||
|       if (result !== child) { |       if (result !== 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…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user