From 35ecb38c48a97906b3eaa33ea90c4058b43e995f Mon Sep 17 00:00:00 2001 From: Xotic750 Date: Thu, 7 Jan 2016 21:23:29 +0100 Subject: [PATCH] Remove unnecessary semi-colons --- lib/ast.js | 6 +- lib/compress.js | 54 ++++++++-------- lib/mozilla-ast.js | 16 ++--- lib/output.js | 64 +++++++++---------- lib/parse.js | 150 ++++++++++++++++++++++---------------------- lib/scope.js | 4 +- lib/sourcemap.js | 2 +- lib/transform.js | 4 +- lib/utils.js | 52 +++++++-------- test/mozilla-ast.js | 2 +- test/parser.js | 5 +- test/run-tests.js | 2 +- tools/node.js | 2 +- 13 files changed, 181 insertions(+), 182 deletions(-) diff --git a/lib/ast.js b/lib/ast.js index 358862b1..b5df6889 100644 --- a/lib/ast.js +++ b/lib/ast.js @@ -83,7 +83,7 @@ function DEFNODE(type, props, methods, base) { }; exports["AST_" + type] = ctor; return ctor; -}; +} var AST_Token = DEFNODE("Token", "type value line col pos endline endcol endpos nlb comments_before file raw", { }, null); @@ -149,7 +149,7 @@ function walk_body(node, visitor) { else node.body.forEach(function(stat){ stat._walk(visitor); }); -}; +} var AST_Block = DEFNODE("Block", "body", { $documentation: "A body of statements (usually bracketed)", @@ -1171,7 +1171,7 @@ function TreeWalker(callback) { this.visit = callback; this.stack = []; this.directives = Object.create(null); -}; +} TreeWalker.prototype = { _visit: function(node, descend) { this.push(node); diff --git a/lib/compress.js b/lib/compress.js index 52fbb74d..825d0ad7 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -78,7 +78,7 @@ function Compressor(options, false_by_default) { warnings : true, global_defs : {} }, true); -}; +} Compressor.prototype = new TreeTransformer; merge(Compressor.prototype, { @@ -117,7 +117,7 @@ merge(Compressor.prototype, { if (opt === self) return opt; return opt.transform(compressor); }); - }; + } OPT(AST_Node, function(self, compressor){ return self; @@ -135,7 +135,7 @@ merge(Compressor.prototype, { if (!props.end) props.end = orig.end; } return new ctor(props); - }; + } function make_node_from_constant(compressor, val, orig) { // XXX: WIP. @@ -173,7 +173,7 @@ merge(Compressor.prototype, { type: typeof val })); } - }; + } function as_statement_array(thing) { if (thing === null) return []; @@ -181,14 +181,14 @@ merge(Compressor.prototype, { if (thing instanceof AST_EmptyStatement) return []; if (thing instanceof AST_Statement) return [ thing ]; throw new Error("Can't convert thing to statement array"); - }; + } function is_empty(thing) { if (thing === null) return true; if (thing instanceof AST_EmptyStatement) return true; if (thing instanceof AST_BlockStatement) return thing.body.length == 0; return false; - }; + } function loop_body(x) { if (x instanceof AST_Switch) return x; @@ -196,7 +196,7 @@ merge(Compressor.prototype, { return (x.body instanceof AST_BlockStatement ? x.body : x); } return x; - }; + } function tighten_body(statements, compressor) { var CHANGED, max_iter = 10; @@ -328,7 +328,7 @@ merge(Compressor.prototype, { } return a; }, []); - }; + } function handle_if_return(statements, compressor) { var self = compressor.self(); @@ -459,7 +459,7 @@ merge(Compressor.prototype, { } } return ret; - }; + } function eliminate_dead_code(statements, compressor) { var has_quit = false; @@ -490,7 +490,7 @@ merge(Compressor.prototype, { }, []); CHANGED = statements.length != orig; return statements; - }; + } function sequencesize(statements, compressor) { if (statements.length < 2) return statements; @@ -501,7 +501,7 @@ merge(Compressor.prototype, { body: seq })); seq = []; - }; + } statements.forEach(function(stat){ if (stat instanceof AST_SimpleStatement && seq.length < 2000) seq.push(stat.body); else push_seq(), ret.push(stat); @@ -510,7 +510,7 @@ merge(Compressor.prototype, { ret = sequencesize_2(ret, compressor); CHANGED = ret.length != statements.length; return ret; - }; + } function sequencesize_2(statements, compressor) { function cons_seq(right) { @@ -522,7 +522,7 @@ merge(Compressor.prototype, { left = AST_Seq.cons(left, right); } return left.transform(compressor); - }; + } var ret = [], prev = null; statements.forEach(function(stat){ if (prev) { @@ -564,7 +564,7 @@ merge(Compressor.prototype, { prev = stat instanceof AST_SimpleStatement ? stat : null; }); return ret; - }; + } function join_consecutive_vars(statements, compressor) { var prev = null; @@ -592,7 +592,7 @@ merge(Compressor.prototype, { } return a; }, []); - }; + } function negate_iifes(statements, compressor) { statements.forEach(function(stat){ @@ -626,9 +626,9 @@ merge(Compressor.prototype, { })(stat.body); } }); - }; + } - }; + } function extract_declarations_from_unreachable_code(compressor, stat, target) { compressor.warn("Dropping unreachable code [{file}:{line},{col}]", stat.start); @@ -647,7 +647,7 @@ merge(Compressor.prototype, { return true; } })); - }; + } /* -----[ boolean/negation helpers ]----- */ @@ -713,7 +713,7 @@ merge(Compressor.prototype, { return ast1.print_to_string().length > ast2.print_to_string().length ? ast2 : ast1; - }; + } // methods to evaluate a constant expression (function (def){ @@ -777,7 +777,7 @@ merge(Compressor.prototype, { if (!compressor) throw new Error("Compressor must be passed"); return node._eval(compressor); - }; + } def(AST_Node, function(){ throw def; // not constant }); @@ -869,7 +869,7 @@ merge(Compressor.prototype, { operator: "!", expression: exp }); - }; + } def(AST_Node, function(){ return basic_negation(this); }); @@ -1017,14 +1017,14 @@ merge(Compressor.prototype, { // tell me if a statement aborts function aborts(thing) { return thing && thing.aborts(); - }; + } (function(def){ def(AST_Statement, function(){ return null }); def(AST_Jump, function(){ return this }); function block_aborts(){ var n = this.body.length; return n > 0 && aborts(this.body[n - 1]); - }; + } def(AST_BlockStatement, block_aborts); def(AST_SwitchBranch, block_aborts); def(AST_If, function(){ @@ -1391,7 +1391,7 @@ merge(Compressor.prototype, { definitions: defs }); hoisted.push(defs); - }; + } } self.body = dirs.concat(hoisted, self.body); } @@ -1471,7 +1471,7 @@ merge(Compressor.prototype, { drop_it(first.body); } } - }; + } OPT(AST_While, function(self, compressor) { if (!compressor.option("loops")) return self; @@ -1862,7 +1862,7 @@ merge(Compressor.prototype, { })); } catch(ex) { if (ex !== ast) throw ex; - }; + } if (!fun) return self; var args = fun.argnames.map(function(arg, i){ return make_node(AST_String, self.args[i], { @@ -2611,7 +2611,7 @@ merge(Compressor.prototype, { return make_node(AST_True, self); } return self; - }; + } OPT(AST_Array, literals_in_boolean_context); OPT(AST_Object, literals_in_boolean_context); OPT(AST_RegExp, literals_in_boolean_context); diff --git a/lib/mozilla-ast.js b/lib/mozilla-ast.js index c1b2b683..cf5cf965 100644 --- a/lib/mozilla-ast.js +++ b/lib/mozilla-ast.js @@ -410,7 +410,7 @@ endpos : range ? range[0] : moznode.start, raw : raw_token(moznode), }); - }; + } function my_end_token(moznode) { var loc = moznode.loc, end = loc && loc.end; @@ -425,7 +425,7 @@ endpos : range ? range[1] : moznode.end, raw : raw_token(moznode), }); - }; + } function map(moztype, mytype, propmap) { var moz_to_me = "function From_Moz_" + moztype + "(M){\n"; @@ -480,7 +480,7 @@ ); MOZ_TO_ME[moztype] = moz_to_me; def_to_moz(mytype, me_to_moz); - }; + } var FROM_MOZ_STACK = null; @@ -489,7 +489,7 @@ var ret = node != null ? MOZ_TO_ME[node.type](node) : null; FROM_MOZ_STACK.pop(); return ret; - }; + } AST_Node.from_mozilla_ast = function(node){ var save_stack = FROM_MOZ_STACK; @@ -515,23 +515,23 @@ } } return moznode; - }; + } function def_to_moz(mytype, handler) { mytype.DEFMETHOD("to_mozilla_ast", function() { return set_moz_loc(this, handler(this)); }); - }; + } function to_moz(node) { return node != null ? node.to_mozilla_ast() : null; - }; + } function to_moz_block(node) { return { type: "BlockStatement", body: node.body.map(to_moz) }; - }; + } })(); diff --git a/lib/output.js b/lib/output.js index c0b86b96..9e1d5f41 100644 --- a/lib/output.js +++ b/lib/output.js @@ -84,7 +84,7 @@ function OutputStream(options) { return "\\u" + code; } }); - }; + } function make_string(str, quote) { var dq = 0, sq = 0; @@ -122,7 +122,7 @@ function OutputStream(options) { default: return dq > sq ? quote_single() : quote_double(); } - }; + } function encode_string(str, quote) { var ret = make_string(str, quote); @@ -132,18 +132,18 @@ function OutputStream(options) { ret = ret.replace(/--\x3e/g, "--\\x3e"); } return ret; - }; + } function make_name(name) { name = name.toString(); if (options.ascii_only) name = to_ascii(name, true); return name; - }; + } function make_indent(back) { return repeat_string(" ", options.indent_start + indentation - back * options.indent_level); - }; + } /* -----[ beautification/minification ]----- */ @@ -153,12 +153,12 @@ function OutputStream(options) { function last_char() { return last.charAt(last.length - 1); - }; + } function maybe_newline() { if (options.max_line_len && current_col > options.max_line_len) print("\n"); - }; + } var requireSemicolonChars = makePredicate("( [ + * / - , ."); @@ -224,7 +224,7 @@ function OutputStream(options) { current_pos += str.length; last = str; OUTPUT += str; - }; + } var space = options.beautify ? function() { print(" "); @@ -260,11 +260,11 @@ function OutputStream(options) { function force_semicolon() { might_need_semicolon = false; print(";"); - }; + } function next_indent() { return indentation + options.indent_level; - }; + } function with_block(cont) { var ret; @@ -276,7 +276,7 @@ function OutputStream(options) { indent(); print("}"); return ret; - }; + } function with_parens(cont) { print("("); @@ -285,7 +285,7 @@ function OutputStream(options) { var ret = cont(); print(")"); return ret; - }; + } function with_square(cont) { print("["); @@ -293,17 +293,17 @@ function OutputStream(options) { var ret = cont(); print("]"); return ret; - }; + } function comma() { print(","); space(); - }; + } function colon() { print(":"); if (options.space_colon) space(); - }; + } var add_mapping = options.source_map ? function(token, name) { try { @@ -327,7 +327,7 @@ function OutputStream(options) { function get() { return OUTPUT; - }; + } if (options.preamble) { print(options.preamble.replace(/\r\n?|[\n\u2028\u2029]|\s*$/g, "\n")); @@ -370,7 +370,7 @@ function OutputStream(options) { } }; -}; +} /* -----[ code generators ]----- */ @@ -380,7 +380,7 @@ function OutputStream(options) { function DEFPRINT(nodetype, generator) { nodetype.DEFMETHOD("_codegen", generator); - }; + } var use_asm = false; @@ -492,7 +492,7 @@ function OutputStream(options) { } else { nodetype.DEFMETHOD("needs_parens", func); } - }; + } PARENS(AST_Node, function(){ return false; @@ -666,7 +666,7 @@ function OutputStream(options) { } } }); - }; + } AST_StatementWithBody.DEFMETHOD("_do_print_body", function(output){ force_statement(this.body, output); @@ -694,7 +694,7 @@ function OutputStream(options) { display_body(body, false, output); }); else output.print("{}"); - }; + } DEFPRINT(AST_BlockStatement, function(self, output){ print_bracketed(self.body, output); }); @@ -927,7 +927,7 @@ function OutputStream(options) { else break; } force_statement(self.body, output); - }; + } DEFPRINT(AST_If, function(self, output){ output.print("if"); output.space(); @@ -1052,7 +1052,7 @@ function OutputStream(options) { if (ex !== output) throw ex; node.print(output, true); } - }; + } DEFPRINT(AST_VarDef, function(self, output){ self.name.print(output); @@ -1370,7 +1370,7 @@ function OutputStream(options) { 0x2028 , // unicode "line separator" 0x2029 , // unicode "paragraph separator" ].indexOf(code) < 0; - }; + } DEFPRINT(AST_RegExp, function(self, output){ var str = self.getValue().toString(); @@ -1407,7 +1407,7 @@ function OutputStream(options) { else stat.print(output); } - }; + } // return true if the node at the top of the stack (that means the // innermost node in the current output) is lexically the first in @@ -1431,12 +1431,12 @@ function OutputStream(options) { return false; } } - }; + } // self should be AST_New. decide if we want to show parens or not. function no_constructor_parens(self, output) { return self.args.length == 0 && !output.option("beautify"); - }; + } function best_of(a) { var best = a[0], len = best.length; @@ -1447,7 +1447,7 @@ function OutputStream(options) { } } return best; - }; + } function make_num(num) { var str = num.toString(10), a = [ str.replace(/^0\./, ".").replace('e+', 'e') ], m; @@ -1467,7 +1467,7 @@ function OutputStream(options) { str.substr(str.indexOf("."))); } return best_of(a); - }; + } function make_block(stmt, output) { if (stmt instanceof AST_BlockStatement) { @@ -1479,7 +1479,7 @@ function OutputStream(options) { stmt.print(output); output.newline(); }); - }; + } /* -----[ source map generators ]----- */ @@ -1487,7 +1487,7 @@ function OutputStream(options) { nodetype.DEFMETHOD("add_source_map", function(stream){ generator(this, stream); }); - }; + } // We could easily add info for ALL nodes, but it seems to me that // would be quite wasteful, hence this noop in the base class. @@ -1495,7 +1495,7 @@ function OutputStream(options) { function basic_sourcemap_gen(self, output) { output.add_mapping(self.start); - }; + } // XXX: I'm not exactly sure if we need it for all of these nodes, // or if we should add even more. diff --git a/lib/parse.js b/lib/parse.js index 8c8d19dd..20dc718c 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -133,15 +133,15 @@ function is_letter(code) { return (code >= 97 && code <= 122) || (code >= 65 && code <= 90) || (code >= 0xaa && UNICODE.letter.test(String.fromCharCode(code))); -}; +} function is_digit(code) { return code >= 48 && code <= 57; -}; +} function is_alphanumeric_char(code) { return is_digit(code) || is_letter(code); -}; +} function is_unicode_digit(code) { return UNICODE.digit.test(String.fromCharCode(code)); @@ -149,19 +149,19 @@ function is_unicode_digit(code) { function is_unicode_combining_mark(ch) { return UNICODE.non_spacing_mark.test(ch) || UNICODE.space_combining_mark.test(ch); -}; +} function is_unicode_connector_punctuation(ch) { return UNICODE.connector_punctuation.test(ch); -}; +} function is_identifier(name) { return !RESERVED_WORDS(name) && /^[a-z_$][a-z0-9_$]*$/i.test(name); -}; +} function is_identifier_start(code) { return code == 36 || code == 95 || is_letter(code); -}; +} function is_identifier_char(ch) { var code = ch.charCodeAt(0); @@ -173,11 +173,11 @@ function is_identifier_char(ch) { || is_unicode_connector_punctuation(ch) || is_unicode_digit(code) ; -}; +} function is_identifier_string(str){ return /^[a-z_$][a-z0-9_$]*$/i.test(str); -}; +} function parse_js_number(num) { if (RE_HEX_NUMBER.test(num)) { @@ -194,7 +194,7 @@ function parse_js_number(num) { var val = parseFloat(num); if (val == num) return val; } -}; +} function JS_Parse_Error(message, filename, line, col, pos) { this.message = message; @@ -203,7 +203,7 @@ function JS_Parse_Error(message, filename, line, col, pos) { this.col = col; this.pos = pos; this.stack = new Error().stack; -}; +} JS_Parse_Error.prototype.toString = function() { return this.message + " (line: " + this.line + ", col: " + this.col + ", pos: " + this.pos + ")" + "\n\n" + this.stack; @@ -211,11 +211,11 @@ JS_Parse_Error.prototype.toString = function() { function js_error(message, filename, line, col, pos) { throw new JS_Parse_Error(message, filename, line, col, pos); -}; +} function is_token(token, type, val) { return token.type == type && (val == null || token.value == val); -}; +} var EX_EOF = {}; @@ -235,7 +235,7 @@ function tokenizer($TEXT, filename, html5_comments, shebang) { comments_before : [] }; - function peek() { return S.text.charAt(S.pos); }; + function peek() { return S.text.charAt(S.pos); } function next(signal_eof, in_string) { var ch = S.text.charAt(S.pos++); @@ -254,27 +254,27 @@ function tokenizer($TEXT, filename, html5_comments, shebang) { ++S.col; } return ch; - }; + } function forward(i) { while (i-- > 0) next(); - }; + } function looking_at(str) { return S.text.substr(S.pos, str.length) == str; - }; + } function find(what, signal_eof) { var pos = S.text.indexOf(what, S.pos); if (signal_eof && pos == -1) throw EX_EOF; return pos; - }; + } function start_token() { S.tokline = S.line; S.tokcol = S.col; S.tokpos = S.pos; - }; + } var prev_was_dot = false; function token(type, value, is_comment) { @@ -307,24 +307,24 @@ function tokenizer($TEXT, filename, html5_comments, shebang) { } S.newline_before = false; return new AST_Token(ret); - }; + } function skip_whitespace() { var ch; while (WHITESPACE_CHARS(ch = peek()) || ch == "\u2028" || ch == "\u2029") next(); - }; + } function read_while(pred) { var ret = "", ch, i = 0; while ((ch = peek()) && pred(ch, i++)) ret += next(); return ret; - }; + } function parse_error(err) { js_error(err, filename, S.tokline, S.tokcol, S.tokpos); - }; + } function read_num(prefix) { var has_e = false, after_e = false, has_x = false, has_dot = prefix == "."; @@ -351,7 +351,7 @@ function tokenizer($TEXT, filename, html5_comments, shebang) { } else { parse_error("Invalid syntax: " + num); } - }; + } function read_escaped_char(in_string) { var ch = next(true, in_string); @@ -373,7 +373,7 @@ function tokenizer($TEXT, filename, html5_comments, shebang) { } } return ch; - }; + } function hex_bytes(n) { var num = 0; @@ -384,7 +384,7 @@ function tokenizer($TEXT, filename, html5_comments, shebang) { num = (num << 4) | digit; } return num; - }; + } var read_string = with_eof_error("Unterminated string constant", function(quote_char){ var quote = next(), ret = ""; @@ -431,7 +431,7 @@ function tokenizer($TEXT, filename, html5_comments, shebang) { S.comments_before.push(token(type, ret, true)); S.regex_allowed = regex_allowed; return next_token(); - }; + } var skip_multiline_comment = with_eof_error("Unterminated multiline comment", function(){ var regex_allowed = S.regex_allowed; @@ -472,7 +472,7 @@ function tokenizer($TEXT, filename, html5_comments, shebang) { name = "\\u" + "0000".substr(hex.length) + hex + name.slice(1); } return name; - }; + } var read_regexp = with_eof_error("Unterminated regular expression", function(regexp){ var prev_backslash = false, ch, in_class = false; @@ -510,9 +510,9 @@ function tokenizer($TEXT, filename, html5_comments, shebang) { } else { return op; } - }; + } return token("operator", grow(prefix || next())); - }; + } function handle_slash() { next(); @@ -525,7 +525,7 @@ function tokenizer($TEXT, filename, html5_comments, shebang) { return skip_multiline_comment(); } return S.regex_allowed ? read_regexp("") : read_operator("/"); - }; + } function handle_eq_sign() { next(); @@ -535,7 +535,7 @@ function tokenizer($TEXT, filename, html5_comments, shebang) { } else { return read_operator("="); } - }; + } function handle_dot() { next(); @@ -549,7 +549,7 @@ function tokenizer($TEXT, filename, html5_comments, shebang) { } return token("punc", "."); - }; + } function read_word() { var word = read_name(); @@ -558,7 +558,7 @@ function tokenizer($TEXT, filename, html5_comments, shebang) { : !KEYWORDS(word) ? token("name", word) : OPERATORS(word) ? token("operator", word) : token("keyword", word); - }; + } function with_eof_error(eof_error, cont) { return function(x) { @@ -569,7 +569,7 @@ function tokenizer($TEXT, filename, html5_comments, shebang) { else throw ex; } }; - }; + } function next_token(force_regexp) { if (force_regexp != null) @@ -607,7 +607,7 @@ function tokenizer($TEXT, filename, html5_comments, shebang) { } } parse_error("Unexpected character '" + ch + "'"); - }; + } next_token.next = next; next_token.peek = peek; @@ -619,7 +619,7 @@ function tokenizer($TEXT, filename, html5_comments, shebang) { return next_token; -}; +} /* -----[ Parser (constants) ]----- */ @@ -699,9 +699,9 @@ function parse($TEXT, options) { function is(type, value) { return is_token(S.token, type, value); - }; + } - function peek() { return S.peeked || (S.peeked = S.input()); }; + function peek() { return S.peeked || (S.peeked = S.input()); } function next() { S.prev = S.token; @@ -715,11 +715,11 @@ function parse($TEXT, options) { S.token.type == "string" || is("punc", ";") ); return S.token; - }; + } function prev() { return S.prev; - }; + } function croak(msg, line, col, pos) { var ctx = S.input.context(); @@ -728,44 +728,44 @@ function parse($TEXT, options) { line != null ? line : ctx.tokline, col != null ? col : ctx.tokcol, pos != null ? pos : ctx.tokpos); - }; + } function token_error(token, msg) { croak(msg, token.line, token.col); - }; + } function unexpected(token) { if (token == null) token = S.token; token_error(token, "Unexpected token: " + token.type + " (" + token.value + ")"); - }; + } function expect_token(type, val) { if (is(type, val)) { return next(); } token_error(S.token, "Unexpected token " + S.token.type + " «" + S.token.value + "»" + ", expected " + type + " «" + val + "»"); - }; + } - function expect(punc) { return expect_token("punc", punc); }; + function expect(punc) { return expect_token("punc", punc); } function can_insert_semicolon() { return !options.strict && ( S.token.nlb || is("eof") || is("punc", "}") ); - }; + } function semicolon(optional) { if (is("punc", ";")) next(); else if (!optional && !can_insert_semicolon()) unexpected(); - }; + } function parenthesised() { expect("("); var exp = expression(true); expect(")"); return exp; - }; + } function embed_tokens(parser) { return function() { @@ -776,14 +776,14 @@ function parse($TEXT, options) { expr.end = end; return expr; }; - }; + } function handle_regexp() { if (is("operator", "/") || is("operator", "/=")) { S.peeked = null; S.token = S.input(S.token.value.substr(1)); // force regexp } - }; + } var statement = embed_tokens(function() { var tmp; @@ -941,11 +941,11 @@ function parse($TEXT, options) { }); } return new AST_LabeledStatement({ body: stat, label: label }); - }; + } function simple_statement(tmp) { return new AST_SimpleStatement({ body: (tmp = expression(true), semicolon(), tmp) }); - }; + } function break_cont(type) { var label = null, ldef; @@ -964,7 +964,7 @@ function parse($TEXT, options) { var stat = new type({ label: label }); if (ldef) ldef.references.push(stat); return stat; - }; + } function for_() { expect("("); @@ -989,7 +989,7 @@ function parse($TEXT, options) { } } return regular_for(init); - }; + } function regular_for(init) { expect(";"); @@ -1003,7 +1003,7 @@ function parse($TEXT, options) { step : step, body : in_loop(statement) }); - }; + } function for_of(init) { var lhs = init instanceof AST_Var ? init.definitions[0].name : null; @@ -1015,7 +1015,7 @@ function parse($TEXT, options) { object : obj, body : in_loop(statement) }); - }; + } function for_in(init) { var lhs = init instanceof AST_Var ? init.definitions[0].name : null; @@ -1027,7 +1027,7 @@ function parse($TEXT, options) { object : obj, body : in_loop(statement) }); - }; + } var arrow_function = function(args) { expect_token("arrow", "=>"); @@ -1121,7 +1121,7 @@ function parse($TEXT, options) { body : body, alternative : belse }); - }; + } function block_() { expect("{"); @@ -1132,7 +1132,7 @@ function parse($TEXT, options) { } next(); return a; - }; + } function switch_body_() { expect("{"); @@ -1167,7 +1167,7 @@ function parse($TEXT, options) { if (branch) branch.end = prev(); next(); return a; - }; + } function try_() { var body = block_(), bcatch = null, bfinally = null; @@ -1200,7 +1200,7 @@ function parse($TEXT, options) { bcatch : bcatch, bfinally : bfinally }); - }; + } function vardefs(no_in, in_const) { var a = []; @@ -1228,7 +1228,7 @@ function parse($TEXT, options) { next(); } return a; - }; + } var destructuring_ = embed_tokens(function (sym_type) { var is_array = is("punc", "["); @@ -1359,7 +1359,7 @@ function parse($TEXT, options) { } next(); return ret; - }; + } var expr_atom = function(allow_calls) { if (is("operator", "new")) { @@ -1450,7 +1450,7 @@ function parse($TEXT, options) { } next(); return a; - }; + } var array_ = embed_tokens(function() { expect("["); @@ -1486,7 +1486,7 @@ function parse($TEXT, options) { })); continue; } - + if (is("operator", "=")) { next(); a.push(new AST_Assign({ @@ -1622,7 +1622,7 @@ function parse($TEXT, options) { default: unexpected(); } - }; + } function as_name() { var tmp = S.token; @@ -1636,7 +1636,7 @@ function parse($TEXT, options) { default: unexpected(); } - }; + } function _make_symbol(type) { var name = S.token.value; @@ -1647,7 +1647,7 @@ function parse($TEXT, options) { start : S.token, end : S.token }); - }; + } function as_symbol(type, noerror) { if (!is("name")) { @@ -1657,7 +1657,7 @@ function parse($TEXT, options) { var sym = _make_symbol(type); next(); return sym; - }; + } var subscripts = function(expr, allow_calls) { var start = expr.start; @@ -1736,7 +1736,7 @@ function parse($TEXT, options) { if ((op == "++" || op == "--") && !is_assignable(expr)) croak("Invalid use of " + op + " operator"); return new ctor({ operator: op, expression: expr }); - }; + } var expr_op = function(left, min_prec, no_in) { var op = is("operator") ? S.token.value : null; @@ -1758,7 +1758,7 @@ function parse($TEXT, options) { function expr_ops(no_in) { return expr_op(maybe_unary(true), 0, no_in); - }; + } var maybe_conditional = function(no_in) { var start = S.token; @@ -1783,7 +1783,7 @@ function parse($TEXT, options) { if (expr instanceof AST_This) return false; if (expr instanceof AST_Super) return false; return (expr instanceof AST_PropAccess || expr instanceof AST_Symbol); - }; + } // In ES6, AssignmentExpression can also be an ArrowFunction var maybe_assign = function(no_in) { @@ -1843,7 +1843,7 @@ function parse($TEXT, options) { var ret = cont(); --S.in_loop; return ret; - }; + } if (options.expression) { return expression(true); @@ -1865,4 +1865,4 @@ function parse($TEXT, options) { return toplevel; })(); -}; +} diff --git a/lib/scope.js b/lib/scope.js index ac58ad80..6330cb68 100644 --- a/lib/scope.js +++ b/lib/scope.js @@ -54,7 +54,7 @@ function SymbolDef(scope, index, orig) { this.undeclared = false; this.constant = false; this.index = index; -}; +} SymbolDef.prototype = { unmangleable: function(options) { @@ -567,7 +567,7 @@ var base54 = (function() { base = 64; } while (num > 0); return ret; - }; + } return base54; })(); diff --git a/lib/sourcemap.js b/lib/sourcemap.js index a67011f0..30cc3008 100644 --- a/lib/sourcemap.js +++ b/lib/sourcemap.js @@ -89,4 +89,4 @@ function SourceMap(options) { get : function() { return generator }, toString : function() { return JSON.stringify(generator.toJSON()); } }; -}; +} diff --git a/lib/transform.js b/lib/transform.js index 2cea8705..4d36df24 100644 --- a/lib/transform.js +++ b/lib/transform.js @@ -73,13 +73,13 @@ TreeTransformer.prototype = new TreeWalker; tw.pop(this); return x; }); - }; + } function do_list(list, tw) { return MAP(list, function(node){ return node.transform(tw, true); }); - }; + } _(AST_Node, noop); diff --git a/lib/utils.js b/lib/utils.js index 4612a322..1a10b35a 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -48,29 +48,29 @@ function array_to_hash(a) { for (var i = 0; i < a.length; ++i) ret[a[i]] = true; return ret; -}; +} function slice(a, start) { return Array.prototype.slice.call(a, start || 0); -}; +} function characters(str) { return str.split(""); -}; +} function member(name, array) { for (var i = array.length; --i >= 0;) if (array[i] == name) return true; return false; -}; +} function find_if(func, array) { for (var i = 0, n = array.length; i < n; ++i) { if (func(array[i])) return array[i]; } -}; +} function repeat_string(str, i) { if (i <= 0) return ""; @@ -79,13 +79,13 @@ function repeat_string(str, i) { d += d; if (i & 1) d += str; return d; -}; +} function DefaultsError(msg, defs) { Error.call(this, msg); this.msg = msg; this.defs = defs; -}; +} DefaultsError.prototype = Object.create(Error.prototype); DefaultsError.prototype.constructor = DefaultsError; @@ -103,7 +103,7 @@ function defaults(args, defs, croak) { ret[i] = (args && args.hasOwnProperty(i)) ? args[i] : defs[i]; } return ret; -}; +} function merge(obj, ext) { var count = 0; @@ -112,9 +112,9 @@ function merge(obj, ext) { count++; } return count; -}; +} -function noop() {}; +function noop() {} var MAP = (function(){ function MAP(a, f, backwards) { @@ -139,7 +139,7 @@ var MAP = (function(){ } } return is_last; - }; + } if (a instanceof Array) { if (backwards) { for (i = a.length; --i >= 0;) if (doit()) break; @@ -153,33 +153,33 @@ var MAP = (function(){ for (i in a) if (a.hasOwnProperty(i)) if (doit()) break; } return top.concat(ret); - }; + } MAP.at_top = function(val) { return new AtTop(val) }; MAP.splice = function(val) { return new Splice(val) }; MAP.last = function(val) { return new Last(val) }; var skip = MAP.skip = {}; - function AtTop(val) { this.v = val }; - function Splice(val) { this.v = val }; - function Last(val) { this.v = val }; + function AtTop(val) { this.v = val } + function Splice(val) { this.v = val } + function Last(val) { this.v = val } return MAP; })(); function push_uniq(array, el) { if (array.indexOf(el) < 0) array.push(el); -}; +} function string_template(text, props) { return text.replace(/\{(.+?)\}/g, function(str, p){ return props[p]; }); -}; +} function remove(array, el) { for (var i = array.length; --i >= 0;) { if (array[i] === el) array.splice(i, 1); } -}; +} function mergeSort(array, cmp) { if (array.length < 2) return array.slice(); @@ -193,7 +193,7 @@ function mergeSort(array, cmp) { if (ai < a.length) r.push.apply(r, a.slice(ai)); if (bi < b.length) r.push.apply(r, b.slice(bi)); return r; - }; + } function _ms(a) { if (a.length <= 1) return a; @@ -201,21 +201,21 @@ function mergeSort(array, cmp) { left = _ms(left); right = _ms(right); return merge(left, right); - }; + } return _ms(array); -}; +} function set_difference(a, b) { return a.filter(function(el){ return b.indexOf(el) < 0; }); -}; +} function set_intersection(a, b) { return a.filter(function(el){ return b.indexOf(el) >= 0; }); -}; +} // this function is taken from Acorn [1], written by Marijn Haverbeke // [1] https://github.com/marijnh/acorn @@ -252,19 +252,19 @@ function makePredicate(words) { compareTo(words); } return new Function("str", f); -}; +} function all(array, predicate) { for (var i = array.length; --i >= 0;) if (!predicate(array[i])) return false; return true; -}; +} function Dictionary() { this._values = Object.create(null); this._size = 0; -}; +} Dictionary.prototype = { set: function(key, val) { if (!this.has(key)) ++this._size; diff --git a/test/mozilla-ast.js b/test/mozilla-ast.js index b5c6c6ed..a888d94c 100644 --- a/test/mozilla-ast.js +++ b/test/mozilla-ast.js @@ -62,7 +62,7 @@ module.exports = function(options) { var ast1 = normalizeInput(esfuzz.generate({ maxDepth: options.maxDepth })); - + var ast2 = UglifyJS .AST_Node diff --git a/test/parser.js b/test/parser.js index a84c2df9..d9db0c28 100644 --- a/test/parser.js +++ b/test/parser.js @@ -17,13 +17,13 @@ module.exports = function () { // Destructurings as arguments var destr_fun1 = UglifyJS.parse('(function ({a, b}) {})').body[0].body; var destr_fun2 = UglifyJS.parse('(function ([a, [b]]) {})').body[0].body; - + ok.equal(destr_fun1.argnames.length, 1); ok.equal(destr_fun2.argnames.length, 1); var destr_fun1 = UglifyJS.parse('({a, b}) => null').body[0].body; var destr_fun2 = UglifyJS.parse('([a, [b]]) => null').body[0].body; - + ok.equal(destr_fun1.argnames.length, 1); ok.equal(destr_fun2.argnames.length, 1); @@ -124,4 +124,3 @@ module.exports = function () { if (module.parent === null) { module.exports(); } - diff --git a/test/run-tests.js b/test/run-tests.js index c1530109..9b1da088 100755 --- a/test/run-tests.js +++ b/test/run-tests.js @@ -195,7 +195,7 @@ function parse_test(file) { }); block.walk(tw); return test; - }; + } } function make_code(ast, options) { diff --git a/tools/node.js b/tools/node.js index f6048661..9545ba06 100644 --- a/tools/node.js +++ b/tools/node.js @@ -170,7 +170,7 @@ exports.describe_ast = function() { }); }); } - }; + } doitem(UglifyJS.AST_Node); return out + ""; };