Comparing version 3.1.1 to 4.0.0
@@ -27,14 +27,13 @@ /* | ||
var estraverse, | ||
var assign, | ||
estraverse, | ||
isArray, | ||
objectKeys; | ||
assign = require('object-assign'); | ||
estraverse = require('estraverse'); | ||
isArray = Array.isArray; | ||
if (!isArray) { | ||
isArray = function isArray(array) { | ||
return Object.prototype.toString.call(array) === '[object Array]'; | ||
}; | ||
} | ||
isArray = Array.isArray || function isArray(array) { | ||
return Object.prototype.toString.call(array) === '[object Array]'; | ||
}; | ||
@@ -60,4 +59,10 @@ objectKeys = Object.keys || function (o) { | ||
function Visitor(visitor) { | ||
function Visitor(visitor, options) { | ||
options = options || {}; | ||
this.__visitor = visitor || this; | ||
this.__childVisitorKeys = options.childVisitorKeys | ||
? assign({}, estraverse.VisitorKeys, options.childVisitorKeys) | ||
: estraverse.VisitorKeys; | ||
this.__fallback = options.fallback === 'iteration'; | ||
} | ||
@@ -78,5 +83,9 @@ | ||
children = estraverse.VisitorKeys[type]; | ||
children = this.__childVisitorKeys[type]; | ||
if (!children) { | ||
children = objectKeys(node); | ||
if (this.__fallback) { | ||
children = objectKeys(node); | ||
} else { | ||
throw new Error('Unknown node type ' + type + '.'); | ||
} | ||
} | ||
@@ -87,3 +96,3 @@ | ||
if (child) { | ||
if (Array.isArray(child)) { | ||
if (isArray(child)) { | ||
for (j = 0, jz = child.length; j < jz; ++j) { | ||
@@ -121,4 +130,4 @@ if (child[j]) { | ||
exports.Visitor = Visitor; | ||
exports.visit = function (node, visitor) { | ||
var v = new Visitor(visitor); | ||
exports.visit = function (node, visitor, options) { | ||
var v = new Visitor(visitor, options); | ||
v.visit(node); | ||
@@ -125,0 +134,0 @@ }; |
{ | ||
"name": "esrecurse", | ||
"description": "ECMAScript scope analyzer", | ||
"homepage": "http://github.com/estools/esrecurse", | ||
"description": "ECMAScript AST recursive visitor", | ||
"homepage": "https://github.com/estools/esrecurse", | ||
"main": "esrecurse.js", | ||
"version": "3.1.1", | ||
"version": "4.0.0", | ||
"engines": { | ||
@@ -14,3 +14,3 @@ "node": ">=0.10.0" | ||
"email": "utatane.tea@gmail.com", | ||
"web": "http://github.com/Constellation" | ||
"web": "https://github.com/Constellation" | ||
} | ||
@@ -20,27 +20,23 @@ ], | ||
"type": "git", | ||
"url": "http://github.com/estools/esrecurse.git" | ||
"url": "https://github.com/estools/esrecurse.git" | ||
}, | ||
"dependencies": { | ||
"estraverse": "~3.1.0" | ||
"estraverse": "~4.1.0", | ||
"object-assign": "^4.0.1" | ||
}, | ||
"devDependencies": { | ||
"chai": "^2.1.1", | ||
"chai": "^3.3.0", | ||
"coffee-script": "^1.9.1", | ||
"esprima": "^2.1.0", | ||
"gulp": "~3.8.10", | ||
"gulp-bump": "^0.2.2", | ||
"gulp-eslint": "^0.6.0", | ||
"gulp-filter": "^2.0.2", | ||
"gulp": "^3.9.0", | ||
"gulp-bump": "^1.0.0", | ||
"gulp-eslint": "^1.0.0", | ||
"gulp-filter": "^3.0.1", | ||
"gulp-git": "^1.1.0", | ||
"gulp-mocha": "~2.0.0", | ||
"gulp-mocha": "^2.1.3", | ||
"gulp-tag-version": "^1.2.1", | ||
"jsdoc": "~3.3.0-alpha10", | ||
"jsdoc": "^3.3.0-alpha10", | ||
"minimist": "^1.1.0" | ||
}, | ||
"licenses": [ | ||
{ | ||
"type": "BSD", | ||
"url": "http://github.com/estools/esrecurse/raw/master/LICENSE.BSD" | ||
} | ||
], | ||
"license": "BSD-2-Clause", | ||
"scripts": { | ||
@@ -47,0 +43,0 @@ "test": "gulp travis", |
@@ -1,4 +0,4 @@ | ||
### Esrecurse [![Build Status](https://secure.travis-ci.org/estools/esrecurse.png)](http://travis-ci.org/estools/esrecurse) | ||
### Esrecurse [![Build Status](https://travis-ci.org/estools/esrecurse.svg?branch=master)](https://travis-ci.org/estools/esrecurse) | ||
Esrecurse ([esrecurse](http://github.com/estools/esrecurse)) is | ||
Esrecurse ([esrecurse](https://github.com/estools/esrecurse)) is | ||
[ECMAScript](http://www.ecma-international.org/publications/standards/Ecma-262.htm) | ||
@@ -62,6 +62,58 @@ recursive traversing functionality. | ||
The `childVisitorKeys` option does customize the behavoir of `this.visitChildren(node)`. | ||
We can use user-defined node types. | ||
```javascript | ||
// This tree contains a user-defined `TestExpression` node. | ||
var tree = { | ||
type: 'TestExpression', | ||
// This 'argument' is the property containing the other **node**. | ||
argument: { | ||
type: 'Literal', | ||
value: 20 | ||
}, | ||
// This 'extended' is the property not containing the other **node**. | ||
extended: true | ||
}; | ||
esrecurse.visit( | ||
ast, | ||
{ | ||
Literal: function (node) { | ||
// do something... | ||
} | ||
}, | ||
{ | ||
// Extending the existing traversing rules. | ||
childVisitorKeys: { | ||
// TargetNodeName: [ 'keys', 'containing', 'the', 'other', '**node**' ] | ||
TestExpression: ['argument'] | ||
} | ||
} | ||
); | ||
``` | ||
We can use the `fallback` option as well. | ||
If the `fallback` option is `"iteration"`, `esrecurse` would visit all enumerable properties of unknown nodes. | ||
Please note circular references cause the stack overflow. AST might have circular references in additional properties for some purpose (e.g. `node.parent`). | ||
```javascript | ||
esrecurse.visit( | ||
ast, | ||
{ | ||
Literal: function (node) { | ||
// do something... | ||
} | ||
}, | ||
{ | ||
fallback: 'iteration' | ||
} | ||
); | ||
``` | ||
### License | ||
Copyright (C) 2014 [Yusuke Suzuki](http://github.com/Constellation) | ||
(twitter: [@Constellation](http://twitter.com/Constellation)) and other contributors. | ||
Copyright (C) 2014 [Yusuke Suzuki](https://github.com/Constellation) | ||
(twitter: [@Constellation](https://twitter.com/Constellation)) and other contributors. | ||
@@ -68,0 +120,0 @@ Redistribution and use in source and binary forms, with or without |
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
No License Found
License(Experimental) License information could not be found.
Found 1 instance in 1 package
12645
0
111
139
2
+ Addedobject-assign@^4.0.1
+ Addedestraverse@4.1.1(transitive)
+ Addedobject-assign@4.1.1(transitive)
- Removedestraverse@3.1.0(transitive)
Updatedestraverse@~4.1.0