Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions esprima-walk.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function walk( ast, fn ) {

child = node[ key ]

if ( child instanceof Array ) {
if ( child instanceof Array && key != 'range') {

for ( j = 0, len = child.length; j < len; j += 1 ) {
stack.push( child[ j ] )
Expand Down Expand Up @@ -51,13 +51,13 @@ walk.walkAddParent = function ( ast, fn ) {

child = node[ key ]

if ( child instanceof Array ) {
if ( child instanceof Array && key != 'range') {

for ( j = 0, len = child.length; j < len; j += 1 ) {

subchild = child[ j ]

if( subchild instanceof Object ) {
if( subchild instanceof Object ) {

subchild.parent = node

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"devDependencies": {
"mocha": "~1.19.0",
"chai": "~1.9.1",
"eslint": "~0.6.2"
"eslint": "~0.6.2",
"esprima": "~2.7.2"
},
"scripts": {
"test": "node_modules/eslint/bin/eslint.js . && node_modules/mocha/bin/mocha --reporter spec test.js"
Expand Down
59 changes: 58 additions & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,64 @@ var expect = require( 'chai' ).expect

var walk = require( './esprima-walk' )

describe( 'esprima-walk', function () {
var esprima = require('esprima')

var source = 'var i=0;'






describe('esprima-walk with range', function(){
it('should work', function(){
var ast = esprima.parse(source, {
range: true
})

var types = []

walk( ast, function ( node ) {
types.push( node.type )
} )

var expectedTypes = [ 'Program',
'VariableDeclaration',
'VariableDeclarator',
'Identifier',
'Literal' ]

expect( types ).to.deep.equal( expectedTypes )

})
})

describe('esprima-walkAddParent with range', function(){
walk = walk.walkAddParent
it('should work', function(){
var ast = esprima.parse(source, {
range: true
})

var types = []

walk( ast, function ( node ) {
types.push( node.type )
} )

var expectedTypes = [ 'Program',
'VariableDeclaration',
'VariableDeclarator',
'Identifier',
'Literal' ]

expect( types ).to.deep.equal( expectedTypes )

})
})


describe( 'esprima-walk', function () {

it( 'should work', function () {

Expand Down Expand Up @@ -68,3 +124,4 @@ describe( 'esprima-walk', function () {


} )