Skip to content

Commit 94a954c

Browse files
authored
minor clean-ups (#5701)
1 parent be8ccc3 commit 94a954c

File tree

17 files changed

+89
-77
lines changed

17 files changed

+89
-77
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Contributing
33

44
## Documentation
55

6-
Every new feature and API change should be accompanied by a README additon.
6+
Every new feature and API change should be accompanied by a README addition.
77

88
## Testing
99

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,7 @@ to be `false` and all symbol names will be omitted.
646646
- `bare_returns` (default: `false`) — support top level `return` statements
647647

648648
- `html5_comments` (default: `true`) — process HTML comment as workaround for
649-
browsers which do not recognise `<script>` tags
649+
browsers which do not recognize `<script>` tags
650650

651651
- `module` (default: `false`) — set to `true` if you wish to process input as
652652
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.
753753
ES module, i.e. implicit `"use strict";` alongside with `toplevel` enabled.
754754

755755
- `negate_iife` (default: `true`) — negate "Immediately-Called Function Expressions"
756-
where the return value is discarded, to avoid the parens that the
756+
where the return value is discarded, to avoid the parentheses that the
757757
code generator would insert.
758758

759759
- `objects` (default: `true`) — compact duplicate keys in object literals.
@@ -851,7 +851,7 @@ to be `false` and all symbol names will be omitted.
851851
- `unused` (default: `true`) — drop unreferenced functions and variables (simple
852852
direct variable assignments do not count as references unless set to `"keep_assign"`)
853853

854-
- `varify` (default: `true`) — convert block-scoped declaractions into `var`
854+
- `varify` (default: `true`) — convert block-scoped declarations into `var`
855855
whenever safe to do so
856856

857857
- `yields` (default: `true`) — apply optimizations to `yield` expressions

lib/ast.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ var AST_SimpleStatement = DEFNODE("SimpleStatement", "body", {
332332
var AST_BlockScope = DEFNODE("BlockScope", "_var_names enclosed functions make_def parent_scope variables", {
333333
$documentation: "Base class for all statements introducing a lexical scope",
334334
$propdoc: {
335-
enclosed: "[SymbolDef*/S] a list of all symbol definitions that are accessed from this scope or any subscopes",
335+
enclosed: "[SymbolDef*/S] a list of all symbol definitions that are accessed from this scope or any inner scopes",
336336
functions: "[Dictionary/S] like `variables`, but only lists function declarations",
337337
parent_scope: "[AST_Scope?/S] link to the parent scope",
338338
variables: "[Dictionary/S] a map of name ---> SymbolDef for all variables/functions defined in this scope",

lib/compress.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,6 @@ Compressor.prototype.compress = function(node) {
368368
args: [],
369369
});
370370
}
371-
return self;
372371
});
373372
AST_Node.DEFMETHOD("wrap_expression", function() {
374373
var self = this;
@@ -5083,7 +5082,7 @@ Compressor.prototype.compress = function(node) {
50835082
return static_fn && (static_fn[node.property] || expr.name == "Math" && node.property == "random");
50845083
}
50855084

5086-
// Accomodate when compress option evaluate=false
5085+
// Accommodate when compress option evaluate=false
50875086
// as well as the common constant expressions !0 and -1
50885087
(function(def) {
50895088
def(AST_Node, return_false);
@@ -11882,7 +11881,7 @@ Compressor.prototype.compress = function(node) {
1188211881
if (nullish ? ll == null : !ll) {
1188311882
AST_Node.warn("Condition left of {operator} always {value} [{start}]", {
1188411883
operator: self.operator,
11885-
value: nullish ? "nulish" : "false",
11884+
value: nullish ? "nullish" : "false",
1188611885
start: self.start,
1188711886
});
1188811887
return make_sequence(self, [ self.left, self.right ]).optimize(compressor);

lib/output.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ function OutputStream(options) {
7676
wrap_iife : false,
7777
}, true);
7878

79-
// Convert comment option to RegExp if neccessary and set up comments filter
79+
// Convert comment option to RegExp if necessary and set up comments filter
8080
var comment_filter = return_false; // Default case, throw all comments away
8181
if (options.comments) {
8282
var comments = options.comments;
@@ -997,7 +997,7 @@ function OutputStream(options) {
997997
if (self.init instanceof AST_Definitions) {
998998
self.init.print(output);
999999
} else {
1000-
parenthesize_for_noin(self.init, output, true);
1000+
parenthesize_for_no_in(self.init, output, true);
10011001
}
10021002
output.print(";");
10031003
output.space();
@@ -1413,7 +1413,7 @@ function OutputStream(options) {
14131413
print_braced(this, output);
14141414
});
14151415

1416-
function print_definitinos(type) {
1416+
function print_definitions(type) {
14171417
return function(output) {
14181418
var self = this;
14191419
output.print(type);
@@ -1426,15 +1426,15 @@ function OutputStream(options) {
14261426
if (!(p instanceof AST_IterationStatement && p.init === self)) output.semicolon();
14271427
};
14281428
}
1429-
DEFPRINT(AST_Const, print_definitinos("const"));
1430-
DEFPRINT(AST_Let, print_definitinos("let"));
1431-
DEFPRINT(AST_Var, print_definitinos("var"));
1429+
DEFPRINT(AST_Const, print_definitions("const"));
1430+
DEFPRINT(AST_Let, print_definitions("let"));
1431+
DEFPRINT(AST_Var, print_definitions("var"));
14321432

1433-
function parenthesize_for_noin(node, output, noin) {
1433+
function parenthesize_for_no_in(node, output, no_in) {
14341434
var parens = false;
14351435
// need to take some precautions here:
14361436
// https://github.com/mishoo/UglifyJS/issues/60
1437-
if (noin) node.walk(new TreeWalker(function(node) {
1437+
if (no_in) node.walk(new TreeWalker(function(node) {
14381438
if (parens) return true;
14391439
if (node instanceof AST_Binary && node.operator == "in") return parens = true;
14401440
if (node instanceof AST_Scope && !(is_arrow(node) && node.value)) return true;
@@ -1450,8 +1450,8 @@ function OutputStream(options) {
14501450
output.print("=");
14511451
output.space();
14521452
var p = output.parent(1);
1453-
var noin = p instanceof AST_For || p instanceof AST_ForEnumeration;
1454-
parenthesize_for_noin(self.value, output, noin);
1453+
var no_in = p instanceof AST_For || p instanceof AST_ForEnumeration;
1454+
parenthesize_for_no_in(self.value, output, no_in);
14551455
}
14561456
});
14571457

lib/parse.js

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,7 @@ function parse($TEXT, options) {
782782
else if (!optional && !can_insert_semicolon()) expect(";");
783783
}
784784

785-
function parenthesised() {
785+
function parenthesized() {
786786
expect("(");
787787
var exp = expression();
788788
expect(")");
@@ -920,18 +920,18 @@ function parse($TEXT, options) {
920920
next();
921921
var body = in_loop(statement);
922922
expect_token("keyword", "while");
923-
var condition = parenthesised();
923+
var condition = parenthesized();
924924
semicolon(true);
925925
return new AST_Do({
926926
body : body,
927-
condition : condition
927+
condition : condition,
928928
});
929929

930930
case "while":
931931
next();
932932
return new AST_While({
933-
condition : parenthesised(),
934-
body : in_loop(statement)
933+
condition : parenthesized(),
934+
body : in_loop(statement),
935935
});
936936

937937
case "for":
@@ -959,15 +959,13 @@ function parse($TEXT, options) {
959959
value = expression();
960960
semicolon();
961961
}
962-
return new AST_Return({
963-
value: value
964-
});
962+
return new AST_Return({ value: value });
965963

966964
case "switch":
967965
next();
968966
return new AST_Switch({
969-
expression : parenthesised(),
970-
body : in_loop(switch_body_)
967+
expression : parenthesized(),
968+
body : in_loop(switch_body_),
971969
});
972970

973971
case "throw":
@@ -976,9 +974,7 @@ function parse($TEXT, options) {
976974
croak("Illegal newline after 'throw'");
977975
var value = expression();
978976
semicolon();
979-
return new AST_Throw({
980-
value: value
981-
});
977+
return new AST_Throw({ value: value });
982978

983979
case "try":
984980
next();
@@ -996,8 +992,8 @@ function parse($TEXT, options) {
996992
}
997993
next();
998994
return new AST_With({
999-
expression : parenthesised(),
1000-
body : statement()
995+
expression : parenthesized(),
996+
body : statement(),
1001997
});
1002998
}
1003999
}
@@ -1421,15 +1417,15 @@ function parse($TEXT, options) {
14211417
};
14221418

14231419
function if_() {
1424-
var cond = parenthesised(), body = statement(), belse = null;
1420+
var cond = parenthesized(), body = statement(), alt = null;
14251421
if (is("keyword", "else")) {
14261422
next();
1427-
belse = statement();
1423+
alt = statement();
14281424
}
14291425
return new AST_If({
14301426
condition : cond,
14311427
body : body,
1432-
alternative : belse
1428+
alternative : alt,
14331429
});
14341430
}
14351431

@@ -2171,9 +2167,9 @@ function parse($TEXT, options) {
21712167
token_error(sym.start, "Unexpected " + sym.name + " in strict mode");
21722168
}
21732169

2174-
function as_symbol(type, noerror) {
2170+
function as_symbol(type, no_error) {
21752171
if (!is("name")) {
2176-
if (!noerror) croak("Name expected");
2172+
if (!no_error) croak("Name expected");
21772173
return null;
21782174
}
21792175
var sym = _make_symbol(type, S.token);
@@ -2409,20 +2405,20 @@ function parse($TEXT, options) {
24092405
return new ctor({ operator: op, expression: expr });
24102406
}
24112407

2412-
var expr_op = function(left, min_prec, no_in) {
2408+
var expr_op = function(left, min_precision, no_in) {
24132409
var op = is("operator") ? S.token.value : null;
24142410
if (op == "in" && no_in) op = null;
2415-
var prec = op != null ? PRECEDENCE[op] : null;
2416-
if (prec != null && prec > min_prec) {
2411+
var precision = op != null ? PRECEDENCE[op] : null;
2412+
if (precision != null && precision > min_precision) {
24172413
next();
2418-
var right = expr_op(maybe_unary(no_in), op == "**" ? prec - 1 : prec, no_in);
2414+
var right = expr_op(maybe_unary(no_in), op == "**" ? precision - 1 : precision, no_in);
24192415
return expr_op(new AST_Binary({
24202416
start : left.start,
24212417
left : left,
24222418
operator : op,
24232419
right : right,
2424-
end : right.end
2425-
}), min_prec, no_in);
2420+
end : right.end,
2421+
}), min_precision, no_in);
24262422
}
24272423
return left;
24282424
};

lib/propmangle.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ function mangle_properties(ast, options) {
188188
var regex = options.regex;
189189

190190
// note debug is either false (disabled), or a string of the debug suffix to use (enabled).
191-
// note debug may be enabled as an empty string, which is falsey. Also treat passing 'true'
191+
// note debug may be enabled as an empty string, which is falsy. Also treat passing 'true'
192192
// the same as passing an empty string.
193193
var debug = options.debug !== false;
194194
var debug_suffix;

test/compress/concat-strings.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ concat_1: {
1212

1313
var e = 1 + x() + 2 + "X" + 3 + "boo";
1414

15-
// be careful with concatentation with "\0" with octal-looking strings.
15+
// be careful with concatenation with "\0" with octal-looking strings.
1616
var f = "\0" + 360 + "\0" + 8 + "\0";
1717
}
1818
expect: {

test/compress/if_return.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ if_var_return_2: {
525525
}
526526
}
527527

528-
if_var_retrn_3: {
528+
if_var_return_3: {
529529
options = {
530530
conditionals: true,
531531
if_return: true,

test/compress/imports.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,12 @@ mangle: {
140140
}
141141
input: {
142142
import foo, { bar } from "baz";
143-
consoe.log(moo);
143+
console.log(moo);
144144
import * as moo from "moz";
145145
}
146146
expect: {
147147
import o, { bar as m } from "baz";
148-
consoe.log(r);
148+
console.log(r);
149149
import * as r from "moz";
150150
}
151151
}
@@ -157,12 +157,12 @@ rename_mangle: {
157157
}
158158
input: {
159159
import foo, { bar } from "baz";
160-
consoe.log(moo);
160+
console.log(moo);
161161
import * as moo from "moz";
162162
}
163163
expect: {
164164
import o, { bar as m } from "baz";
165-
consoe.log(r);
165+
console.log(r);
166166
import * as r from "moz";
167167
}
168168
}

0 commit comments

Comments
 (0)