Skip to content

Commit

Permalink
bring back breaking changes
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiosantoscode committed Mar 4, 2020
1 parent ceba645 commit e140ce9
Show file tree
Hide file tree
Showing 8 changed files with 371 additions and 161 deletions.
274 changes: 241 additions & 33 deletions lib/ast.js

Large diffs are not rendered by default.

186 changes: 94 additions & 92 deletions lib/compress/index.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions lib/mozilla-ast.js
Expand Up @@ -646,7 +646,7 @@ import {
return to_moz_scope("Program", M);
});

def_to_moz(AST_Expansion, function To_Moz_Spread(M, parent) {
def_to_moz(AST_Expansion, function To_Moz_Spread(M) {
return {
type: to_moz_in_destructuring() ? "RestElement" : "SpreadElement",
argument: to_moz(M.expression)
Expand Down Expand Up @@ -994,7 +994,7 @@ import {
};
});

def_to_moz(AST_NewTarget, function To_Moz_MetaProperty(M) {
def_to_moz(AST_NewTarget, function To_Moz_MetaProperty() {
return {
type: "MetaProperty",
meta: {
Expand Down Expand Up @@ -1179,7 +1179,7 @@ import {
return ast;
};

function set_moz_loc(mynode, moznode, myparent) {
function set_moz_loc(mynode, moznode) {
var start = mynode.start;
var end = mynode.end;
if (!(start && end)) {
Expand Down
28 changes: 14 additions & 14 deletions lib/output.js
Expand Up @@ -142,6 +142,8 @@ import {
AST_With,
AST_Yield,
TreeWalker,
walk,
walk_abort
} from "./ast.js";
import {
get_full_char_code,
Expand Down Expand Up @@ -994,15 +996,12 @@ function OutputStream(options) {
// parens around it too, otherwise the call will be
// interpreted as passing the arguments to the upper New
// expression.
var parens = false;
this.walk(new TreeWalker(function(node) {
if (parens || node instanceof AST_Scope) return true;
return walk(this, node => {
if (node instanceof AST_Scope) return true;
if (node instanceof AST_Call) {
parens = true;
return true;
return walk_abort; // makes walk() return true.
}
}));
return parens;
});
}
});

Expand Down Expand Up @@ -1678,13 +1677,14 @@ function OutputStream(options) {
var parens = false;
// need to take some precautions here:
// https://github.com/mishoo/UglifyJS2/issues/60
if (noin) node.walk(new TreeWalker(function(node) {
if (parens || node instanceof AST_Scope) return true;
if (node instanceof AST_Binary && node.operator == "in") {
parens = true;
return true;
}
}));
if (noin) {
parens = walk(node, node => {
if (node instanceof AST_Scope) return true;
if (node instanceof AST_Binary && node.operator == "in") {
return walk_abort; // makes walk() return true
}
});
}
node.print(output, parens);
}

Expand Down
6 changes: 1 addition & 5 deletions lib/parse.js
Expand Up @@ -47,7 +47,6 @@
import {
characters,
defaults,
HOP,
makePredicate,
set_annotation,
} from "./utils/index.js";
Expand Down Expand Up @@ -1464,8 +1463,6 @@ function parse($TEXT, options) {
};

var function_ = function(ctor, is_generator_property, is_async, is_export_default) {
var start = S.token;

var in_statement = ctor === AST_Defun;
var is_generator = is("operator", "*");
if (is_generator) {
Expand Down Expand Up @@ -1556,7 +1553,6 @@ function parse($TEXT, options) {
}

function parameters(params) {
var start = S.token;
var used_parameters = track_used_binding_identifiers(true, S.input.has_directive("use strict"));

expect("(");
Expand Down Expand Up @@ -2278,7 +2274,7 @@ function parse($TEXT, options) {
unexpected();
};

function template_string(tagged) {
function template_string() {
var segments = [], start = S.token;

segments.push(new AST_TemplateSegment({
Expand Down
1 change: 0 additions & 1 deletion lib/propmangle.js
Expand Up @@ -51,7 +51,6 @@ import {
import { base54 } from "./scope";
import {
AST_Call,
AST_ClassProperty,
AST_Conditional,
AST_Dot,
AST_ObjectKeyVal,
Expand Down
25 changes: 12 additions & 13 deletions lib/scope.js
Expand Up @@ -46,7 +46,6 @@
import {
defaults,
keep_name,
member,
mergeSort,
push_uniq,
return_false,
Expand Down Expand Up @@ -103,6 +102,7 @@ import {
AST_VarDef,
AST_With,
TreeWalker,
walk
} from "./ast.js";
import {
RESERVED_WORDS,
Expand Down Expand Up @@ -201,13 +201,12 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options) {
});

// pass 1: setup scope chaining and handle definitions
var self = this;
var scope = self.parent_scope = null;
var scope = this.parent_scope = null;
var labels = new Map();
var defun = null;
var in_destructuring = null;
var for_scopes = [];
var tw = new TreeWalker(function(node, descend) {
var tw = new TreeWalker((node, descend) => {
if (node.is_block_scope()) {
const save_scope = scope;
node.block_scope = scope = new AST_Scope(node);
Expand Down Expand Up @@ -358,7 +357,7 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options) {
);
}
});
self.walk(tw);
this.walk(tw);

function mark_export(def, level) {
if (in_destructuring) {
Expand All @@ -377,8 +376,8 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options) {
}

// pass 2: find back references and eval
self.globals = new Map();
var tw = new TreeWalker(function(node, descend) {
this.globals = new Map();
var tw = new TreeWalker(node => {
if (node instanceof AST_LoopControl && node.label) {
node.label.thedef.references.push(node);
return true;
Expand All @@ -393,7 +392,7 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options) {
var sym;
if (tw.parent() instanceof AST_NameMapping && tw.parent(1).module_name
|| !(sym = node.scope.find_variable(name))) {
sym = self.def_global(node);
sym = this.def_global(node);
if (node instanceof AST_SymbolExport) sym.export = MASK_EXPORT_DONT_MANGLE;
} else if (sym.scope instanceof AST_Lambda && name == "arguments") {
sym.scope.uses_arguments = true;
Expand All @@ -417,16 +416,16 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options) {
}
}
});
self.walk(tw);
this.walk(tw);

// pass 3: work around IE8 and Safari catch scope bugs
if (options.ie8 || options.safari10) {
self.walk(new TreeWalker(function(node, descend) {
walk(this, node => {
if (node instanceof AST_SymbolCatch) {
var name = node.name;
var refs = node.thedef.references;
var scope = node.scope.get_defun_scope();
var def = scope.find_variable(name) || self.globals.get(name) || scope.def_variable(node);
var def = scope.find_variable(name) || this.globals.get(name) || scope.def_variable(node);
refs.forEach(function(ref) {
ref.thedef = def;
ref.reference(options);
Expand All @@ -435,7 +434,7 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options) {
node.reference(options);
return true;
}
}));
});
}

// pass 4: add symbol definitions to loop scopes
Expand Down Expand Up @@ -567,7 +566,7 @@ AST_Arrow.DEFMETHOD("init_scope_vars", function() {
this.uses_arguments = false;
});

AST_Symbol.DEFMETHOD("mark_enclosed", function(options) {
AST_Symbol.DEFMETHOD("mark_enclosed", function() {
var def = this.definition();
var s = this.scope;
while (s) {
Expand Down
6 changes: 6 additions & 0 deletions package.json
Expand Up @@ -102,6 +102,12 @@
],
"no-debugger": "error",
"no-undef": "error",
"no-unused-vars": [
"error",
{
"varsIgnorePattern": "^_$"
}
],
"no-tabs": "error",
"semi": [
"error",
Expand Down

0 comments on commit e140ce9

Please sign in to comment.