node-source-walk
Advanced tools
Comparing version 2.1.0 to 3.0.0
23
index.js
@@ -1,2 +0,2 @@ | ||
var acorn = require('acorn-jsx/inject')(require('acorn')); | ||
var babylon = require('babylon'); | ||
var assign = require('object-assign'); | ||
@@ -6,8 +6,21 @@ | ||
* @param {Object} options - Options to configure parser | ||
* @param {Boolean} [options.ecmaVersion=5] | ||
*/ | ||
module.exports = function(options) { | ||
this.options = assign({ | ||
ecmaVersion: 6, | ||
plugins: {jsx: true}, | ||
plugins: [ | ||
'jsx', | ||
'flow', | ||
'asyncFunctions', | ||
'classConstructorCall', | ||
'doExpressions', | ||
'trailingFunctionCommas', | ||
'objectRestSpread', | ||
'decorators', | ||
'classProperties', | ||
'exportExtensions', | ||
'exponentiationOperator', | ||
'asyncGenerators', | ||
'functionBind', | ||
'functionSent' | ||
], | ||
sourceType: 'module' | ||
@@ -32,3 +45,3 @@ }, options); | ||
return acorn.parse(src, options); | ||
return babylon.parse(src, options); | ||
}; | ||
@@ -35,0 +48,0 @@ |
{ | ||
"name": "node-source-walk", | ||
"version": "2.1.0", | ||
"version": "3.0.0", | ||
"description": "Execute a callback on every node of a source code's AST and stop walking when you see fit", | ||
@@ -29,4 +29,3 @@ "main": "index.js", | ||
"dependencies": { | ||
"acorn": "^2.0.4", | ||
"acorn-jsx": "^2.0.1", | ||
"babylon": "~6.8.1", | ||
"object-assign": "^4.0.1" | ||
@@ -33,0 +32,0 @@ }, |
@@ -29,13 +29,16 @@ ### node-source-walk [![npm](http://img.shields.io/npm/v/node-source-walk.svg)](https://npmjs.org/package/node-source-walk) [![npm](http://img.shields.io/npm/dm/node-source-walk.svg)](https://npmjs.org/package/node-source-walk) | ||
By default, Walker will use `acorn` supporting ES6 (and JSX) and the `sourceType: module`, but you can change any of the defaults as follows: | ||
By default, Walker will use `babylon` (supporting ES6, JSX, Flow, and all other available babylon plugins) and the `sourceType: module`, but you can change any of the defaults as follows: | ||
```js | ||
var walker = new Walker({ | ||
ecmaVersion: 5, | ||
sourceType: 'script' | ||
sourceType: 'script', | ||
// If you don't like experimental plugins | ||
plugins: [ | ||
'jsx', | ||
'flow' | ||
] | ||
}); | ||
``` | ||
* The supplied options are passed through to the parser, so you can configure it according | ||
to acorn's documentation: https://github.com/marijnh/acorn | ||
* The supplied options are passed through to the parser, so you can configure it according to babylon's documentation: https://github.com/babel/babylon | ||
@@ -46,3 +49,3 @@ ### Public Members | ||
* src: the contents of a file OR its AST (via Esprima or Acorn) | ||
* src: the contents of a file **OR** its (already parsed) AST | ||
* cb: a function that is called for every visited node | ||
@@ -49,0 +52,0 @@ |
@@ -31,2 +31,9 @@ var assert = require('assert'); | ||
it('does not throw on ES7 async functions', function() { | ||
var walker = new Walker(); | ||
assert.doesNotThrow(function() { | ||
walker.walk('async function foo() {}', function() {}); | ||
}); | ||
}); | ||
describe('walk', function() { | ||
@@ -72,3 +79,3 @@ var parseSpy, cb; | ||
var secondNode = cb.getCall(1).args[0]; | ||
assert(secondNode.parent === firstNode.body); | ||
assert(secondNode.parent === firstNode); | ||
}); | ||
@@ -75,0 +82,0 @@ }); |
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
8090
2
182
60
+ Addedbabylon@~6.8.1
+ Addedbabel-runtime@6.26.0(transitive)
+ Addedbabylon@6.8.4(transitive)
+ Addedcore-js@2.6.12(transitive)
+ Addedregenerator-runtime@0.11.1(transitive)
- Removedacorn@^2.0.4
- Removedacorn-jsx@^2.0.1
- Removedacorn@2.7.0(transitive)
- Removedacorn-jsx@2.0.1(transitive)