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 Richard van Velzen
parent 025d34bfa2
commit e99bc914ca

View File

@@ -96,7 +96,7 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){
var scope = self.parent_scope = null;
var defun = null;
var nesting = 0;
var object_destructuring_arg = false;
var in_destructuring = null;
var tw = new TreeWalker(function(node, descend){
if (options.screw_ie8 && node instanceof AST_Catch) {
var save_scope = scope;
@@ -108,9 +108,9 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){
return true;
}
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();
object_destructuring_arg = false;
in_destructuring = null;
return true;
}
if (node instanceof AST_Scope) {
@@ -137,7 +137,7 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){
node.scope = scope;
}
if (node instanceof AST_SymbolFunarg) {
node.object_destructuring_arg = object_destructuring_arg;
node.object_destructuring_arg = !!in_destructuring;
defun.def_variable(node);
}
if (node instanceof AST_SymbolLambda) {
@@ -155,6 +155,7 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){
|| node instanceof AST_SymbolConst) {
var def = defun.def_variable(node);
def.constant = node instanceof AST_SymbolConst;
def.destructuring = in_destructuring;
def.init = tw.parent().value;
}
else if (node instanceof AST_SymbolCatch) {
@@ -412,7 +413,10 @@ AST_Toplevel.DEFMETHOD("mangle_names", function(options){
}
});
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) {
options.cache.cname = this.cname;