Do not mangle a name if it is in a destructuring vardef.

This commit is contained in:
Fábio Santos 2015-08-14 02:00:31 +01:00 committed by Burak Can
parent a3a4ae5ef8
commit d757202b74

View File

@ -98,7 +98,7 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){
var defun = null; var defun = null;
var last_var_had_const_pragma = false; var last_var_had_const_pragma = false;
var nesting = 0; var nesting = 0;
var object_destructuring_arg = false; var in_destructuring = null;
var tw = new TreeWalker(function(node, descend){ var tw = new TreeWalker(function(node, descend){
if (options.screw_ie8 && node instanceof AST_Catch) { if (options.screw_ie8 && node instanceof AST_Catch) {
var save_scope = scope; var save_scope = scope;
@ -110,9 +110,9 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){
return true; return true;
} }
if (node instanceof AST_Destructuring && node.is_array === false) { if (node instanceof AST_Destructuring && node.is_array === false) {
object_destructuring_arg = true; // These don't nest in_destructuring = node; // These don't nest
descend(); descend();
object_destructuring_arg = false; in_destructuring = null;
return true; return true;
} }
if (node instanceof AST_Scope) { if (node instanceof AST_Scope) {
@ -151,7 +151,7 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){
node.references = []; node.references = [];
} }
if (node instanceof AST_SymbolFunarg) { if (node instanceof AST_SymbolFunarg) {
node.object_destructuring_arg = object_destructuring_arg; node.object_destructuring_arg = !!in_destructuring;
defun.def_variable(node); defun.def_variable(node);
} }
if (node instanceof AST_SymbolLambda) { if (node instanceof AST_SymbolLambda) {
@ -171,7 +171,8 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){
else if (node instanceof AST_SymbolVar else if (node instanceof AST_SymbolVar
|| node instanceof AST_SymbolConst) { || node instanceof AST_SymbolConst) {
var def = defun.def_variable(node); var def = defun.def_variable(node);
def.constant = node instanceof AST_SymbolConst || last_var_had_const_pragma; def.constant = node instanceof AST_SymbolConst;
def.destructuring = in_destructuring;
def.init = tw.parent().value; def.init = tw.parent().value;
} }
else if (node instanceof AST_SymbolCatch) { else if (node instanceof AST_SymbolCatch) {
@ -458,7 +459,10 @@ AST_Toplevel.DEFMETHOD("mangle_names", function(options){
} }
}); });
this.walk(tw); this.walk(tw);
to_mangle.forEach(function(def){ def.mangle(options) }); to_mangle.forEach(function(def){
if (def.destructuring && !def.destructuring.is_array) return;
def.mangle(options);
});
if (options.cache) { if (options.cache) {
options.cache.cname = this.cname; options.cache.cname = this.cname;