@@ -227,9 +227,7 @@ Compressor.prototype.exposed = function(def) {
|
||||
Compressor.prototype.compress = function(node) {
|
||||
node = node.resolve_defines(this);
|
||||
node.hoist_exports(this);
|
||||
if (this.option("expression")) {
|
||||
node.process_expression(true);
|
||||
}
|
||||
if (this.option("expression")) node.process_expression(true);
|
||||
var merge_vars = this.options.merge_vars;
|
||||
var passes = +this.options.passes || 1;
|
||||
var min_count = 1 / 0;
|
||||
@@ -261,9 +259,7 @@ Compressor.prototype.compress = function(node) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this.option("expression")) {
|
||||
node.process_expression(false);
|
||||
}
|
||||
if (this.option("expression")) node.process_expression(false);
|
||||
return node;
|
||||
};
|
||||
|
||||
@@ -308,12 +304,19 @@ Compressor.prototype.compress = function(node) {
|
||||
AST_Scope.DEFMETHOD("process_expression", function(insert, transform) {
|
||||
var self = this;
|
||||
var tt = new TreeTransformer(function(node) {
|
||||
if (insert && node instanceof AST_SimpleStatement) {
|
||||
return transform ? transform(node) : make_node(AST_Return, node, { value: node.body });
|
||||
}
|
||||
if (!insert && node instanceof AST_Return) {
|
||||
return transform ? transform(node) : make_node(AST_SimpleStatement, node, {
|
||||
body: node.value || make_node(AST_UnaryPrefix, node, {
|
||||
if (insert) {
|
||||
if (node instanceof AST_Directive) node = make_node(AST_SimpleStatement, node, {
|
||||
body: make_node(AST_String, node, node),
|
||||
});
|
||||
if (node instanceof AST_SimpleStatement) {
|
||||
return transform ? transform(node) : make_node(AST_Return, node, { value: node.body });
|
||||
}
|
||||
} else if (node instanceof AST_Return) {
|
||||
if (transform) return transform(node);
|
||||
var value = node.value;
|
||||
if (value instanceof AST_String) return make_node(AST_Directive, node, value);
|
||||
return make_node(AST_SimpleStatement, node, {
|
||||
body: value || make_node(AST_UnaryPrefix, node, {
|
||||
operator: "void",
|
||||
expression: make_node(AST_Number, node, { value: 0 }),
|
||||
}),
|
||||
@@ -334,9 +337,7 @@ Compressor.prototype.compress = function(node) {
|
||||
}
|
||||
} else if (node instanceof AST_If) {
|
||||
node.body = node.body.transform(tt);
|
||||
if (node.alternative) {
|
||||
node.alternative = node.alternative.transform(tt);
|
||||
}
|
||||
if (node.alternative) node.alternative = node.alternative.transform(tt);
|
||||
} else if (node instanceof AST_With) {
|
||||
node.body = node.body.transform(tt);
|
||||
}
|
||||
|
||||
@@ -129,3 +129,32 @@ valid_after_invalid_2: {
|
||||
}
|
||||
expect_stdout: "undefined"
|
||||
}
|
||||
|
||||
issue_5368_1: {
|
||||
options = {
|
||||
directives: true,
|
||||
expression: true,
|
||||
}
|
||||
input: {
|
||||
"foo";
|
||||
}
|
||||
expect: {
|
||||
"foo";
|
||||
}
|
||||
}
|
||||
|
||||
issue_5368_2: {
|
||||
options = {
|
||||
directives: true,
|
||||
expression: true,
|
||||
}
|
||||
input: {
|
||||
"foo";
|
||||
(function() {
|
||||
"bar";
|
||||
})();
|
||||
}
|
||||
expect: {
|
||||
(function() {})();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user