Merge branch 'master' into harmony-v2.8.15
This commit is contained in:
@@ -132,6 +132,11 @@ merge(Compressor.prototype, {
|
||||
}
|
||||
return node;
|
||||
},
|
||||
info: function() {
|
||||
if (this.options.warnings == "verbose") {
|
||||
AST_Node.warn.apply(AST_Node, arguments);
|
||||
}
|
||||
},
|
||||
warn: function(text, props) {
|
||||
if (this.options.warnings) {
|
||||
// only emit unique warnings
|
||||
@@ -629,12 +634,24 @@ merge(Compressor.prototype, {
|
||||
|| node instanceof AST_IterationStatement
|
||||
|| (parent instanceof AST_If && node !== parent.condition)
|
||||
|| (parent instanceof AST_Conditional && node !== parent.condition)
|
||||
|| (node instanceof AST_SymbolRef
|
||||
&& !are_references_in_scope(node.definition(), self))
|
||||
|| (parent instanceof AST_Binary
|
||||
&& (parent.operator == "&&" || parent.operator == "||")
|
||||
&& node === parent.right)
|
||||
|| (parent instanceof AST_Switch && node !== parent.expression)) {
|
||||
return side_effects_encountered = unwind = true, node;
|
||||
}
|
||||
function are_references_in_scope(def, scope) {
|
||||
if (def.orig.length === 1
|
||||
&& def.orig[0] instanceof AST_SymbolDefun) return true;
|
||||
if (def.scope.get_defun_scope() !== scope) return false;
|
||||
var refs = def.references;
|
||||
for (var i = 0, len = refs.length; i < len; i++) {
|
||||
if (refs[i].scope.get_defun_scope() !== scope) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
},
|
||||
function postorder(node) {
|
||||
if (unwind) return node;
|
||||
@@ -679,7 +696,7 @@ merge(Compressor.prototype, {
|
||||
// Further optimize statement after substitution.
|
||||
stat.reset_opt_flags(compressor);
|
||||
|
||||
compressor.warn("Collapsing " + (is_constant ? "constant" : "variable") +
|
||||
compressor.info("Collapsing " + (is_constant ? "constant" : "variable") +
|
||||
" " + var_name + " [{file}:{line},{col}]", node.start);
|
||||
CHANGED = true;
|
||||
return value;
|
||||
@@ -1933,7 +1950,7 @@ merge(Compressor.prototype, {
|
||||
sym.__unused = true;
|
||||
if (trim) {
|
||||
a.pop();
|
||||
compressor.warn("Dropping unused function argument {name} [{file}:{line},{col}]", {
|
||||
compressor[sym.unreferenced() ? "warn" : "info"]("Dropping unused function argument {name} [{file}:{line},{col}]", {
|
||||
name : sym.name,
|
||||
file : sym.start.file,
|
||||
line : sym.start.line,
|
||||
@@ -1949,7 +1966,7 @@ merge(Compressor.prototype, {
|
||||
if ((node instanceof AST_Defun || node instanceof AST_DefClass) && node !== self) {
|
||||
var keep = (node.name.definition().id in in_use_ids) || !drop_funcs && node.name.definition().global;
|
||||
if (!keep) {
|
||||
compressor.warn("Dropping unused function {name} [{file}:{line},{col}]", {
|
||||
compressor[node.name.unreferenced() ? "warn" : "info"]("Dropping unused function {name} [{file}:{line},{col}]", {
|
||||
name : node.name.name,
|
||||
file : node.name.start.file,
|
||||
line : node.name.start.line,
|
||||
@@ -1976,7 +1993,7 @@ merge(Compressor.prototype, {
|
||||
compressor.warn("Side effects in initialization of unused variable {name} [{file}:{line},{col}]", w);
|
||||
return true;
|
||||
}
|
||||
compressor.warn("Dropping unused variable {name} [{file}:{line},{col}]", w);
|
||||
compressor[def.name.unreferenced() ? "warn" : "info"]("Dropping unused variable {name} [{file}:{line},{col}]", w);
|
||||
return false;
|
||||
});
|
||||
// place uninitialized names at the start
|
||||
|
||||
99
lib/parse.js
99
lib/parse.js
@@ -2467,12 +2467,52 @@ function parse($TEXT, options) {
|
||||
};
|
||||
|
||||
function is_assignable(expr) {
|
||||
if (!options.strict) return true;
|
||||
if (expr instanceof AST_This) return false;
|
||||
if (expr instanceof AST_Super) return false;
|
||||
return (expr instanceof AST_PropAccess || expr instanceof AST_Symbol);
|
||||
return expr instanceof AST_PropAccess || expr instanceof AST_SymbolRef;
|
||||
};
|
||||
|
||||
function to_destructuring(node) {
|
||||
if (node instanceof AST_Object) {
|
||||
node = new AST_Destructuring({
|
||||
start: node.start,
|
||||
names: node.properties.map(to_destructuring),
|
||||
is_array: false,
|
||||
end: node.end
|
||||
});
|
||||
} else if (node instanceof AST_Array) {
|
||||
var names = [];
|
||||
|
||||
for (var i = 0; i < node.elements.length; i++) {
|
||||
// Only allow expansion as last element
|
||||
if (node.elements[i] instanceof AST_Expansion) {
|
||||
if (i + 1 !== node.elements.length) {
|
||||
token_error(node.elements[i].start, "Spread must the be last element in destructuring array");
|
||||
}
|
||||
node.elements[i].expression = to_destructuring(node.elements[i].expression);
|
||||
}
|
||||
|
||||
names.push(to_destructuring(node.elements[i]));
|
||||
}
|
||||
|
||||
node = new AST_Destructuring({
|
||||
start: node.start,
|
||||
names: names,
|
||||
is_array: true,
|
||||
end: node.end
|
||||
});
|
||||
} else if (node instanceof AST_ObjectProperty) {
|
||||
node.value = to_destructuring(node.value);
|
||||
} else if (node instanceof AST_Assign) {
|
||||
node = new AST_DefaultAssign({
|
||||
start: node.start,
|
||||
left: node.left,
|
||||
operator: "=",
|
||||
right: node.right,
|
||||
end: node.end
|
||||
});
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
// In ES6, AssignmentExpression can also be an ArrowFunction
|
||||
var maybe_assign = function(no_in) {
|
||||
var start = S.token;
|
||||
@@ -2506,56 +2546,7 @@ function parse($TEXT, options) {
|
||||
var val = S.token.value;
|
||||
|
||||
if (is("operator") && ASSIGNMENT(val)) {
|
||||
if (is_assignable(left)) {
|
||||
|
||||
var walk = function(node) {
|
||||
var newNode;
|
||||
if (node instanceof AST_Object) {
|
||||
newNode = new AST_Destructuring({
|
||||
start: node.start,
|
||||
names: node.properties.map(walk),
|
||||
is_array: false,
|
||||
end: node.end
|
||||
});
|
||||
node = newNode;
|
||||
} else if (node instanceof AST_Array) {
|
||||
var names = [];
|
||||
|
||||
for (var i = 0; i < node.elements.length; i++) {
|
||||
// Only allow expansion as last element
|
||||
if (node.elements[i] instanceof AST_Expansion) {
|
||||
if (i + 1 !== node.elements.length) {
|
||||
token_error(node.elements[i].start, "Spread must the be last element in destructuring array");
|
||||
}
|
||||
node.elements[i].expression = walk(node.elements[i].expression);
|
||||
}
|
||||
|
||||
names.push(walk(node.elements[i]));
|
||||
}
|
||||
|
||||
newNode = new AST_Destructuring({
|
||||
start: node.start,
|
||||
names: names,
|
||||
is_array: true,
|
||||
end: node.end
|
||||
});
|
||||
node = newNode;
|
||||
} else if (node instanceof AST_ObjectProperty) {
|
||||
node.value = walk(node.value);
|
||||
} else if (node instanceof AST_Assign) {
|
||||
node = new AST_DefaultAssign({
|
||||
start: node.start,
|
||||
left: node.left,
|
||||
operator: "=",
|
||||
right: node.right,
|
||||
end: node.end
|
||||
});
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
left = walk(left);
|
||||
|
||||
if (is_assignable(left) || (left = to_destructuring(left)) instanceof AST_Destructuring) {
|
||||
next();
|
||||
return new AST_Assign({
|
||||
start : start,
|
||||
|
||||
Reference in New Issue
Block a user