From 7de8daa4b151fc47080d5a5f6329c3f80b9a5e7d Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Wed, 23 Sep 2020 16:06:12 +0100 Subject: minor clean up (#4149) --- lib/parse.js | 15 +++++++++------ lib/scope.js | 12 ++++++------ 2 files changed, 15 insertions(+), 12 deletions(-) (limited to 'lib') diff --git a/lib/parse.js b/lib/parse.js index 3a1f809b..d57baccb 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -44,11 +44,14 @@ "use strict"; -var KEYWORDS = 'break case catch const continue debugger default delete do else finally for function if in instanceof new return switch throw try typeof var void while with'; -var KEYWORDS_ATOM = 'false null true'; -var RESERVED_WORDS = 'abstract boolean byte char class double enum export extends final float goto implements import int interface let long native package private protected public short static super synchronized this throws transient volatile yield' - + " " + KEYWORDS_ATOM + " " + KEYWORDS; -var KEYWORDS_BEFORE_EXPRESSION = 'return new delete throw else case'; +var KEYWORDS = "break case catch const continue debugger default delete do else finally for function if in instanceof new return switch throw try typeof var void while with"; +var KEYWORDS_ATOM = "false null true"; +var RESERVED_WORDS = [ + "abstract boolean byte char class double enum export extends final float goto implements import int interface let long native package private protected public short static super synchronized this throws transient volatile yield", + KEYWORDS_ATOM, + KEYWORDS, +].join(" "); +var KEYWORDS_BEFORE_EXPRESSION = "return new delete throw else case"; KEYWORDS = makePredicate(KEYWORDS); RESERVED_WORDS = makePredicate(RESERVED_WORDS); @@ -438,7 +441,7 @@ function tokenizer($TEXT, filename, html5_comments, shebang) { var skip_multiline_comment = with_eof_error("Unterminated multiline comment", function() { var regex_allowed = S.regex_allowed; var i = find("*/", true); - var text = S.text.substring(S.pos, i).replace(/\r\n|\r|\u2028|\u2029/g, '\n'); + var text = S.text.substring(S.pos, i).replace(/\r\n|\r|\u2028|\u2029/g, "\n"); // update stream position forward(text.length /* doesn't count \r\n as 2 char while S.pos - i does */ + 2); S.comments_before.push(token("comment2", text, true)); diff --git a/lib/scope.js b/lib/scope.js index ec69eb1b..405f563d 100644 --- a/lib/scope.js +++ b/lib/scope.js @@ -335,7 +335,7 @@ AST_Toplevel.DEFMETHOD("resolve", return_this); function names_in_use(scope, options) { var names = scope.names_in_use; if (!names) { - scope.names_in_use = names = Object.create(scope.mangled_names || null); + scope.names_in_use = names = Object.create(null); scope.cname_holes = []; var cache = options.cache && options.cache.props; scope.enclosed.forEach(function(def) { @@ -369,7 +369,7 @@ function next_mangled_name(scope, options, def) { name = base54(holes[i]); if (names[name]) continue; holes.splice(i, 1); - scope.names_in_use[name] = true; + in_use[name] = true; return name; } while (true) { @@ -378,7 +378,7 @@ function next_mangled_name(scope, options, def) { if (!names[name]) break; holes.push(scope.cname); } - scope.names_in_use[name] = true; + in_use[name] = true; return name; } @@ -419,7 +419,7 @@ AST_Toplevel.DEFMETHOD("mangle_names", function(options) { var lname = -1; if (options.cache && options.cache.props) { - var mangled_names = this.mangled_names = Object.create(null); + var mangled_names = names_in_use(this, options); options.cache.props.each(function(mangled_name) { mangled_names[mangled_name] = true; }); @@ -491,7 +491,7 @@ AST_Toplevel.DEFMETHOD("mangle_names", function(options) { AST_Toplevel.DEFMETHOD("find_colliding_names", function(options) { var cache = options.cache && options.cache.props; - var avoid = Object.create(null); + var avoid = Object.create(RESERVED_WORDS); options.reserved.forEach(to_avoid); this.globals.each(add_def); this.walk(new TreeWalker(function(node) { @@ -528,7 +528,7 @@ AST_Toplevel.DEFMETHOD("expand_names", function(options) { var name; do { name = base54(cname++); - } while (avoid[name] || RESERVED_WORDS[name]); + } while (avoid[name]); return name; } -- cgit v1.2.3