Comparing version 0.4.18 to 0.4.19
@@ -179,6 +179,3 @@ var assert = require("assert"); | ||
if (!canReprintChildren || | ||
// Require reprinting if additional parentheses are needed. | ||
(path.needsParens() && !hasParens(oldNode))) | ||
{ | ||
if (!canReprintChildren) { | ||
reprints.push({ | ||
@@ -222,2 +219,8 @@ newPath: path, | ||
// If this node needs parentheses and will not be wrapped with | ||
// parentheses when reprinted, then return false to skip reprinting | ||
// and let it be printed generically. | ||
if (path.needsParens() && !hasParens(oldNode)) | ||
return false; | ||
for (var k in util.getUnionOfKeys(newNode, oldNode)) { | ||
@@ -224,0 +227,0 @@ if (k === "loc") |
@@ -15,3 +15,3 @@ { | ||
], | ||
"version": "0.4.18", | ||
"version": "0.4.19", | ||
"homepage": "http://github.com/benjamn/recast", | ||
@@ -18,0 +18,0 @@ "repository": { |
@@ -5,2 +5,3 @@ var assert = require("assert"); | ||
var Printer = require("../lib/printer").Printer; | ||
var NodePath = require("../lib/path").NodePath; | ||
var util = require("../lib/util"); | ||
@@ -169,1 +170,46 @@ var n = require("../lib/types").namedTypes; | ||
}; | ||
exports.testNegatedLoopCondition = function(t) { | ||
var ast = parse([ | ||
"for (var i = 0; i < 10; ++i) {", | ||
" console.log(i);", | ||
"}" | ||
].join("\n")) | ||
var loop = ast.program.body[0]; | ||
var test = loop.test; | ||
var negation = b.unaryExpression("!", test); | ||
assert.strictEqual( | ||
printer.print(negation), | ||
"!(i < 10)" | ||
); | ||
loop.test = negation; | ||
assert.strictEqual(printer.print(ast), [ | ||
"for (var i = 0; !(i < 10); ++i) {", | ||
" console.log(i);", | ||
"}" | ||
].join("\n")); | ||
t.finish(); | ||
}; | ||
exports.testDiscretionaryParens = function(t) { | ||
var code = [ | ||
"if (info.line && (i > 0 || !skipFirstLine)) {", | ||
" info = copyLineInfo(info);", | ||
"}" | ||
].join("\n"); | ||
var ast = parse(code); | ||
var rightPath = new NodePath(ast).get( | ||
"program", "body", 0, "test", "right"); | ||
assert.ok(rightPath.needsParens()); | ||
assert.strictEqual(printer.print(ast), code); | ||
t.finish(); | ||
}; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
198081
5300