Comparing version 0.3.0 to 0.3.1
@@ -268,7 +268,12 @@ /* jshint node:true, undef:true, unused:true */ | ||
types.traverse(ast, function(node) { | ||
if (isReference(this) && !this.scope.lookup(node.name)) { | ||
if (!(node.name in seen)) { | ||
seen[node.name] = true; | ||
globals.push(node); | ||
types.visit(ast, { | ||
visitNode: function(path) { | ||
this.traverse(path); | ||
var node = path.value; | ||
if (isReference(path) && !path.scope.lookup(node.name)) { | ||
if (!(node.name in seen)) { | ||
seen[node.name] = true; | ||
globals.push(node); | ||
} | ||
} | ||
@@ -356,8 +361,7 @@ } | ||
bodyPath.get(0).replace( | ||
bodyPath.unshift( | ||
b.variableDeclaration( | ||
'var', | ||
[b.variableDeclarator(identifier, init || null)] | ||
), | ||
bodyPath.get(0).value | ||
) | ||
); | ||
@@ -364,0 +368,0 @@ |
{ | ||
"name": "ast-util", | ||
"version": "0.3.0", | ||
"version": "0.3.1", | ||
"description": "Utilities for AST transformers.", | ||
@@ -31,9 +31,9 @@ "main": "lib/index.js", | ||
"mocha": "^1.18.2", | ||
"recast": "^0.5.16", | ||
"recast": "^0.6.2", | ||
"esprima": "git://github.com/ariya/esprima.git#harmony" | ||
}, | ||
"dependencies": { | ||
"ast-types": "^0.3.26", | ||
"private": "^0.1.3" | ||
"ast-types": "^0.4.1", | ||
"private": "^0.1.5" | ||
} | ||
} |
@@ -24,5 +24,9 @@ /* jshint node:true, mocha:true, undef:true, unused:true */ | ||
var ast = parse(source); | ||
types.traverse(ast, function(node) { | ||
if (n.Identifier.check(node) && node.name === 'IT') { | ||
callback.call(this, node); | ||
types.visit(ast, { | ||
visitIdentifier: function(path) { | ||
if (path.value.name === 'IT') { | ||
callback.call(path, path.value); | ||
return false; | ||
} | ||
this.traverse(path); | ||
} | ||
@@ -213,6 +217,7 @@ }); | ||
it('can check names', function() { | ||
types.traverse(parse('a'), function(node) { | ||
if (n.Identifier.check(node)) { | ||
assert.ok(util.isReference(this, 'a')); | ||
assert.ok(!util.isReference(this, 'b')); | ||
types.visit(parse('a'), { | ||
visitIdentifier: function(path) { | ||
assert.ok(util.isReference(path, 'a')); | ||
assert.ok(!util.isReference(path, 'b')); | ||
return false; | ||
} | ||
@@ -303,8 +308,8 @@ }); | ||
types.traverse(ast, function(node) { | ||
if (n.VariableDeclaration.check(node)) { | ||
util.injectVariable(this.scope, b.identifier('b')); | ||
this.replace(b.expressionStatement( | ||
types.visit(ast, { | ||
visitVariableDeclaration: function(path) { | ||
util.injectVariable(path.scope, b.identifier('b')); | ||
return b.expressionStatement( | ||
b.callExpression(b.identifier('replacement'), []) | ||
)); | ||
); | ||
} | ||
@@ -311,0 +316,0 @@ }); |
Sorry, the diff of this file is not supported yet
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
104123
1866
+ Addedast-types@0.4.13(transitive)
+ Addeddepd@1.0.1(transitive)
- Removedast-types@0.3.38(transitive)
Updatedast-types@^0.4.1
Updatedprivate@^0.1.5