ast-types
Advanced tools
Comparing version 0.3.0 to 0.3.1
@@ -26,3 +26,7 @@ var types = require("./types"); | ||
traverse(new NodePath(node)); | ||
// Just in case we call this.replace at the root, there needs to be an | ||
// additional parent Path to update. | ||
var rootPath = new NodePath({ root: node }); | ||
traverse(rootPath.get("root")); | ||
return rootPath.value.root; | ||
}; |
@@ -21,3 +21,3 @@ { | ||
], | ||
"version": "0.3.0", | ||
"version": "0.3.1", | ||
"homepage": "http://github.com/benjamn/ast-types", | ||
@@ -33,3 +33,3 @@ "repository": { | ||
"dependencies": { | ||
"ast-path": "~0.1.0" | ||
"ast-path": "~0.1.1" | ||
}, | ||
@@ -36,0 +36,0 @@ "devDependencies": {}, |
@@ -282,3 +282,3 @@ var types = require("../main"); | ||
traverse(ts, function(node) { | ||
n.TryStatement.assert(traverse(ts, function(node) { | ||
if (n.Literal.check(node)) { | ||
@@ -293,3 +293,3 @@ literalCount += 1; | ||
} | ||
}); | ||
}), true); | ||
@@ -329,2 +329,24 @@ assert.strictEqual(literalCount, 2); | ||
exports.testReplaceRoot = function(t, assert) { | ||
var ast = b.expressionStatement( | ||
b.unaryExpression("!", b.sequenceExpression([ | ||
b.identifier("a"), | ||
b.identifier("b"), | ||
b.identifier("c") | ||
])) | ||
); | ||
var callExp = types.traverse(ast, function(node) { | ||
if (n.ExpressionStatement.check(node)) { | ||
this.replace(b.callExpression(b.identifier("f"), [ | ||
node.expression | ||
])); | ||
} | ||
}); | ||
n.CallExpression.assert(callExp, true); | ||
t.finish(); | ||
}; | ||
exports.testNodePath = function(t, assert) { | ||
@@ -331,0 +353,0 @@ assert.strictEqual(new Path({}).constructor, Path); |
402978
11318
Updatedast-path@~0.1.1