implement --expression (#5607)
This commit is contained in:
@@ -343,6 +343,35 @@ Compressor.prototype.compress = function(node) {
|
||||
});
|
||||
self.transform(tt);
|
||||
});
|
||||
AST_Toplevel.DEFMETHOD("unwrap_expression", function() {
|
||||
var self = this;
|
||||
switch (self.body.length) {
|
||||
case 0:
|
||||
return make_node(AST_UnaryPrefix, self, {
|
||||
operator: "void",
|
||||
expression: make_node(AST_Number, self, { value: 0 }),
|
||||
});
|
||||
case 1:
|
||||
var stat = self.body[0];
|
||||
if (stat instanceof AST_Directive) return make_node(AST_String, self, stat);
|
||||
if (stat instanceof AST_SimpleStatement) return stat.body;
|
||||
default:
|
||||
return make_node(AST_Call, self, {
|
||||
expression: make_node(AST_Function, self, {
|
||||
argnames: [],
|
||||
body: self.body,
|
||||
}).init_vars(self),
|
||||
args: [],
|
||||
});
|
||||
}
|
||||
return self;
|
||||
});
|
||||
AST_Node.DEFMETHOD("wrap_expression", function() {
|
||||
var self = this;
|
||||
if (!is_statement(self)) self = make_node(AST_SimpleStatement, self, { body: self });
|
||||
if (!(self instanceof AST_Toplevel)) self = make_node(AST_Toplevel, self, { body: [ self ] });
|
||||
return self;
|
||||
});
|
||||
|
||||
function read_property(obj, node) {
|
||||
var key = node.get_property();
|
||||
|
||||
Reference in New Issue
Block a user