Skip to content

Commit

Permalink
- Travis: Remove old versions; add 10, 12, 14
Browse files Browse the repository at this point in the history
- npm: Add recommended `bugs`, `keywords`, `dependencies` and use `author`/`contributors`
- npm: Update devDeps, and switch to Babel 7/preset-env
- npm: Use simple run script syntax
- npm: Drop package-lock.json in favor of npmrc for consistency with other estools projects
- Maintenance: Add `.editorconfig`
- Maintenance: Drop use of gulpfile
- Update: Mocha API
- Testing: Add nyc
- Testing: Use chai/register-expect
- Testing: Drop bundled esprima in favor of using versioned
- Testing: Update espree API to supply sourceType/ecmaVersion
- Testing: Enable espree for dynamic import and adjust test expectation to take into account full Program context
- Docs: Use more modern syntax in examples
  • Loading branch information
brettz9 committed Apr 30, 2021
1 parent d16797b commit b1e56aa
Show file tree
Hide file tree
Showing 14 changed files with 96 additions and 5,510 deletions.
2 changes: 1 addition & 1 deletion .babelrc → .babelrc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"presets": [["env", {
"presets": [["@babel/preset-env", {
"targets": {
"node": "4.0"
}
Expand Down
18 changes: 18 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# This file is for unifying the coding style for different editors and IDEs
# editorconfig.org

root = true

[*]
end_of_line = lf
charset = utf-8
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = space
indent_size = 4

[*.json]
indent_size = 2

[*.yml]
indent_size = 2
16 changes: 0 additions & 16 deletions .npmignore

This file was deleted.

1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock = false
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ arch:
- ppc64le
language: node_js
node_js:
- 4
- 6
- 8
- 10
- 12
- 14
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ The following code will output all variables declared at the root of a file.

```javascript
estraverse.traverse(ast, {
enter: function (node, parent) {
enter (node, parent) {
if (node.type == 'FunctionExpression' || node.type == 'FunctionDeclaration')
return estraverse.VisitorOption.Skip;
},
leave: function (node, parent) {
leave (node, parent) {
if (node.type == 'VariableDeclarator')
console.log(node.id.name);
}
Expand All @@ -29,7 +29,7 @@ We can use `this.skip`, `this.remove` and `this.break` functions instead of usin

```javascript
estraverse.traverse(ast, {
enter: function (node) {
enter (node) {
this.break();
}
});
Expand All @@ -38,8 +38,8 @@ estraverse.traverse(ast, {
And estraverse provides `estraverse.replace` function. When returning node from `enter`/`leave`, current node is replaced with it.

```javascript
result = estraverse.replace(tree, {
enter: function (node) {
const result = estraverse.replace(tree, {
enter (node) {
// Replace it with replaced.
if (node.type === 'Literal')
return replaced;
Expand All @@ -51,7 +51,7 @@ By passing `visitor.keys` mapping, we can extend estraverse traversing functiona

```javascript
// This tree contains a user-defined `TestExpression` node.
var tree = {
const tree = {
type: 'TestExpression',

// This 'argument' is the property containing the other **node**.
Expand All @@ -64,7 +64,7 @@ var tree = {
extended: true
};
estraverse.traverse(tree, {
enter: function (node) { },
enter (node) { },

// Extending the existing traversing rules.
keys: {
Expand All @@ -78,7 +78,7 @@ By passing `visitor.fallback` option, we can control the behavior when encounter

```javascript
// This tree contains a user-defined `TestExpression` node.
var tree = {
const tree = {
type: 'TestExpression',

// This 'argument' is the property containing the other **node**.
Expand All @@ -91,7 +91,7 @@ var tree = {
extended: true
};
estraverse.traverse(tree, {
enter: function (node) { },
enter (node) { },

// Iterating the child **nodes** of unknown nodes.
fallback: 'iteration'
Expand All @@ -102,7 +102,7 @@ When `visitor.fallback` is a function, we can determine which keys to visit on e

```javascript
// This tree contains a user-defined `TestExpression` node.
var tree = {
const tree = {
type: 'TestExpression',

// This 'argument' is the property containing the other **node**.
Expand All @@ -115,11 +115,11 @@ var tree = {
extended: true
};
estraverse.traverse(tree, {
enter: function (node) { },
enter (node) { },

// Skip the `argument` property of each node
fallback: function(node) {
return Object.keys(node).filter(function(key) {
fallback(node) {
return Object.keys(node).filter((key) => {
return key !== 'argument';
});
}
Expand Down
70 changes: 0 additions & 70 deletions gulpfile.js

This file was deleted.

59 changes: 40 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,60 @@
"name": "estraverse",
"description": "ECMAScript JS AST traversal functions",
"homepage": "https://github.com/estools/estraverse",
"bugs": "https://github.com/estools/estraverse/issues",
"main": "estraverse.js",
"version": "5.2.0",
"engines": {
"node": ">=4.0"
},
"maintainers": [
{
"name": "Yusuke Suzuki",
"email": "[email protected]",
"web": "http://github.com/Constellation"
}
"keywords": [
"traversal"
],
"author": {
"name": "Yusuke Suzuki",
"email": "[email protected]",
"web": "http://github.com/Constellation"
},
"contributors": [
"Brett Zamir"
],
"files": [
"estraverse.js",
"dist"
],
"repository": {
"type": "git",
"url": "http://github.com/estools/estraverse.git"
},
"dependencies": {},
"devDependencies": {
"babel-preset-env": "^1.6.1",
"babel-register": "^6.3.13",
"chai": "^2.1.1",
"espree": "^1.11.0",
"gulp": "^3.8.10",
"gulp-bump": "^0.2.2",
"gulp-filter": "^2.0.0",
"gulp-git": "^1.0.1",
"gulp-tag-version": "^1.3.0",
"jshint": "^2.5.6",
"mocha": "^2.1.0"
"@babel/core": "^7.14.0",
"@babel/preset-env": "^7.14.0",
"@babel/register": "^7.13.16",
"chai": "^4.3.4",
"espree": "^7.3.1",
"esprima": "^4.0.1",
"jshint": "^2.12.0",
"mocha": "^8.3.2",
"nyc": "^15.1.0"
},
"license": "BSD-2-Clause",
"nyc": {
"branches": 100,
"lines": 100,
"functions": 100,
"statements": 100,
"reporter": [
"html",
"text"
],
"exclude": [
"test"
]
},
"scripts": {
"test": "npm run-script lint && npm run-script unit-test",
"test": "npm run lint && npm run unit-test",
"lint": "jshint estraverse.js",
"unit-test": "mocha --compilers js:babel-register"
"unit-test": "nyc mocha --require chai/register-expect --require @babel/register"
}
}
2 changes: 0 additions & 2 deletions test/checkDump.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

import { expect } from 'chai';

export default function checkDump(dump, expected) {
expect(normalize(expected)).to.be.equal(normalize(dump));
}
Expand Down
50 changes: 20 additions & 30 deletions test/es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

import Dumper from './dumper';
import checkDump from './checkDump';
import { parse as esprima } from './third_party/esprima';
import { parse as esprima } from 'esprima';
import { parse as espree } from 'espree';

function classDeclaration() {
Expand Down Expand Up @@ -250,9 +250,8 @@ describe('export', function() {
describe('import', function() {
it('default specifier #1', function() {
const tree = espree(`import Cocoa from 'rabbit-house'`, {
ecmaFeatures: {
modules: true
}
ecmaVersion: 2015,
sourceType: 'module'
});

checkDump(Dumper.dump(tree), `
Expand All @@ -271,9 +270,8 @@ describe('import', function() {

it('named specifier #1', function() {
const tree = espree(`import {Cocoa, Cappuccino as Chino} from 'rabbit-house'`, {
ecmaFeatures: {
modules: true
}
ecmaVersion: 2015,
sourceType: 'module'
});

checkDump(Dumper.dump(tree), `
Expand All @@ -300,9 +298,8 @@ describe('import', function() {

it('namespace specifier #1', function() {
const tree = espree(`import * as RabbitHouse from 'rabbit-house'`, {
ecmaFeatures: {
modules: true
}
ecmaVersion: 2015,
sourceType: 'module'
});

checkDump(Dumper.dump(tree), `
Expand All @@ -322,27 +319,20 @@ describe('import', function() {

describe('dynamic import', function() {
it('expression pattern #1', function() {
// TODO: espree currently doesn't support dynamic imports. Update when it does
// const tree = espree(`import('rabbit-house')`, {
// ecmaFeatures: {
// modules: true
// }
// });

const tree = {
type: 'ImportExpression',
source: {
type: 'Literal',
value: 'rabbit-house'
}
};
const tree = espree(`import('rabbit-house')`, {
ecmaVersion: 2020
});

checkDump(Dumper.dump(tree), `
enter - ImportExpression
enter - Literal
leave - Literal
leave - ImportExpression
`);
checkDump(Dumper.dump(tree), `
enter - Program
enter - ExpressionStatement
enter - ImportExpression
enter - Literal
leave - Literal
leave - ImportExpression
leave - ExpressionStatement
leave - Program
`);
});
});

Expand Down
Loading

0 comments on commit b1e56aa

Please sign in to comment.