Skip to content
This repository was archived by the owner on Jun 23, 2025. It is now read-only.

Convert to ES6 that is supported on Node 4, commonjs modules and remove Babel #9

Closed
wants to merge 2 commits into from
Closed
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
3 changes: 0 additions & 3 deletions .babelrc

This file was deleted.

21 changes: 6 additions & 15 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
sudo: false
language: node_js
node_js:
- "0.10"
- "0.11"
- "0.12"
- "iojs-1"
- "iojs-2"
- "iojs-3"
- "4"
matrix:
allow_failures:
- node_js:
- "0.11"
- "iojs-1"
- "iojs-2"
- "iojs-3"
- "4"
- "5"
- "6"
- "7"
sudo: false
script: "npm test"
65 changes: 45 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
# ESLint Scope
Escope ([escope](http://github.com/estools/escope)) is
[ECMAScript](http://www.ecma-international.org/publications/standards/Ecma-262.htm)
scope analyzer extracted from [esmangle project](http://github.com/estools/esmangle).

ESLint Scope is the [ECMAScript](http://www.ecma-international.org/publications/standards/Ecma-262.htm) scope analyzer used in ESLint. It is a fork of [escope](http://github.com/estools/escope).
[![Build Status](https://travis-ci.org/estools/escope.png?branch=master)](https://travis-ci.org/estools/escope)

## Usage

Install:

```
npm i eslint-scope --save
```

Example:
### Example

```js
var eslintScope = require('eslint-scope');
var escope = require('escope');
var esprima = require('esprima');
var estraverse = require('estraverse');

var ast = esprima.parse(code);
var scopeManager = eslintScope.analyze(ast);
var scopeManager = escope.analyze(ast);

var currentScope = scopeManager.acquire(ast); // global scope

Expand All @@ -40,15 +34,46 @@ estraverse.traverse(ast, {
});
```

## Contributing
### Document

Generated JSDoc is [here](http://estools.github.io/escope/).

### Demos and Tools

Demonstration is [here](http://mazurov.github.io/escope-demo/) by [Sasha Mazurov](https://github.com/mazurov) (twitter: [@mazurov](http://twitter.com/mazurov)). [issue](https://github.com/estools/escope/issues/14)

![Demo](https://f.cloud.github.com/assets/75759/462920/7aa6dd40-b4f5-11e2-9f07-9f4e8d0415f9.gif)


And there are tools constructed on Escope.

- [Esmangle](https://github.com/estools/esmangle) is a minifier / mangler / optimizer.
- [Eslevels](https://github.com/mazurov/eslevels) is a scope levels analyzer and [SublimeText plugin for scope context coloring](https://github.com/mazurov/sublime-levels) is constructed on it.
- [Esgoggles](https://github.com/keeyipchan/esgoggles) is JavaScript code browser.


### License

Issues and pull requests will be triaged and responded to as quickly as possible. We operate under the [ESLint Contributor Guidelines](http://eslint.org/docs/developer-guide/contributing), so please be sure to read them before contributing. If you're not sure where to dig in, check out the [issues](https://github.com/eslint/eslint-scope/issues).
Copyright (C) 2012-2013 [Yusuke Suzuki](http://github.com/Constellation)
(twitter: [@Constellation](http://twitter.com/Constellation)) and other contributors.

## Build Commands
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* `npm test` - run all linting and tests
* `npm run lint` - run all linting
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

## License
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

ESLint Scope is licensed under a permissive BSD 2-clause license.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 changes: 6 additions & 31 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

var gulp = require('gulp'),
mocha = require('gulp-mocha'),
babel = require('gulp-babel'),
git = require('gulp-git'),
bump = require('gulp-bump'),
filter = require('gulp-filter'),
Expand All @@ -39,10 +38,6 @@ var gulp = require('gulp'),
eslint = require('gulp-eslint'),
fs = require('fs');

require('babel-register')({
only: /eslint-scope\/(src|test)\//
});

var TEST = [ 'test/*.js' ];
var SOURCE = [ 'src/**/*.js' ];

Expand All @@ -69,43 +64,23 @@ var ESLINT_OPTION = {
}
};

var BABEL_OPTIONS = JSON.parse(fs.readFileSync('.babelrc', { encoding: 'utf8' }));

var build = lazypipe()
.pipe(sourcemaps.init)
.pipe(babel, BABEL_OPTIONS)
.pipe(sourcemaps.write)
.pipe(gulp.dest, 'lib');

gulp.task('build-for-watch', function () {
return gulp.src(SOURCE).pipe(plumber()).pipe(build());
});

gulp.task('build', function () {
return gulp.src(SOURCE).pipe(build());
});

gulp.task('browserify', [ 'build' ], function () {
gulp.task('browserify', function () {
return browserify({
entries: [ './lib/index.js' ]
entries: [ './src/index.js' ]
})
.bundle()
.pipe(source('bundle.js'))
.pipe(gulp.dest('build'))
});

gulp.task('test', [ 'lint', 'build' ], function () {
gulp.task('test', function () {
return gulp.src(TEST)
.pipe(mocha({
reporter: 'spec',
timeout: 100000 // 100s
}));
});

gulp.task('watch', [ 'build-for-watch' ], function () {
gulp.watch(SOURCE, [ 'build-for-watch' ]);
});

// Currently, not works for ES6.
gulp.task('lint', function () {
return gulp.src(SOURCE)
Expand Down Expand Up @@ -145,9 +120,9 @@ function inc(importance) {
}));
}

gulp.task('patch', [ 'build' ], function () { return inc('patch'); })
gulp.task('minor', [ 'build' ], function () { return inc('minor'); })
gulp.task('major', [ 'build' ], function () { return inc('major'); })
gulp.task('patch', function () { return inc('patch'); })
gulp.task('minor', function () { return inc('minor'); })
gulp.task('major', function () { return inc('major'); })

gulp.task('travis', [ 'test' ]);
gulp.task('default', [ 'travis' ]);
43 changes: 20 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
{
"name": "eslint-scope",
"description": "ECMAScript scope analyzer for ESLint",
"homepage": "http://github.com/eslint/eslint-scope",
"main": "lib/index.js",
"description": "ECMAScript scope analyzer",
"homepage": "http://github.com/estools/escope",
"main": "src/index.js",
"version": "3.6.0",
"engines": {
"node": ">=0.4.0"
},
"repository": "eslint/eslint-scope",
"bugs": {
"url": "https://github.com/eslint/eslint-scope/issues"
},
"license": "BSD-2-Clause",
"scripts": {
"test": "gulp travis",
"unit-test": "gulp test",
"lint": "gulp lint",
"jsdoc": "jsdoc src/*.js README.md",
"release": "eslint-release",
"ci-release": "eslint-ci-release",
"gh-release": "eslint-gh-release",
"alpharelease": "eslint-prerelease alpha",
"betarelease": "eslint-prerelease beta"
"maintainers": [
{
"name": "Yusuke Suzuki",
"email": "[email protected]",
"web": "http://github.com/Constellation"
}
],
"repository": {
"type": "git",
"url": "https://github.com/estools/escope.git"
},
"dependencies": {
"es6-map": "^0.1.3",
Expand All @@ -30,16 +25,11 @@
"estraverse": "^4.1.1"
},
"devDependencies": {
"babel": "^6.3.26",
"babel-preset-es2015": "^6.3.13",
"babel-register": "^6.3.13",
"browserify": "^13.0.0",
"chai": "^3.4.1",
"eslint-release": "^0.10.1",
"espree": "^3.1.1",
"esprima": "^2.7.1",
"gulp": "^3.9.0",
"gulp-babel": "^6.1.1",
"gulp-bump": "^1.0.0",
"gulp-eslint": "^1.1.1",
"gulp-espower": "^1.0.2",
Expand All @@ -52,5 +42,12 @@
"jsdoc": "^3.4.0",
"lazypipe": "^1.0.1",
"vinyl-source-stream": "^1.1.0"
},
"license": "BSD-2-Clause",
"scripts": {
"test": "gulp travis",
"unit-test": "gulp test",
"lint": "gulp lint",
"jsdoc": "jsdoc src/*.js README.md"
}
}
9 changes: 5 additions & 4 deletions src/definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
"use strict";

import Variable from './variable';
const Variable = require('./variable');

/**
* @class Definition
*/
export default class Definition {
class Definition {
constructor(type, name, node, parent, index, kind) {
/**
* @member {String} Definition#type - type of the occurrence (e.g. "Parameter", "Variable", ...).
Expand Down Expand Up @@ -70,9 +71,9 @@ class ParameterDefinition extends Definition {
}
}

export {
module.exports = {
ParameterDefinition,
Definition
}
};

/* vim: set sw=4 ts=4 et tw=80 : */
22 changes: 12 additions & 10 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,18 @@
* The main interface is the {@link analyze} function.
* @module escope
*/
"use strict";

/*jslint bitwise:true */

import assert from 'assert';
const assert = require('assert');

import ScopeManager from './scope-manager';
import Referencer from './referencer';
import Reference from './reference';
import Variable from './variable';
import Scope from './scope';
import { version } from '../package.json';
const ScopeManager = require('./scope-manager');
const Referencer = require('./referencer');
const Reference = require('./reference');
const Variable = require('./variable');
const Scope = require('./scope');
const version = require('../package.json').version;

function defaultOptions() {
return {
Expand Down Expand Up @@ -114,7 +115,7 @@ function updateDeeply(target, override) {
* @param {string} [providedOptions.fallback='iteration'] - A kind of the fallback in order to encounter with unknown node. See [esrecurse](https://github.com/estools/esrecurse)'s the `fallback` option.
* @return {ScopeManager}
*/
export function analyze(tree, providedOptions) {
function analyze(tree, providedOptions) {
var scopeManager, referencer, options;

options = updateDeeply(defaultOptions(), providedOptions);
Expand All @@ -129,7 +130,7 @@ export function analyze(tree, providedOptions) {
return scopeManager;
}

export {
module.exports = {
/** @name module:escope.version */
version,
/** @name module:escope.Reference */
Expand All @@ -139,7 +140,8 @@ export {
/** @name module:escope.Scope */
Scope,
/** @name module:escope.ScopeManager */
ScopeManager
ScopeManager,
analyze
};


Expand Down
9 changes: 6 additions & 3 deletions src/pattern-visitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
"use strict";

import { Syntax } from 'estraverse';
import esrecurse from 'esrecurse';
const Syntax = require('estraverse').Syntax;
const esrecurse = require('esrecurse');

function getLast(xs) {
return xs[xs.length - 1] || null;
}

export default class PatternVisitor extends esrecurse.Visitor {
class PatternVisitor extends esrecurse.Visitor {
static isPattern(node) {
var nodeType = node.type;
return (
Expand Down Expand Up @@ -131,4 +132,6 @@ export default class PatternVisitor extends esrecurse.Visitor {
}
}

module.exports = PatternVisitor;

/* vim: set sw=4 ts=4 et tw=80 : */
5 changes: 4 additions & 1 deletion src/reference.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
"use strict";

const READ = 0x1;
const WRITE = 0x2;
Expand All @@ -30,7 +31,7 @@ const RW = READ | WRITE;
* A Reference represents a single occurrence of an identifier in code.
* @class Reference
*/
export default class Reference {
class Reference {
constructor(ident, scope, flag, writeExpr, maybeImplicitGlobal, partial, init) {
/**
* Identifier syntax node.
Expand Down Expand Up @@ -151,4 +152,6 @@ Reference.WRITE = WRITE;
*/
Reference.RW = RW;

module.exports = Reference;

/* vim: set sw=4 ts=4 et tw=80 : */
Loading