fix evaluate on object getter & setter (#1515)
This commit is contained in:
@@ -1148,11 +1148,14 @@ merge(Compressor.prototype, {
|
|||||||
def(AST_Statement, function(){
|
def(AST_Statement, function(){
|
||||||
throw new Error(string_template("Cannot evaluate a statement [{file}:{line},{col}]", this.start));
|
throw new Error(string_template("Cannot evaluate a statement [{file}:{line},{col}]", this.start));
|
||||||
});
|
});
|
||||||
|
// XXX: AST_Accessor and AST_Function both inherit from AST_Scope,
|
||||||
|
// which itself inherits from AST_Statement; however, they aren't
|
||||||
|
// really statements. This could bite in other places too. :-(
|
||||||
|
// Wish JS had multiple inheritance.
|
||||||
|
def(AST_Accessor, function(){
|
||||||
|
throw def;
|
||||||
|
});
|
||||||
def(AST_Function, function(){
|
def(AST_Function, function(){
|
||||||
// XXX: AST_Function inherits from AST_Scope, which itself
|
|
||||||
// inherits from AST_Statement; however, an AST_Function
|
|
||||||
// isn't really a statement. This could byte in other
|
|
||||||
// places too. :-( Wish JS had multiple inheritance.
|
|
||||||
throw def;
|
throw def;
|
||||||
});
|
});
|
||||||
function ev(node, compressor) {
|
function ev(node, compressor) {
|
||||||
@@ -1180,7 +1183,9 @@ merge(Compressor.prototype, {
|
|||||||
for (var i = 0, len = this.properties.length; i < len; i++) {
|
for (var i = 0, len = this.properties.length; i < len; i++) {
|
||||||
var prop = this.properties[i];
|
var prop = this.properties[i];
|
||||||
var key = prop.key;
|
var key = prop.key;
|
||||||
if (key instanceof AST_Node) {
|
if (key instanceof AST_Symbol) {
|
||||||
|
key = key.name;
|
||||||
|
} else if (key instanceof AST_Node) {
|
||||||
key = ev(key, compressor);
|
key = ev(key, compressor);
|
||||||
}
|
}
|
||||||
if (typeof Object.prototype[key] === 'function') {
|
if (typeof Object.prototype[key] === 'function') {
|
||||||
|
|||||||
@@ -337,6 +337,32 @@ unsafe_object_repeated: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsafe_object_accessor: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
unsafe: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f() {
|
||||||
|
var a = {
|
||||||
|
get b() {},
|
||||||
|
set b() {}
|
||||||
|
};
|
||||||
|
return {a:a};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f() {
|
||||||
|
var a = {
|
||||||
|
get b() {},
|
||||||
|
set b() {}
|
||||||
|
};
|
||||||
|
return {a:a};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
unsafe_function: {
|
unsafe_function: {
|
||||||
options = {
|
options = {
|
||||||
evaluate : true,
|
evaluate : true,
|
||||||
|
|||||||
Reference in New Issue
Block a user