diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/compress/collapse_vars.js | 31 | ||||
-rw-r--r-- | test/compress/pure_funcs.js | 2 | ||||
-rw-r--r-- | test/compress/side_effects.js | 23 | ||||
-rw-r--r-- | test/mocha/operator.js | 15 | ||||
-rw-r--r-- | test/ufuzz/index.js | 24 |
5 files changed, 86 insertions, 9 deletions
diff --git a/test/compress/collapse_vars.js b/test/compress/collapse_vars.js index 0c232aa0..f99e0124 100644 --- a/test/compress/collapse_vars.js +++ b/test/compress/collapse_vars.js @@ -8164,3 +8164,34 @@ issue_3927: { } expect_stdout: "PASS" } + +operator_in: { + options = { + collapse_vars: true, + } + input: { + function log(msg) { + console.log(msg); + } + var a = "FAIL"; + try { + a = "PASS"; + 0 in null; + log("FAIL", a); + } catch (e) {} + log(a); + } + expect: { + function log(msg) { + console.log(msg); + } + var a = "FAIL"; + try { + a = "PASS"; + 0 in null; + log("FAIL", a); + } catch (e) {} + log(a); + } + expect_stdout: "PASS" +} diff --git a/test/compress/pure_funcs.js b/test/compress/pure_funcs.js index d65399f1..09f0bd45 100644 --- a/test/compress/pure_funcs.js +++ b/test/compress/pure_funcs.js @@ -136,7 +136,7 @@ relational: { side_effects :true, } input: { - foo() in foo(); + foo() in new foo(); foo() instanceof bar(); foo() < "bar"; bar() > foo(); diff --git a/test/compress/side_effects.js b/test/compress/side_effects.js index 63282660..b7ffe47a 100644 --- a/test/compress/side_effects.js +++ b/test/compress/side_effects.js @@ -274,3 +274,26 @@ drop_value: { foo(), bar(); } } + +operator_in: { + options = { + side_effects: true, + } + input: { + try { + "foo" in true; + console.log("FAIL"); + } catch (e) { + console.log("PASS"); + } + } + expect: { + try { + 0 in true; + console.log("FAIL"); + } catch (e) { + console.log("PASS"); + } + } + expect_stdout: "PASS" +} diff --git a/test/mocha/operator.js b/test/mocha/operator.js index d36d3a1d..8dfea547 100644 --- a/test/mocha/operator.js +++ b/test/mocha/operator.js @@ -486,4 +486,19 @@ describe("operator", function() { assert.strictEqual(UglifyJS.parse(exp[0]).print_to_string(), exp[1] + ";"); }); }); + it("Should preserve space between /regex/ and `in`", function() { + [ + "/regex/ in {}", + "/regex/g in {}", + "0 + /regex/ in {}", + "0 + /regex/g in {}", + ].forEach(function(exp) { + var code = UglifyJS.parse(exp).print_to_string(); + try { + assert.strictEqual(UglifyJS.parse(code).print_to_string(), code); + } catch (ex) { + assert.fail("Failed to reparse: " + exp + "\n" + ex); + } + }); + }); }); diff --git a/test/ufuzz/index.js b/test/ufuzz/index.js index edd2ab80..eec4ab4a 100644 --- a/test/ufuzz/index.js +++ b/test/ufuzz/index.js @@ -168,7 +168,7 @@ var VALUES = [ "this", ]; -var BINARY_OPS_NO_COMMA = [ +var BINARY_OPS = [ " + ", // spaces needed to disambiguate with ++ cases (could otherwise cause syntax errors) " - ", "/", @@ -190,9 +190,14 @@ var BINARY_OPS_NO_COMMA = [ "%", "&&", "||", - "^" ]; - -var BINARY_OPS = [","].concat(BINARY_OPS_NO_COMMA); + "^", + ",", +]; +BINARY_OPS = BINARY_OPS.concat(BINARY_OPS); +BINARY_OPS = BINARY_OPS.concat(BINARY_OPS); +BINARY_OPS = BINARY_OPS.concat(BINARY_OPS); +BINARY_OPS = BINARY_OPS.concat(BINARY_OPS); +BINARY_OPS.push(" in "); var ASSIGNMENTS = [ "=", @@ -879,7 +884,7 @@ function createNestedBinaryExpr(recurmax, noComma, stmtDepth, canThrow) { } function _createBinaryExpr(recurmax, noComma, stmtDepth, canThrow) { return "(" + _createSimpleBinaryExpr(recurmax, noComma, stmtDepth, canThrow) - + createBinaryOp(noComma) + _createSimpleBinaryExpr(recurmax, noComma, stmtDepth, canThrow) + ")"; + + createBinaryOp(noComma, canThrow) + _createSimpleBinaryExpr(recurmax, noComma, stmtDepth, canThrow) + ")"; } function _createSimpleBinaryExpr(recurmax, noComma, stmtDepth, canThrow) { // intentionally generate more hardcore ops @@ -929,9 +934,12 @@ function createValue() { return VALUES[rng(VALUES.length)]; } -function createBinaryOp(noComma) { - if (noComma) return BINARY_OPS_NO_COMMA[rng(BINARY_OPS_NO_COMMA.length)]; - return BINARY_OPS[rng(BINARY_OPS.length)]; +function createBinaryOp(noComma, canThrow) { + var op; + do { + op = BINARY_OPS[rng(BINARY_OPS.length)]; + } while (noComma && op == "," || !canThrow && op == " in "); + return op; } function createAssignment() { |