minor clean-ups (#5701)
This commit is contained in:
@@ -3,7 +3,7 @@ Contributing
|
||||
|
||||
## Documentation
|
||||
|
||||
Every new feature and API change should be accompanied by a README additon.
|
||||
Every new feature and API change should be accompanied by a README addition.
|
||||
|
||||
## Testing
|
||||
|
||||
|
||||
@@ -646,7 +646,7 @@ to be `false` and all symbol names will be omitted.
|
||||
- `bare_returns` (default: `false`) — support top level `return` statements
|
||||
|
||||
- `html5_comments` (default: `true`) — process HTML comment as workaround for
|
||||
browsers which do not recognise `<script>` tags
|
||||
browsers which do not recognize `<script>` tags
|
||||
|
||||
- `module` (default: `false`) — set to `true` if you wish to process input as
|
||||
ES module, i.e. implicit `"use strict";` and support for top-level `await`.
|
||||
@@ -753,7 +753,7 @@ to be `false` and all symbol names will be omitted.
|
||||
ES module, i.e. implicit `"use strict";` alongside with `toplevel` enabled.
|
||||
|
||||
- `negate_iife` (default: `true`) — negate "Immediately-Called Function Expressions"
|
||||
where the return value is discarded, to avoid the parens that the
|
||||
where the return value is discarded, to avoid the parentheses that the
|
||||
code generator would insert.
|
||||
|
||||
- `objects` (default: `true`) — compact duplicate keys in object literals.
|
||||
@@ -851,7 +851,7 @@ to be `false` and all symbol names will be omitted.
|
||||
- `unused` (default: `true`) — drop unreferenced functions and variables (simple
|
||||
direct variable assignments do not count as references unless set to `"keep_assign"`)
|
||||
|
||||
- `varify` (default: `true`) — convert block-scoped declaractions into `var`
|
||||
- `varify` (default: `true`) — convert block-scoped declarations into `var`
|
||||
whenever safe to do so
|
||||
|
||||
- `yields` (default: `true`) — apply optimizations to `yield` expressions
|
||||
|
||||
@@ -332,7 +332,7 @@ var AST_SimpleStatement = DEFNODE("SimpleStatement", "body", {
|
||||
var AST_BlockScope = DEFNODE("BlockScope", "_var_names enclosed functions make_def parent_scope variables", {
|
||||
$documentation: "Base class for all statements introducing a lexical scope",
|
||||
$propdoc: {
|
||||
enclosed: "[SymbolDef*/S] a list of all symbol definitions that are accessed from this scope or any subscopes",
|
||||
enclosed: "[SymbolDef*/S] a list of all symbol definitions that are accessed from this scope or any inner scopes",
|
||||
functions: "[Dictionary/S] like `variables`, but only lists function declarations",
|
||||
parent_scope: "[AST_Scope?/S] link to the parent scope",
|
||||
variables: "[Dictionary/S] a map of name ---> SymbolDef for all variables/functions defined in this scope",
|
||||
|
||||
@@ -368,7 +368,6 @@ Compressor.prototype.compress = function(node) {
|
||||
args: [],
|
||||
});
|
||||
}
|
||||
return self;
|
||||
});
|
||||
AST_Node.DEFMETHOD("wrap_expression", function() {
|
||||
var self = this;
|
||||
@@ -5083,7 +5082,7 @@ Compressor.prototype.compress = function(node) {
|
||||
return static_fn && (static_fn[node.property] || expr.name == "Math" && node.property == "random");
|
||||
}
|
||||
|
||||
// Accomodate when compress option evaluate=false
|
||||
// Accommodate when compress option evaluate=false
|
||||
// as well as the common constant expressions !0 and -1
|
||||
(function(def) {
|
||||
def(AST_Node, return_false);
|
||||
@@ -11882,7 +11881,7 @@ Compressor.prototype.compress = function(node) {
|
||||
if (nullish ? ll == null : !ll) {
|
||||
AST_Node.warn("Condition left of {operator} always {value} [{start}]", {
|
||||
operator: self.operator,
|
||||
value: nullish ? "nulish" : "false",
|
||||
value: nullish ? "nullish" : "false",
|
||||
start: self.start,
|
||||
});
|
||||
return make_sequence(self, [ self.left, self.right ]).optimize(compressor);
|
||||
|
||||
@@ -76,7 +76,7 @@ function OutputStream(options) {
|
||||
wrap_iife : false,
|
||||
}, true);
|
||||
|
||||
// Convert comment option to RegExp if neccessary and set up comments filter
|
||||
// Convert comment option to RegExp if necessary and set up comments filter
|
||||
var comment_filter = return_false; // Default case, throw all comments away
|
||||
if (options.comments) {
|
||||
var comments = options.comments;
|
||||
@@ -997,7 +997,7 @@ function OutputStream(options) {
|
||||
if (self.init instanceof AST_Definitions) {
|
||||
self.init.print(output);
|
||||
} else {
|
||||
parenthesize_for_noin(self.init, output, true);
|
||||
parenthesize_for_no_in(self.init, output, true);
|
||||
}
|
||||
output.print(";");
|
||||
output.space();
|
||||
@@ -1413,7 +1413,7 @@ function OutputStream(options) {
|
||||
print_braced(this, output);
|
||||
});
|
||||
|
||||
function print_definitinos(type) {
|
||||
function print_definitions(type) {
|
||||
return function(output) {
|
||||
var self = this;
|
||||
output.print(type);
|
||||
@@ -1426,15 +1426,15 @@ function OutputStream(options) {
|
||||
if (!(p instanceof AST_IterationStatement && p.init === self)) output.semicolon();
|
||||
};
|
||||
}
|
||||
DEFPRINT(AST_Const, print_definitinos("const"));
|
||||
DEFPRINT(AST_Let, print_definitinos("let"));
|
||||
DEFPRINT(AST_Var, print_definitinos("var"));
|
||||
DEFPRINT(AST_Const, print_definitions("const"));
|
||||
DEFPRINT(AST_Let, print_definitions("let"));
|
||||
DEFPRINT(AST_Var, print_definitions("var"));
|
||||
|
||||
function parenthesize_for_noin(node, output, noin) {
|
||||
function parenthesize_for_no_in(node, output, no_in) {
|
||||
var parens = false;
|
||||
// need to take some precautions here:
|
||||
// https://github.com/mishoo/UglifyJS/issues/60
|
||||
if (noin) node.walk(new TreeWalker(function(node) {
|
||||
if (no_in) node.walk(new TreeWalker(function(node) {
|
||||
if (parens) return true;
|
||||
if (node instanceof AST_Binary && node.operator == "in") return parens = true;
|
||||
if (node instanceof AST_Scope && !(is_arrow(node) && node.value)) return true;
|
||||
@@ -1450,8 +1450,8 @@ function OutputStream(options) {
|
||||
output.print("=");
|
||||
output.space();
|
||||
var p = output.parent(1);
|
||||
var noin = p instanceof AST_For || p instanceof AST_ForEnumeration;
|
||||
parenthesize_for_noin(self.value, output, noin);
|
||||
var no_in = p instanceof AST_For || p instanceof AST_ForEnumeration;
|
||||
parenthesize_for_no_in(self.value, output, no_in);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
48
lib/parse.js
48
lib/parse.js
@@ -782,7 +782,7 @@ function parse($TEXT, options) {
|
||||
else if (!optional && !can_insert_semicolon()) expect(";");
|
||||
}
|
||||
|
||||
function parenthesised() {
|
||||
function parenthesized() {
|
||||
expect("(");
|
||||
var exp = expression();
|
||||
expect(")");
|
||||
@@ -920,18 +920,18 @@ function parse($TEXT, options) {
|
||||
next();
|
||||
var body = in_loop(statement);
|
||||
expect_token("keyword", "while");
|
||||
var condition = parenthesised();
|
||||
var condition = parenthesized();
|
||||
semicolon(true);
|
||||
return new AST_Do({
|
||||
body : body,
|
||||
condition : condition
|
||||
condition : condition,
|
||||
});
|
||||
|
||||
case "while":
|
||||
next();
|
||||
return new AST_While({
|
||||
condition : parenthesised(),
|
||||
body : in_loop(statement)
|
||||
condition : parenthesized(),
|
||||
body : in_loop(statement),
|
||||
});
|
||||
|
||||
case "for":
|
||||
@@ -959,15 +959,13 @@ function parse($TEXT, options) {
|
||||
value = expression();
|
||||
semicolon();
|
||||
}
|
||||
return new AST_Return({
|
||||
value: value
|
||||
});
|
||||
return new AST_Return({ value: value });
|
||||
|
||||
case "switch":
|
||||
next();
|
||||
return new AST_Switch({
|
||||
expression : parenthesised(),
|
||||
body : in_loop(switch_body_)
|
||||
expression : parenthesized(),
|
||||
body : in_loop(switch_body_),
|
||||
});
|
||||
|
||||
case "throw":
|
||||
@@ -976,9 +974,7 @@ function parse($TEXT, options) {
|
||||
croak("Illegal newline after 'throw'");
|
||||
var value = expression();
|
||||
semicolon();
|
||||
return new AST_Throw({
|
||||
value: value
|
||||
});
|
||||
return new AST_Throw({ value: value });
|
||||
|
||||
case "try":
|
||||
next();
|
||||
@@ -996,8 +992,8 @@ function parse($TEXT, options) {
|
||||
}
|
||||
next();
|
||||
return new AST_With({
|
||||
expression : parenthesised(),
|
||||
body : statement()
|
||||
expression : parenthesized(),
|
||||
body : statement(),
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1421,15 +1417,15 @@ function parse($TEXT, options) {
|
||||
};
|
||||
|
||||
function if_() {
|
||||
var cond = parenthesised(), body = statement(), belse = null;
|
||||
var cond = parenthesized(), body = statement(), alt = null;
|
||||
if (is("keyword", "else")) {
|
||||
next();
|
||||
belse = statement();
|
||||
alt = statement();
|
||||
}
|
||||
return new AST_If({
|
||||
condition : cond,
|
||||
body : body,
|
||||
alternative : belse
|
||||
alternative : alt,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -2171,9 +2167,9 @@ function parse($TEXT, options) {
|
||||
token_error(sym.start, "Unexpected " + sym.name + " in strict mode");
|
||||
}
|
||||
|
||||
function as_symbol(type, noerror) {
|
||||
function as_symbol(type, no_error) {
|
||||
if (!is("name")) {
|
||||
if (!noerror) croak("Name expected");
|
||||
if (!no_error) croak("Name expected");
|
||||
return null;
|
||||
}
|
||||
var sym = _make_symbol(type, S.token);
|
||||
@@ -2409,20 +2405,20 @@ function parse($TEXT, options) {
|
||||
return new ctor({ operator: op, expression: expr });
|
||||
}
|
||||
|
||||
var expr_op = function(left, min_prec, no_in) {
|
||||
var expr_op = function(left, min_precision, no_in) {
|
||||
var op = is("operator") ? S.token.value : null;
|
||||
if (op == "in" && no_in) op = null;
|
||||
var prec = op != null ? PRECEDENCE[op] : null;
|
||||
if (prec != null && prec > min_prec) {
|
||||
var precision = op != null ? PRECEDENCE[op] : null;
|
||||
if (precision != null && precision > min_precision) {
|
||||
next();
|
||||
var right = expr_op(maybe_unary(no_in), op == "**" ? prec - 1 : prec, no_in);
|
||||
var right = expr_op(maybe_unary(no_in), op == "**" ? precision - 1 : precision, no_in);
|
||||
return expr_op(new AST_Binary({
|
||||
start : left.start,
|
||||
left : left,
|
||||
operator : op,
|
||||
right : right,
|
||||
end : right.end
|
||||
}), min_prec, no_in);
|
||||
end : right.end,
|
||||
}), min_precision, no_in);
|
||||
}
|
||||
return left;
|
||||
};
|
||||
|
||||
@@ -188,7 +188,7 @@ function mangle_properties(ast, options) {
|
||||
var regex = options.regex;
|
||||
|
||||
// note debug is either false (disabled), or a string of the debug suffix to use (enabled).
|
||||
// note debug may be enabled as an empty string, which is falsey. Also treat passing 'true'
|
||||
// note debug may be enabled as an empty string, which is falsy. Also treat passing 'true'
|
||||
// the same as passing an empty string.
|
||||
var debug = options.debug !== false;
|
||||
var debug_suffix;
|
||||
|
||||
@@ -12,7 +12,7 @@ concat_1: {
|
||||
|
||||
var e = 1 + x() + 2 + "X" + 3 + "boo";
|
||||
|
||||
// be careful with concatentation with "\0" with octal-looking strings.
|
||||
// be careful with concatenation with "\0" with octal-looking strings.
|
||||
var f = "\0" + 360 + "\0" + 8 + "\0";
|
||||
}
|
||||
expect: {
|
||||
|
||||
@@ -525,7 +525,7 @@ if_var_return_2: {
|
||||
}
|
||||
}
|
||||
|
||||
if_var_retrn_3: {
|
||||
if_var_return_3: {
|
||||
options = {
|
||||
conditionals: true,
|
||||
if_return: true,
|
||||
|
||||
@@ -140,12 +140,12 @@ mangle: {
|
||||
}
|
||||
input: {
|
||||
import foo, { bar } from "baz";
|
||||
consoe.log(moo);
|
||||
console.log(moo);
|
||||
import * as moo from "moz";
|
||||
}
|
||||
expect: {
|
||||
import o, { bar as m } from "baz";
|
||||
consoe.log(r);
|
||||
console.log(r);
|
||||
import * as r from "moz";
|
||||
}
|
||||
}
|
||||
@@ -157,12 +157,12 @@ rename_mangle: {
|
||||
}
|
||||
input: {
|
||||
import foo, { bar } from "baz";
|
||||
consoe.log(moo);
|
||||
console.log(moo);
|
||||
import * as moo from "moz";
|
||||
}
|
||||
expect: {
|
||||
import o, { bar as m } from "baz";
|
||||
consoe.log(r);
|
||||
console.log(r);
|
||||
import * as r from "moz";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* There was an incorrect sort behaviour documented in issue #143:
|
||||
* There was an incorrect sort behavior documented in issue #143:
|
||||
* (x = f(…)) <= x → x >= (x = f(…))
|
||||
*
|
||||
* For example, let the equation be:
|
||||
@@ -12,37 +12,54 @@
|
||||
* a >= (a = parseInt('100')) → 99 >= 100 → false
|
||||
*/
|
||||
|
||||
tranformation_sort_order_equal: {
|
||||
transformation_sort_order_equal: {
|
||||
options = {
|
||||
comparisons: true,
|
||||
}
|
||||
|
||||
input: { (a = parseInt('100')) == a }
|
||||
expect: { (a = parseInt('100')) == a }
|
||||
input: {
|
||||
console.log((a = parseInt("100")) == a);
|
||||
}
|
||||
expect: {
|
||||
console.log((a = parseInt("100")) == a);
|
||||
}
|
||||
expect_stdout: "true"
|
||||
}
|
||||
|
||||
tranformation_sort_order_unequal: {
|
||||
transformation_sort_order_unequal: {
|
||||
options = {
|
||||
comparisons: true,
|
||||
}
|
||||
|
||||
input: { (a = parseInt('100')) != a }
|
||||
expect: { (a = parseInt('100')) != a }
|
||||
input: {
|
||||
console.log((a = parseInt("100")) != a);
|
||||
}
|
||||
expect: {
|
||||
console.log((a = parseInt("100")) != a);
|
||||
}
|
||||
expect_stdout: "false"
|
||||
}
|
||||
|
||||
tranformation_sort_order_lesser_or_equal: {
|
||||
transformation_sort_order_lesser_or_equal: {
|
||||
options = {
|
||||
comparisons: true,
|
||||
}
|
||||
|
||||
input: { (a = parseInt('100')) <= a }
|
||||
expect: { (a = parseInt('100')) <= a }
|
||||
input: {
|
||||
console.log((a = parseInt("100")) <= a);
|
||||
}
|
||||
expect: {
|
||||
console.log((a = parseInt("100")) <= a);
|
||||
}
|
||||
expect_stdout: "true"
|
||||
}
|
||||
tranformation_sort_order_greater_or_equal: {
|
||||
|
||||
transformation_sort_order_greater_or_equal: {
|
||||
options = {
|
||||
comparisons: true,
|
||||
}
|
||||
|
||||
input: { (a = parseInt('100')) >= a }
|
||||
expect: { (a = parseInt('100')) >= a }
|
||||
}
|
||||
input: {
|
||||
console.log((a = parseInt("100")) >= a);
|
||||
}
|
||||
expect: {
|
||||
console.log((a = parseInt("100")) >= a);
|
||||
}
|
||||
expect_stdout: "true"
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ collapse: {
|
||||
var a;
|
||||
b = c();
|
||||
a = typeof b === 'function' ? b() : b;
|
||||
return 'stirng' == typeof a && d();
|
||||
return 'string' == typeof a && d();
|
||||
}
|
||||
function f3(c) {
|
||||
var a;
|
||||
@@ -41,7 +41,7 @@ collapse: {
|
||||
return void 0 !== ('function' === typeof b ? b() : b) && c();
|
||||
}
|
||||
function f2(b) {
|
||||
return 'stirng' == typeof ('function' === typeof (b = c()) ? b() : b) && d();
|
||||
return 'string' == typeof ('function' === typeof (b = c()) ? b() : b) && d();
|
||||
}
|
||||
function f3(c) {
|
||||
var a;
|
||||
|
||||
@@ -570,7 +570,7 @@ inlined_assignments: {
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
inilne_for: {
|
||||
inline_for: {
|
||||
options = {
|
||||
inline: true,
|
||||
join_vars: true,
|
||||
@@ -590,7 +590,7 @@ inilne_for: {
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
inilne_var: {
|
||||
inline_var: {
|
||||
options = {
|
||||
inline: true,
|
||||
join_vars: true,
|
||||
|
||||
@@ -400,7 +400,7 @@ describe("comments", function() {
|
||||
assert.strictEqual(ast.print_to_string({comments: "all"}), "/*!test1*/\n/*test2*/\n//!test3\n//test4\n//test5\n//!test6\n//test7\n//!test8");
|
||||
});
|
||||
|
||||
it("Should be able to filter commments with the 'some' option", function() {
|
||||
it("Should be able to filter comments with the 'some' option", function() {
|
||||
var ast = UglifyJS.parse("// foo\n/*@preserve*/\n// bar\n/*@license*/\n//@license with the wrong comment type\n/*@cc_on something*/");
|
||||
assert.strictEqual(ast.print_to_string({comments: "some"}), "/*@preserve*/\n/*@license*/\n/*@cc_on something*/");
|
||||
});
|
||||
|
||||
@@ -348,7 +348,7 @@ describe("Directives", function() {
|
||||
'"use strict";doSomething("foo");'
|
||||
],
|
||||
[
|
||||
// Nothing gets optimised in the compressor because "use asm" is the first statement
|
||||
// Nothing gets optimized in the compressor because "use asm" is the first statement
|
||||
'"use asm";"use\\x20strict";1+1;',
|
||||
'"use asm";"use\\x20strict";1+1;'
|
||||
],
|
||||
|
||||
@@ -245,7 +245,7 @@ describe("sourcemaps", function() {
|
||||
if (result.error) throw result.error;
|
||||
assert.strictEqual(result.code + "\n", read("test/input/issue-3294/output.js"));
|
||||
});
|
||||
it("Should work in presence of unrecognised annotations", function() {
|
||||
it("Should work in presence of unrecognized annotations", function() {
|
||||
var result = UglifyJS.minify(read("test/input/issue-3441/input.js"), {
|
||||
compress: false,
|
||||
mangle: false,
|
||||
|
||||
@@ -1142,7 +1142,7 @@ function createStatement(recurmax, canThrow, canBreak, canContinue, cannotReturn
|
||||
}
|
||||
case STMT_FUNC_EXPR:
|
||||
// "In non-strict mode code, functions can only be declared at top level, inside a block, or ..."
|
||||
// (dont both with func decls in `if`; it's only a parser thing because you cant call them without a block)
|
||||
// (don't make func decls in `if`; it's only a parser thing because you can't call them without a block)
|
||||
return "{" + createFunction(recurmax, NO_DEFUN, canThrow, stmtDepth) + "}";
|
||||
case STMT_TRY:
|
||||
// catch var could cause some problems
|
||||
|
||||
Reference in New Issue
Block a user