if (stat instanceof AST_For && !(stat.init instanceof AST_Definitions)) {
var abort = false;
prev.body.walk(new TreeWalker(function(node) {
- if (abort) return true;
+ if (abort || node instanceof AST_Scope) return true;
if (node instanceof AST_Binary && node.operator == "in") {
abort = true;
return true;
// parens around it too, otherwise the call will be
// interpreted as passing the arguments to the upper New
// expression.
- try {
- this.walk(new TreeWalker(function(node){
- if (node instanceof AST_Call) throw p;
- }));
- } catch(ex) {
- if (ex !== p) throw ex;
- return true;
- }
+ var parens = false;
+ this.walk(new TreeWalker(function(node) {
+ if (parens || node instanceof AST_Scope) return true;
+ if (node instanceof AST_Call) {
+ parens = true;
+ return true;
+ }
+ }));
+ return parens;
}
});
});
function parenthesize_for_noin(node, output, noin) {
- if (!noin) node.print(output);
- else try {
- // need to take some precautions here:
- // https://github.com/mishoo/UglifyJS2/issues/60
- node.walk(new TreeWalker(function(node){
- if (node instanceof AST_Binary && node.operator == "in")
- throw output;
- }));
- node.print(output);
- } catch(ex) {
- if (ex !== output) throw ex;
- node.print(output, true);
- }
+ var parens = false;
+ // need to take some precautions here:
+ // https://github.com/mishoo/UglifyJS2/issues/60
+ if (noin) node.walk(new TreeWalker(function(node) {
+ if (parens || node instanceof AST_Scope) return true;
+ if (node instanceof AST_Binary && node.operator == "in") {
+ parens = true;
+ return true;
+ }
+ }));
+ node.print(output, parens);
};
DEFPRINT(AST_VarDef, function(self, output){
}
expect_exact: 'var bar=(+new Date).toString(32);';
}
+
+dot_parenthesis_1: {
+ input: {
+ console.log(new (Math.random().constructor) instanceof Number);
+ }
+ expect_exact: "console.log(new(Math.random().constructor)instanceof Number);"
+ expect_stdout: "true"
+}
+
+dot_parenthesis_2: {
+ input: {
+ console.log(typeof new function(){Math.random()}.constructor);
+ }
+ expect_exact: "console.log(typeof new function(){Math.random()}.constructor);"
+ expect_stdout: "function"
+}