Skip to content

Commit 99c9ba4

Browse files
committed
- Travis: Remove old versions; add 10, 12, 14
- 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
1 parent ec3f900 commit 99c9ba4

File tree

14 files changed

+96
-5510
lines changed

14 files changed

+96
-5510
lines changed

.babelrc renamed to .babelrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"presets": [["env", {
2+
"presets": [["@babel/preset-env", {
33
"targets": {
44
"node": "4.0"
55
}

.editorconfig

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# This file is for unifying the coding style for different editors and IDEs
2+
# editorconfig.org
3+
4+
root = true
5+
6+
[*]
7+
end_of_line = lf
8+
charset = utf-8
9+
insert_final_newline = true
10+
trim_trailing_whitespace = true
11+
indent_style = space
12+
indent_size = 4
13+
14+
[*.json]
15+
indent_size = 2
16+
17+
[*.yml]
18+
indent_size = 2

.npmignore

Lines changed: 0 additions & 16 deletions
This file was deleted.

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock = false

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ arch:
33
- ppc64le
44
language: node_js
55
node_js:
6-
- 4
7-
- 6
8-
- 8
6+
- 10
7+
- 12
8+
- 14

README.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ The following code will output all variables declared at the root of a file.
1414

1515
```javascript
1616
estraverse.traverse(ast, {
17-
enter: function (node, parent) {
17+
enter (node, parent) {
1818
if (node.type == 'FunctionExpression' || node.type == 'FunctionDeclaration')
1919
return estraverse.VisitorOption.Skip;
2020
},
21-
leave: function (node, parent) {
21+
leave (node, parent) {
2222
if (node.type == 'VariableDeclarator')
2323
console.log(node.id.name);
2424
}
@@ -29,7 +29,7 @@ We can use `this.skip`, `this.remove` and `this.break` functions instead of usin
2929

3030
```javascript
3131
estraverse.traverse(ast, {
32-
enter: function (node) {
32+
enter (node) {
3333
this.break();
3434
}
3535
});
@@ -38,8 +38,8 @@ estraverse.traverse(ast, {
3838
And estraverse provides `estraverse.replace` function. When returning node from `enter`/`leave`, current node is replaced with it.
3939

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

5252
```javascript
5353
// This tree contains a user-defined `TestExpression` node.
54-
var tree = {
54+
const tree = {
5555
type: 'TestExpression',
5656

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

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

7979
```javascript
8080
// This tree contains a user-defined `TestExpression` node.
81-
var tree = {
81+
const tree = {
8282
type: 'TestExpression',
8383

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

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

103103
```javascript
104104
// This tree contains a user-defined `TestExpression` node.
105-
var tree = {
105+
const tree = {
106106
type: 'TestExpression',
107107

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

120120
// Skip the `argument` property of each node
121-
fallback: function(node) {
122-
return Object.keys(node).filter(function(key) {
121+
fallback(node) {
122+
return Object.keys(node).filter((key) => {
123123
return key !== 'argument';
124124
});
125125
}

gulpfile.js

Lines changed: 0 additions & 70 deletions
This file was deleted.

package.json

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,60 @@
22
"name": "estraverse",
33
"description": "ECMAScript JS AST traversal functions",
44
"homepage": "https://github.com/estools/estraverse",
5+
"bugs": "https://github.com/estools/estraverse/issues",
56
"main": "estraverse.js",
67
"version": "5.3.0",
78
"engines": {
89
"node": ">=4.0"
910
},
10-
"maintainers": [
11-
{
12-
"name": "Yusuke Suzuki",
13-
"email": "utatane.tea@gmail.com",
14-
"web": "http://github.com/Constellation"
15-
}
11+
"keywords": [
12+
"traversal"
13+
],
14+
"author": {
15+
"name": "Yusuke Suzuki",
16+
"email": "utatane.tea@gmail.com",
17+
"web": "http://github.com/Constellation"
18+
},
19+
"contributors": [
20+
"Brett Zamir"
21+
],
22+
"files": [
23+
"estraverse.js",
24+
"dist"
1625
],
1726
"repository": {
1827
"type": "git",
1928
"url": "http://github.com/estools/estraverse.git"
2029
},
30+
"dependencies": {},
2131
"devDependencies": {
22-
"babel-preset-env": "^1.6.1",
23-
"babel-register": "^6.3.13",
24-
"chai": "^2.1.1",
25-
"espree": "^1.11.0",
26-
"gulp": "^3.8.10",
27-
"gulp-bump": "^0.2.2",
28-
"gulp-filter": "^2.0.0",
29-
"gulp-git": "^1.0.1",
30-
"gulp-tag-version": "^1.3.0",
31-
"jshint": "^2.5.6",
32-
"mocha": "^2.1.0"
32+
"@babel/core": "^7.14.0",
33+
"@babel/preset-env": "^7.14.0",
34+
"@babel/register": "^7.13.16",
35+
"chai": "^4.3.4",
36+
"espree": "^7.3.1",
37+
"esprima": "^4.0.1",
38+
"jshint": "^2.12.0",
39+
"mocha": "^8.3.2",
40+
"nyc": "^15.1.0"
3341
},
3442
"license": "BSD-2-Clause",
43+
"nyc": {
44+
"branches": 100,
45+
"lines": 100,
46+
"functions": 100,
47+
"statements": 100,
48+
"reporter": [
49+
"html",
50+
"text"
51+
],
52+
"exclude": [
53+
"test"
54+
]
55+
},
3556
"scripts": {
36-
"test": "npm run-script lint && npm run-script unit-test",
57+
"test": "npm run lint && npm run unit-test",
3758
"lint": "jshint estraverse.js",
38-
"unit-test": "mocha --compilers js:babel-register"
59+
"unit-test": "nyc mocha --require chai/register-expect --require @babel/register"
3960
}
4061
}

test/checkDump.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2121
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2222

23-
import { expect } from 'chai';
24-
2523
export default function checkDump(dump, expected) {
2624
expect(normalize(expected)).to.be.equal(normalize(dump));
2725
}

test/es6.js

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
import Dumper from './dumper';
2626
import checkDump from './checkDump';
27-
import { parse as esprima } from './third_party/esprima';
27+
import { parse as esprima } from 'esprima';
2828
import { parse as espree } from 'espree';
2929

3030
function classDeclaration() {
@@ -250,9 +250,8 @@ describe('export', function() {
250250
describe('import', function() {
251251
it('default specifier #1', function() {
252252
const tree = espree(`import Cocoa from 'rabbit-house'`, {
253-
ecmaFeatures: {
254-
modules: true
255-
}
253+
ecmaVersion: 2015,
254+
sourceType: 'module'
256255
});
257256

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

272271
it('named specifier #1', function() {
273272
const tree = espree(`import {Cocoa, Cappuccino as Chino} from 'rabbit-house'`, {
274-
ecmaFeatures: {
275-
modules: true
276-
}
273+
ecmaVersion: 2015,
274+
sourceType: 'module'
277275
});
278276

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

301299
it('namespace specifier #1', function() {
302300
const tree = espree(`import * as RabbitHouse from 'rabbit-house'`, {
303-
ecmaFeatures: {
304-
modules: true
305-
}
301+
ecmaVersion: 2015,
302+
sourceType: 'module'
306303
});
307304

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

323320
describe('dynamic import', function() {
324321
it('expression pattern #1', function() {
325-
// TODO: espree currently doesn't support dynamic imports. Update when it does
326-
// const tree = espree(`import('rabbit-house')`, {
327-
// ecmaFeatures: {
328-
// modules: true
329-
// }
330-
// });
331-
332-
const tree = {
333-
type: 'ImportExpression',
334-
source: {
335-
type: 'Literal',
336-
value: 'rabbit-house'
337-
}
338-
};
322+
const tree = espree(`import('rabbit-house')`, {
323+
ecmaVersion: 2020
324+
});
339325

340-
checkDump(Dumper.dump(tree), `
341-
enter - ImportExpression
342-
enter - Literal
343-
leave - Literal
344-
leave - ImportExpression
345-
`);
326+
checkDump(Dumper.dump(tree), `
327+
enter - Program
328+
enter - ExpressionStatement
329+
enter - ImportExpression
330+
enter - Literal
331+
leave - Literal
332+
leave - ImportExpression
333+
leave - ExpressionStatement
334+
leave - Program
335+
`);
346336
});
347337
});
348338

0 commit comments

Comments
 (0)