fix issues in tests flagged by LGTM (#5150)
authorAlex Lam S.L <alexlamsl@gmail.com>
Wed, 20 Oct 2021 18:07:23 +0000 (02:07 +0800)
committerGitHub <noreply@github.com>
Wed, 20 Oct 2021 18:07:23 +0000 (02:07 +0800)
test/input/reduce/diff_error.reduced.js
test/mocha/comments.js
test/mocha/glob.js
test/mocha/minify.js
test/mocha/reduce.js
test/mocha/sourcemaps.js
test/mocha/string-literal.js
test/reduce.js
test/sandbox.js
test/ufuzz/index.js

index 3002460..4fed66e 100644 (file)
@@ -1,7 +1,5 @@
 // (beautified)
-console.log(function() {
-    return 1 + .1 + .1;
-}());
+console.log(1 + .1 + .1);
 // output: 1.2000000000000002
 // 
 // minify: 1.2
index 830ca10..a297089 100644 (file)
@@ -191,7 +191,7 @@ describe("comments", function() {
     });
 
     it("Should correctly preserve new lines around comments", function() {
-        var tests = [
+        [
             [
                 "// foo",
                 "// bar",
index 0f437c3..926c2f7 100644 (file)
@@ -1,7 +1,6 @@
 var assert = require("assert");
 var exec = require("child_process").exec;
 var path = require("path");
-var readFileSync = require("fs").readFileSync;
 
 describe("bin/uglifyjs with input file globs", function() {
     var uglifyjscmd = '"' + process.argv[0] + '" bin/uglifyjs';
index f80ada1..a57f275 100644 (file)
@@ -25,7 +25,7 @@ describe("minify", function() {
         if (result.error) throw result.error;
         assert.strictEqual(result.code, "print(42);");
         assert.strictEqual(JSON.stringify(options), value);
-    })
+    });
     it("Should skip inherited keys from `files`", function() {
         var files = Object.create({ skip: this });
         files[0] = "alert(1 + 1)";
index abe4e78..037d328 100644 (file)
@@ -1,5 +1,4 @@
 var assert = require("assert");
-var exec = require("child_process").exec;
 var fs = require("fs");
 var reduce_test = require("../reduce");
 var semver = require("semver");
index 3201756..24a60f2 100644 (file)
@@ -362,7 +362,7 @@ describe("sourcemaps", function() {
         it("Should not modify input source map", function() {
             var orig = get_map();
             var original = JSON.stringify(orig);
-            var map = prepare_map(orig);
+            prepare_map(orig);
             assert.strictEqual(JSON.stringify(orig), original);
         });
         it("Should copy over original sourcesContent", function() {
index 0274723..a9bac9f 100644 (file)
@@ -12,7 +12,7 @@ describe("String literals", function() {
             '"\u2029"',
         ].forEach(function(input) {
             assert.throws(function() {
-                var ast = UglifyJS.parse(input);
+                UglifyJS.parse(input);
             }, function(e) {
                 return e instanceof UglifyJS.JS_Parse_Error
                     && e.message === "Unterminated string constant";
@@ -44,7 +44,7 @@ describe("String literals", function() {
             '"use strict";\n"\\011"',
         ].forEach(function(input) {
             assert.throws(function() {
-                var output = UglifyJS.parse(input);
+                UglifyJS.parse(input);
             }, function(e) {
                 return e instanceof UglifyJS.JS_Parse_Error
                     && e.message === "Legacy octal escape sequences are not allowed in strict mode";
index 2a16416..30272de 100644 (file)
@@ -215,9 +215,9 @@ module.exports = function reduce_test(testcase, minify_options, reduce_options)
                     // hoist and return expressions from the IIFE function expression
                     var seq = [];
                     node.expression.body.forEach(function(node) {
-                        var expr = expr instanceof U.AST_Exit ? node.value : node.body;
+                        var expr = node instanceof U.AST_Exit ? node.value : node.body;
                         if (expr instanceof U.AST_Node && !U.is_statement(expr) && can_hoist(expr)) {
-                            // collect expressions from each statements' body
+                            // collect expressions from each statement's body
                             seq.push(expr);
                         }
                     });
@@ -395,7 +395,7 @@ module.exports = function reduce_test(testcase, minify_options, reduce_options)
                 var expr = [
                     node.expression,                         // switch expression
                     node.body[0] && node.body[0].expression, // first case expression or undefined
-                    node.body[0] && node.body[0],            // first case body or undefined
+                    node.body[0],                            // first case body or undefined
                 ][ (node.start._permute * steps | 0) % 4 ];
                 node.start._permute += step;
                 if (expr && (!(expr instanceof U.AST_Statement) || !has_loopcontrol(expr, node, parent))) {
index 84d7b07..0ba179e 100644 (file)
@@ -278,11 +278,11 @@ function run_code_exec(code, toplevel, timeout) {
         timeout: timeout || 5000,
     });
     if (result.status === 0) return result.stdout;
+    var msg = ("" + result.stderr).replace(/\r\n/g, "\n");
     if (result.error && result.error.code == "ETIMEDOUT" || /FATAL ERROR:/.test(msg)) {
         return new Error("Script execution timed out.");
     }
     if (result.error) return result.error;
-    var msg = result.stderr.replace(/\r\n/g, "\n");
     var end = msg.indexOf("\n\n-----===== UNCAUGHT EXCEPTION =====-----\n\n");
     var details;
     if (end >= 0) {
index c27b82a..9c47dbf 100644 (file)
@@ -2078,8 +2078,8 @@ if (require.main !== module) {
     return;
 }
 
-function run_code(code, toplevel) {
-    return sandbox.run_code(sandbox.patch_module_statements(code), toplevel);
+function run_code(code, toplevel, timeout) {
+    return sandbox.run_code(sandbox.patch_module_statements(code), toplevel, timeout);
 }
 
 function writeln(stream, msg) {