/* -----[ PARENTHESES ]----- */
function PARENS(nodetype, func) {
- nodetype.DEFMETHOD("needs_parens", func);
+ if (Array.isArray(nodetype)) {
+ nodetype.forEach(function(nodetype){
+ PARENS(nodetype, func);
+ });
+ } else {
+ nodetype.DEFMETHOD("needs_parens", func);
+ }
};
PARENS(AST_Node, function(){
return first_in_statement(output);
});
- PARENS(AST_Unary, function(output){
+ PARENS([ AST_Unary, AST_Undefined ], function(output){
var p = output.parent();
return p instanceof AST_PropAccess && p.expression === this;
});
return true;
});
- function assign_and_conditional_paren_rules(output) {
+ PARENS([ AST_Assign, AST_Conditional ], function (output){
var p = output.parent();
// !(a = false) β true
if (p instanceof AST_Unary)
// (a = foo)["prop"] βorβ (a = foo).prop
if (p instanceof AST_PropAccess && p.expression === this)
return true;
- };
-
- PARENS(AST_Assign, assign_and_conditional_paren_rules);
- PARENS(AST_Conditional, assign_and_conditional_paren_rules);
+ });
/* -----[ PRINTERS ]----- */