Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misc. npm and testing updates/tweaks #109

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
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
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ arch:
- ppc64le
language: node_js
node_js:
- 4
- 6
- 8
- 12
- 14
- 16
- 17
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.3.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.17.5",
"@babel/preset-env": "^7.16.11",
"@babel/register": "^7.17.0",
"chai": "^4.3.6",
"espree": "^9.3.1",
"esprima": "^4.0.1",
"jshint": "^2.13.4",
"mocha": "^9.2.1",
"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.js --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