extend functionality
add tests
This commit is contained in:
parent
f5c6118afd
commit
9ddb75c28b
|
|
@ -333,7 +333,7 @@ merge(Compressor.prototype, {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mark_escaped(d, node, value, 0);
|
mark_escaped(d, node.scope, node, value, 0);
|
||||||
}
|
}
|
||||||
if (node instanceof AST_SymbolCatch) {
|
if (node instanceof AST_SymbolCatch) {
|
||||||
node.definition().fixed = false;
|
node.definition().fixed = false;
|
||||||
|
|
@ -623,11 +623,11 @@ merge(Compressor.prototype, {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function mark_escaped(d, node, value, level) {
|
function mark_escaped(d, scope, node, value, level) {
|
||||||
var parent = tw.parent(level);
|
var parent = tw.parent(level);
|
||||||
if (value) {
|
if (value) {
|
||||||
if (value.is_constant()) return;
|
if (value.is_constant()) return;
|
||||||
if (level > 0 && value.is_constant_expression()) return;
|
if (level > 0 && value.is_constant_expression(scope)) return;
|
||||||
}
|
}
|
||||||
if (parent instanceof AST_Assign && parent.operator == "=" && node === parent.right
|
if (parent instanceof AST_Assign && parent.operator == "=" && node === parent.right
|
||||||
|| parent instanceof AST_Call && node !== parent.expression
|
|| parent instanceof AST_Call && node !== parent.expression
|
||||||
|
|
@ -636,13 +636,13 @@ merge(Compressor.prototype, {
|
||||||
d.escaped = true;
|
d.escaped = true;
|
||||||
return;
|
return;
|
||||||
} else if (parent instanceof AST_Array) {
|
} else if (parent instanceof AST_Array) {
|
||||||
mark_escaped(d, parent, parent, level + 1);
|
mark_escaped(d, scope, parent, parent, level + 1);
|
||||||
} else if (parent instanceof AST_ObjectKeyVal && node === parent.value) {
|
} else if (parent instanceof AST_ObjectKeyVal && node === parent.value) {
|
||||||
var obj = tw.parent(level + 1);
|
var obj = tw.parent(level + 1);
|
||||||
mark_escaped(d, obj, obj, level + 2);
|
mark_escaped(d, scope, obj, obj, level + 2);
|
||||||
} else if (parent instanceof AST_PropAccess && node === parent.expression) {
|
} else if (parent instanceof AST_PropAccess && node === parent.expression) {
|
||||||
value = read_property(value, parent.property);
|
value = read_property(value, parent.property);
|
||||||
mark_escaped(d, parent, value, level + 1);
|
mark_escaped(d, scope, parent, value, level + 1);
|
||||||
if (value) return;
|
if (value) return;
|
||||||
}
|
}
|
||||||
if (level == 0) d.direct_access = true;
|
if (level == 0) d.direct_access = true;
|
||||||
|
|
|
||||||
|
|
@ -523,6 +523,7 @@ issue_2508_1: {
|
||||||
console.log(x);
|
console.log(x);
|
||||||
})([ 1 ]);
|
})([ 1 ]);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_2508_2: {
|
issue_2508_2: {
|
||||||
|
|
@ -547,4 +548,88 @@ issue_2508_2: {
|
||||||
console.log(x);
|
console.log(x);
|
||||||
})({ b: 2 });
|
})({ b: 2 });
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2508_3: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
hoist_props: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var o = {
|
||||||
|
a: [ o ],
|
||||||
|
f: function(x) {
|
||||||
|
console.log(x);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
o.f(o.a);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var o = {
|
||||||
|
a: [ o ],
|
||||||
|
f: function(x) {
|
||||||
|
console.log(x);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
o.f(o.a);
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2508_4: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
hoist_props: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var o = {
|
||||||
|
a: { b: o },
|
||||||
|
f: function(x) {
|
||||||
|
console.log(x);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
o.f(o.a);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var o = {
|
||||||
|
a: { b: o },
|
||||||
|
f: function(x) {
|
||||||
|
console.log(x);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
o.f(o.a);
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2508_5: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
hoist_props: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var o = {
|
||||||
|
f: function(x) {
|
||||||
|
console.log(x);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
o.f(o.f);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var o_f = function(x) {
|
||||||
|
console.log(x);
|
||||||
|
};
|
||||||
|
o_f(o_f);
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user