From 0813c5316fabef4808c541499e47646973efe88c Mon Sep 17 00:00:00 2001 From: alexlamsl Date: Wed, 17 May 2017 10:32:59 +0800 Subject: [PATCH 1/7] remove Travis CI badge --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 52bf4267..a4e7ce23 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,5 @@ UglifyJS 3 ========== -[![Build Status](https://travis-ci.org/mishoo/UglifyJS2.svg)](https://travis-ci.org/mishoo/UglifyJS2) UglifyJS is a JavaScript parser, minifier, compressor and beautifier toolkit. From baef8bf050fd8b4e733e11301912b61470fe61f3 Mon Sep 17 00:00:00 2001 From: Rob Garrison Date: Tue, 16 May 2017 22:54:46 -0500 Subject: [PATCH 2/7] update output options in readme (#1958) --- README.md | 51 +++++++++++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index a4e7ce23..4d60796b 100644 --- a/README.md +++ b/README.md @@ -606,36 +606,33 @@ 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 - ` Date: Wed, 17 May 2017 14:07:34 +0800 Subject: [PATCH 3/7] remove `space_colon` (#1960) Always emit space after colon when `options.output.beautify` is enabled. --- lib/output.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/output.js b/lib/output.js index 0b98825f..b4d31b5b 100644 --- a/lib/output.js +++ b/lib/output.js @@ -70,7 +70,6 @@ function OutputStream(options) { semicolons : true, shebang : true, source_map : null, - space_colon : true, unescape_regexps : false, width : 80, wrap_iife : false, @@ -357,7 +356,7 @@ function OutputStream(options) { function colon() { print(":"); - if (options.space_colon) space(); + space(); }; var add_mapping = options.source_map ? function(token, name) { From 569c21e952c99340db73d6ad1c7102500cc1b341 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Wed, 17 May 2017 20:10:50 +0800 Subject: [PATCH 4/7] improve `RegExp` handling (#1959) - remove `options.output.unescape_regexps` - preserve original pattern whenever possible fixes #54 fixes #1929 --- lib/output.js | 42 ++++----------------------------- lib/parse.js | 16 +++++++------ test/compress/string-literal.js | 9 +++++++ 3 files changed, 23 insertions(+), 44 deletions(-) diff --git a/lib/output.js b/lib/output.js index b4d31b5b..40800559 100644 --- a/lib/output.js +++ b/lib/output.js @@ -70,7 +70,6 @@ function OutputStream(options) { semicolons : true, shebang : true, source_map : null, - unescape_regexps : false, width : 80, wrap_iife : false, }, true); @@ -1260,45 +1259,14 @@ function OutputStream(options) { } }); - function regexp_safe_literal(code) { - return [ - 0x5c , // \ - 0x2f , // / - 0x2e , // . - 0x2b , // + - 0x2a , // * - 0x3f , // ? - 0x28 , // ( - 0x29 , // ) - 0x5b , // [ - 0x5d , // ] - 0x7b , // { - 0x7d , // } - 0x24 , // $ - 0x5e , // ^ - 0x3a , // : - 0x7c , // | - 0x21 , // ! - 0x0a , // \n - 0x0d , // \r - 0x00 , // \0 - 0xfeff , // Unicode BOM - 0x2028 , // unicode "line separator" - 0x2029 , // unicode "paragraph separator" - ].indexOf(code) < 0; - }; - DEFPRINT(AST_RegExp, function(self, output){ - var str = self.getValue().toString(); + var regexp = self.getValue(); + var str = regexp.toString(); + if (regexp.raw_source) { + str = "/" + regexp.raw_source + str.slice(str.lastIndexOf("/")); + } if (output.option("ascii_only")) { str = output.to_ascii(str); - } else if (output.option("unescape_regexps")) { - str = str.split("\\\\").map(function(str){ - return str.replace(/\\u[0-9a-fA-F]{4}|\\x[0-9a-fA-F]{2}/g, function(s){ - var code = parseInt(s.substr(2), 16); - return regexp_safe_literal(code) ? String.fromCharCode(code) : s; - }); - }).join("\\\\"); } output.print(str); var p = output.parent(); diff --git a/lib/parse.js b/lib/parse.js index 97dd6d4b..c960b493 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -477,31 +477,33 @@ function tokenizer($TEXT, filename, html5_comments, shebang) { return name; }; - var read_regexp = with_eof_error("Unterminated regular expression", function(regexp){ + var read_regexp = with_eof_error("Unterminated regular expression", function(source) { var prev_backslash = false, ch, in_class = false; while ((ch = next(true))) if (NEWLINE_CHARS(ch)) { parse_error("Unexpected line terminator"); } else if (prev_backslash) { - regexp += "\\" + ch; + source += "\\" + ch; prev_backslash = false; } else if (ch == "[") { in_class = true; - regexp += ch; + source += ch; } else if (ch == "]" && in_class) { in_class = false; - regexp += ch; + source += ch; } else if (ch == "/" && !in_class) { break; } else if (ch == "\\") { prev_backslash = true; } else { - regexp += ch; + source += ch; } var mods = read_name(); try { - return token("regexp", new RegExp(regexp, mods)); + var regexp = new RegExp(source, mods); + regexp.raw_source = source; + return token("regexp", regexp); } catch(e) { - parse_error(e.message); + parse_error(e.message); } }); 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(/[\\\\/]/)}" +} From 6ed90913cae80e55b9575a64a59ef7b1bd06e702 Mon Sep 17 00:00:00 2001 From: Kara Date: Wed, 17 May 2017 19:51:49 -0700 Subject: [PATCH 5/7] fix docs for side_effects flag to reflect current behavior (#1966) --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 4d60796b..a2997b7f 100644 --- a/README.md +++ b/README.md @@ -552,10 +552,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 From efcf167e5efc95a82678db2056396dcf94993641 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Thu, 18 May 2017 11:28:35 +0800 Subject: [PATCH 6/7] make `expect_stdout` node version specific (#1963) ... via semver string on `node_version` label. --- package.json | 3 ++- test/compress/node_version.js | 12 ++++++++++++ test/run-tests.js | 15 ++++++++++++--- test/sandbox.js | 3 ++- 4 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 test/compress/node_version.js diff --git a/package.json b/package.json index a241a3ce..ef883407 100644 --- a/package.json +++ b/package.json @@ -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/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; From 43add9416b927703471a1a722f6a73dcecb0dac3 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Thu, 18 May 2017 14:49:40 +0800 Subject: [PATCH 7/7] v3.0.8 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ef883407..70967fdd 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "homepage": "http://lisperator.net/uglifyjs", "author": "Mihai Bazon (http://lisperator.net/)", "license": "BSD-2-Clause", - "version": "3.0.7", + "version": "3.0.8", "engines": { "node": ">=0.8.0" },