diff --git a/README.md b/README.md index 4818624c..51f74a51 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,5 @@ uglify-es ========= -[![Build Status](https://travis-ci.org/mishoo/UglifyJS2.svg)](https://travis-ci.org/mishoo/UglifyJS2) **uglify-es** is an ECMAScript 2015 parser, minifier, compressor and beautifier toolkit. @@ -550,10 +549,10 @@ If you're using the `X-SourceMap` header instead, you can just omit `sourceMap.u - `keep_infinity` -- default `false`. Pass `true` to prevent `Infinity` from being compressed into `1/0`, which may cause performance issues on Chrome. -- `side_effects` -- default `false`. Pass `true` to potentially drop functions -marked as "pure". A function call is marked as "pure" if a comment annotation -`/*@__PURE__*/` or `/*#__PURE__*/` immediately precedes the call. For example: -`/*@__PURE__*/foo()`; +- `side_effects` -- default `true`. Pass `false` to disable potentially dropping +functions marked as "pure". A function call is marked as "pure" if a comment +annotation `/*@__PURE__*/` or `/*#__PURE__*/` immediately precedes the call. For +example: `/*@__PURE__*/foo()`; ## Mangle options @@ -604,36 +603,36 @@ The code generator tries to output shortest code possible by default. In case you want beautified output, pass `--beautify` (`-b`). Optionally you can pass additional arguments that control the code output: +- `ascii_only` (default `false`) -- escape Unicode characters in strings and + regexps (affects directives with non-ascii characters becoming invalid) - `beautify` (default `true`) -- whether to actually beautify the output. Passing `-b` will set this to true, but you might need to pass `-b` even when you want to generate minified code, in order to specify additional arguments, so you can use `-b beautify=false` to override it. -- `indent_level` (default 4) -- `indent_start` (default 0) -- prefix all lines by that many spaces -- `quote_keys` (default `false`) -- pass `true` to quote all keys in literal - objects -- `space_colon` (default `true`) -- insert a space after the colon signs -- `ascii_only` (default `false`) -- escape Unicode characters in strings and - regexps (affects directives with non-ascii characters becoming invalid) -- `inline_script` (default `false`) -- escape the slash in occurrences of - ` (http://lisperator.net/)", "license": "BSD-2-Clause", - "version": "3.0.7", + "version": "3.0.8", "engines": { "node": ">=0.8.0" }, @@ -34,7 +34,8 @@ }, "devDependencies": { "acorn": "~5.0.3", - "mocha": "~2.3.4" + "mocha": "~2.3.4", + "semver": "~5.3.0" }, "scripts": { "test": "node test/run-tests.js" diff --git a/test/compress/node_version.js b/test/compress/node_version.js new file mode 100644 index 00000000..ad0bfa15 --- /dev/null +++ b/test/compress/node_version.js @@ -0,0 +1,12 @@ +eval_let: { + input: { + eval("let a;"); + console.log(); + } + expect: { + eval("let a;"); + console.log(); + } + expect_stdout: "" + node_version: ">=6" +} diff --git a/test/compress/string-literal.js b/test/compress/string-literal.js index 8b93961c..1138fed8 100644 --- a/test/compress/string-literal.js +++ b/test/compress/string-literal.js @@ -8,3 +8,12 @@ octal_escape_sequence: { var border_check = "\x20\x30\x38\x30\x00\x30\xc0\x30"; } } + +issue_1929: { + input: { + function f(s) { + return s.split(/[\\/]/); + } + } + expect_exact: "function f(s){return s.split(/[\\\\/]/)}" +} diff --git a/test/run-tests.js b/test/run-tests.js index edcd7cc9..8427d4a8 100755 --- a/test/run-tests.js +++ b/test/run-tests.js @@ -5,6 +5,7 @@ var path = require("path"); var fs = require("fs"); var assert = require("assert"); var sandbox = require("./sandbox"); +var semver = require("semver"); var tests_dir = path.dirname(module.filename); var failures = 0; @@ -164,7 +165,8 @@ function run_compress_tests() { failed_files[file] = 1; } } - if (test.expect_stdout) { + if (test.expect_stdout + && (!test.node_version || semver.satisfies(process.version, test.node_version))) { var stdout = sandbox.run_code(input_code); if (test.expect_stdout === true) { test.expect_stdout = stdout; @@ -274,7 +276,14 @@ function parse_test(file) { if (node instanceof U.AST_LabeledStatement) { var label = node.label; assert.ok( - ["input", "expect", "expect_exact", "expect_warnings", "expect_stdout"].indexOf(label.name) >= 0, + [ + "input", + "expect", + "expect_exact", + "expect_warnings", + "expect_stdout", + "node_version", + ].indexOf(label.name) >= 0, tmpl("Unsupported label {name} [{line},{col}]", { name: label.name, line: label.start.line, @@ -282,7 +291,7 @@ function parse_test(file) { }) ); var stat = node.body; - if (label.name == "expect_exact") { + if (label.name == "expect_exact" || label.name == "node_version") { test[label.name] = read_string(stat); } else if (label.name == "expect_stdout") { if (stat.TYPE == "SimpleStatement" && stat.body instanceof U.AST_Boolean) { diff --git a/test/sandbox.js b/test/sandbox.js index c155f91c..974f5211 100644 --- a/test/sandbox.js +++ b/test/sandbox.js @@ -1,3 +1,4 @@ +var semver = require("semver"); var vm = require("vm"); function safe_log(arg, level) { @@ -63,7 +64,7 @@ exports.run_code = function(code) { process.stdout.write = original_write; } }; -exports.same_stdout = ~process.version.lastIndexOf("v0.12.", 0) ? function(expected, actual) { +exports.same_stdout = semver.satisfies(process.version, "0.12") ? function(expected, actual) { if (typeof expected != typeof actual) return false; if (typeof expected != "string") { if (expected.name != actual.name) return false;