Skip to content
This repository has been archived by the owner on Aug 15, 2024. It is now read-only.

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

Closed
wants to merge 10 commits into from
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"
39 changes: 7 additions & 32 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' ]);
gulp.task('default', [ 'travis' ]);
6 changes: 1 addition & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "eslint-scope",
"description": "ECMAScript scope analyzer for ESLint",
"homepage": "http://github.com/eslint/eslint-scope",
"main": "lib/index.js",
"main": "src/index.js",
"version": "3.6.0",
"engines": {
"node": ">=0.4.0"
Expand Down Expand Up @@ -30,16 +30,12 @@
"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 Down
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 : */
35 changes: 22 additions & 13 deletions src/referencer.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,18 @@
(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 { Syntax } from 'estraverse';
import esrecurse from 'esrecurse';
import Reference from './reference';
import Variable from './variable';
import PatternVisitor from './pattern-visitor';
import { ParameterDefinition, Definition } from './definition';
import assert from 'assert';
"use strict";

const Syntax = require('estraverse').Syntax;
const esrecurse = require('esrecurse');
const Reference = require('./reference');
const Variable = require('./variable');
const PatternVisitor = require('./pattern-visitor');
const definition = require('./definition');
const assert = require('assert');

const ParameterDefinition = definition.ParameterDefinition;
const Definition = definition.Definition;

function traverseIdentifierInPattern(options, rootPattern, referencer, callback) {
// Call the callback at left hand identifier nodes, and Collect right hand nodes.
Expand Down Expand Up @@ -90,7 +95,7 @@ class Importer extends esrecurse.Visitor {
}

// Referencing variables and creating bindings.
export default class Referencer extends esrecurse.Visitor {
class Referencer extends esrecurse.Visitor {
constructor(options, scopeManager) {
super(null, options);
this.options = options;
Expand Down Expand Up @@ -222,11 +227,13 @@ export default class Referencer extends esrecurse.Visitor {
});
}

// Skip BlockStatement to prevent creating BlockStatement scope.
if (node.body.type === Syntax.BlockStatement) {
this.visitChildren(node.body);
} else {
this.visit(node.body);
if (node.body) {
Copy link
Member

@JamesHenry JamesHenry Feb 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code change should not be in this PR, it is being applied via #2

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry thought I had gotten that out with all my reattempts one sec

// Skip BlockStatement to prevent creating BlockStatement scope.
if (node.body.type === Syntax.BlockStatement) {
this.visitChildren(node.body);
} else {
this.visit(node.body);
}
}

this.close(node);
Expand Down Expand Up @@ -581,4 +588,6 @@ export default class Referencer extends esrecurse.Visitor {
}
}

module.exports = Referencer;

/* vim: set sw=4 ts=4 et tw=80 : */
39 changes: 20 additions & 19 deletions src/scope-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,28 @@
(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 WeakMap from 'es6-weak-map';
import Scope from './scope';
import assert from 'assert';

import {
GlobalScope,
CatchScope,
WithScope,
ModuleScope,
ClassScope,
SwitchScope,
FunctionScope,
ForScope,
TDZScope,
FunctionExpressionNameScope,
BlockScope
} from './scope';
"use strict";

const WeakMap = require('es6-weak-map');
const Scope = require('./scope');
const assert = require('assert');

const GlobalScope = Scope.GlobalScope;
const CatchScope = Scope.CatchScope;
const WithScope = Scope.WithScope;
const ModuleScope = Scope.ModuleScope;
const ClassScope = Scope.ClassScope;
const SwitchScope = Scope.SwitchScope;
const FunctionScope = Scope.FunctionScope;
const ForScope = Scope.ForScope;
const TDZScope = Scope.TDZScope;
const FunctionExpressionNameScope = Scope.FunctionExpressionNameScope;
const BlockScope = Scope.BlockScope;

/**
* @class ScopeManager
*/
export default class ScopeManager {
class ScopeManager {
constructor(options) {
this.scopes = [];
this.globalScope = null;
Expand Down Expand Up @@ -242,4 +241,6 @@ export default class ScopeManager {
}
}

module.exports = ScopeManager;

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