Added logging, changed some directory structure

This commit is contained in:
2018-01-13 21:33:40 -05:00
parent f079a5f067
commit 8e72ffb917
73656 changed files with 35284 additions and 53718 deletions

View File

@@ -0,0 +1,3 @@
{
"presets": ["es2015"]
}

View File

@@ -0,0 +1,20 @@
{
"curly": true,
"eqeqeq": true,
"immed": true,
"indent": 4,
"eqnull": true,
"latedef": true,
"noarg": true,
"noempty": true,
"quotmark": "single",
"undef": true,
"unused": true,
"strict": true,
"trailing": true,
"validthis": true,
"onevar": true,
"node": true
}

View File

@@ -0,0 +1,5 @@
## Project license: \<BSD-2-Clause\>
- You will only Submit Contributions where You have authored 100% of the content.
- You will only Submit Contributions to which You have the necessary rights. This means that if You are employed You have received the necessary permissions from Your employer to make the Contributions.
- Whatever content You Contribute will be provided under the Project License.

View File

@@ -0,0 +1,19 @@
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* 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.
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.

View File

@@ -0,0 +1,79 @@
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).
[![Build Status](https://travis-ci.org/estools/escope.png?branch=master)](https://travis-ci.org/estools/escope)
### Example
```js
var escope = require('escope');
var esprima = require('esprima');
var estraverse = require('estraverse');
var ast = esprima.parse(code);
var scopeManager = escope.analyze(ast);
var currentScope = scopeManager.acquire(ast); // global scope
estraverse.traverse(ast, {
enter: function(node, parent) {
// do stuff
if (/Function/.test(node.type)) {
currentScope = scopeManager.acquire(node); // get current function scope
}
},
leave: function(node, parent) {
if (/Function/.test(node.type)) {
currentScope = currentScope.upper; // set to parent scope
}
// do stuff
}
});
```
### 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
Copyright (C) 2012-2013 [Yusuke Suzuki](http://github.com/Constellation)
(twitter: [@Constellation](http://twitter.com/Constellation)) and other contributors.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* 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.
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.

View File

@@ -0,0 +1,13 @@
{
"name": "escope",
"version": "2.0.2-dev",
"main": "escope.js",
"dependencies": {
"estraverse": ">= 0.0.2"
},
"ignore": [
"**/.*",
"node_modules",
"components"
]
}

View File

@@ -0,0 +1,153 @@
/*
Copyright (C) 2014 Yusuke Suzuki <utatane.tea@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* 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.
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.
*/
'use strict';
var gulp = require('gulp'),
mocha = require('gulp-mocha'),
babel = require('gulp-babel'),
git = require('gulp-git'),
bump = require('gulp-bump'),
filter = require('gulp-filter'),
tagVersion = require('gulp-tag-version'),
sourcemaps = require('gulp-sourcemaps'),
plumber = require('gulp-plumber'),
source = require('vinyl-source-stream'),
browserify = require('browserify'),
lazypipe = require('lazypipe'),
eslint = require('gulp-eslint'),
fs = require('fs');
require('babel-register')({
only: /escope\/(src|test)\//
});
var TEST = [ 'test/*.js' ];
var SOURCE = [ 'src/**/*.js' ];
var ESLINT_OPTION = {
rules: {
'quotes': 0,
'eqeqeq': 0,
'no-use-before-define': 0,
'no-shadow': 0,
'no-new': 0,
'no-underscore-dangle': 0,
'no-multi-spaces': 0,
'no-native-reassign': 0,
'no-loop-func': 0,
'no-lone-blocks': 0
},
ecmaFeatures: {
jsx: false,
modules: true
},
env: {
node: true,
es6: true
}
};
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 () {
return browserify({
entries: [ './lib/index.js' ]
})
.bundle()
.pipe(source('bundle.js'))
.pipe(gulp.dest('build'))
});
gulp.task('test', [ 'build' ], 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)
.pipe(eslint(ESLINT_OPTION))
.pipe(eslint.formatEach('stylish', process.stderr))
.pipe(eslint.failOnError());
});
/**
* Bumping version number and tagging the repository with it.
* Please read http://semver.org/
*
* You can use the commands
*
* gulp patch # makes v0.1.0 -> v0.1.1
* gulp feature # makes v0.1.1 -> v0.2.0
* gulp release # makes v0.2.1 -> v1.0.0
*
* To bump the version numbers accordingly after you did a patch,
* introduced a feature or made a backwards-incompatible release.
*/
function inc(importance) {
// get all the files to bump version in
return gulp.src(['./package.json'])
// bump the version number in those files
.pipe(bump({type: importance}))
// save it back to filesystem
.pipe(gulp.dest('./'))
// commit the changed version number
.pipe(git.commit('Bumps package version'))
// read only one file to get the version number
.pipe(filter('package.json'))
// **tag it in the repository**
.pipe(tagVersion({
prefix: ''
}));
}
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('travis', [ 'test' ]);
gulp.task('default', [ 'travis' ]);

View File

@@ -0,0 +1,106 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.Definition = exports.ParameterDefinition = undefined;
var _variable = require('./variable');
var _variable2 = _interopRequireDefault(_variable);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } /*
Copyright (C) 2015 Yusuke Suzuki <utatane.tea@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* 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.
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.
*/
/**
* @class Definition
*/
var Definition = function Definition(type, name, node, parent, index, kind) {
_classCallCheck(this, Definition);
/**
* @member {String} Definition#type - type of the occurrence (e.g. "Parameter", "Variable", ...).
*/
this.type = type;
/**
* @member {esprima.Identifier} Definition#name - the identifier AST node of the occurrence.
*/
this.name = name;
/**
* @member {esprima.Node} Definition#node - the enclosing node of the identifier.
*/
this.node = node;
/**
* @member {esprima.Node?} Definition#parent - the enclosing statement node of the identifier.
*/
this.parent = parent;
/**
* @member {Number?} Definition#index - the index in the declaration statement.
*/
this.index = index;
/**
* @member {String?} Definition#kind - the kind of the declaration statement.
*/
this.kind = kind;
};
/**
* @class ParameterDefinition
*/
exports.default = Definition;
var ParameterDefinition = function (_Definition) {
_inherits(ParameterDefinition, _Definition);
function ParameterDefinition(name, node, index, rest) {
_classCallCheck(this, ParameterDefinition);
/**
* Whether the parameter definition is a part of a rest parameter.
* @member {boolean} ParameterDefinition#rest
*/
var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(ParameterDefinition).call(this, _variable2.default.Parameter, name, node, null, index, null));
_this.rest = rest;
return _this;
}
return ParameterDefinition;
}(Definition);
exports.ParameterDefinition = ParameterDefinition;
exports.Definition = Definition;
/* vim: set sw=4 ts=4 et tw=80 : */
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImRlZmluaXRpb24uanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7OztBQXdCQTs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7SUFLcUIsYUFDakIsU0FEaUIsVUFDakIsQ0FBWSxJQUFaLEVBQWtCLElBQWxCLEVBQXdCLElBQXhCLEVBQThCLE1BQTlCLEVBQXNDLEtBQXRDLEVBQTZDLElBQTdDLEVBQW1EO3dCQURsQyxZQUNrQzs7Ozs7QUFJL0MsT0FBSyxJQUFMLEdBQVksSUFBWjs7OztBQUorQyxNQVEvQyxDQUFLLElBQUwsR0FBWSxJQUFaOzs7O0FBUitDLE1BWS9DLENBQUssSUFBTCxHQUFZLElBQVo7Ozs7QUFaK0MsTUFnQi9DLENBQUssTUFBTCxHQUFjLE1BQWQ7Ozs7QUFo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RzPTQgZXQgdHc9ODAgOiAqL1xuIl0sInNvdXJjZVJvb3QiOiIvc291cmNlLyJ9

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,88 @@
{
"_args": [
[
"escope@3.6.0",
"C:\\Users\\deranjer\\go\\src\\github.com\\deranjer\\goTorrent\\torrent-project"
]
],
"_from": "escope@3.6.0",
"_id": "escope@3.6.0",
"_inBundle": false,
"_integrity": "sha1-4Bl16BJ4GhY6ba392AOY3GTIicM=",
"_location": "/webpack/escope",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "escope@3.6.0",
"name": "escope",
"escapedName": "escope",
"rawSpec": "3.6.0",
"saveSpec": null,
"fetchSpec": "3.6.0"
},
"_requiredBy": [
"/webpack"
],
"_resolved": "https://registry.npmjs.org/escope/-/escope-3.6.0.tgz",
"_spec": "3.6.0",
"_where": "C:\\Users\\deranjer\\go\\src\\github.com\\deranjer\\goTorrent\\torrent-project",
"bugs": {
"url": "https://github.com/estools/escope/issues"
},
"dependencies": {
"es6-map": "^0.1.3",
"es6-weak-map": "^2.0.1",
"esrecurse": "^4.1.0",
"estraverse": "^4.1.1"
},
"description": "ECMAScript scope analyzer",
"devDependencies": {
"babel": "^6.3.26",
"babel-preset-es2015": "^6.3.13",
"babel-register": "^6.3.13",
"browserify": "^13.0.0",
"chai": "^3.4.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",
"gulp-filter": "^3.0.1",
"gulp-git": "^1.6.1",
"gulp-mocha": "^2.2.0",
"gulp-plumber": "^1.0.1",
"gulp-sourcemaps": "^1.6.0",
"gulp-tag-version": "^1.3.0",
"jsdoc": "^3.4.0",
"lazypipe": "^1.0.1",
"vinyl-source-stream": "^1.1.0"
},
"engines": {
"node": ">=0.4.0"
},
"homepage": "http://github.com/estools/escope",
"license": "BSD-2-Clause",
"main": "lib/index.js",
"maintainers": [
{
"name": "Yusuke Suzuki",
"email": "utatane.tea@gmail.com",
"url": "http://github.com/Constellation"
}
],
"name": "escope",
"repository": {
"type": "git",
"url": "git+https://github.com/estools/escope.git"
},
"scripts": {
"jsdoc": "jsdoc src/*.js README.md",
"lint": "gulp lint",
"test": "gulp travis",
"unit-test": "gulp test"
},
"version": "3.6.0"
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,28 @@
(function() {
var escope, esprima, expect, harmony;
expect = require('chai').expect;
esprima = require('esprima');
harmony = require('../third_party/esprima');
escope = require('..');
describe('global increment', function() {
return it('becomes read/write', function() {
var ast, globalScope, scopeManager;
ast = esprima.parse("b++;");
scopeManager = escope.analyze(ast);
expect(scopeManager.scopes).to.have.length(1);
globalScope = scopeManager.scopes[0];
expect(globalScope.type).to.be.equal('global');
expect(globalScope.variables).to.have.length(0);
expect(globalScope.references).to.have.length(1);
return expect(globalScope.references[0].isReadWrite()).to.be["true"];
});
});
}).call(this);
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImdsb2JhbC1pbmNyZW1lbnQuY29mZmVlIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQXVCQTtBQUFBLE1BQUEsZ0NBQUE7O0FBQUEsRUFBQSxNQUFB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RXQVJFLCBFVkVOIElGIEFEVklTRUQgT0YgVEhFIFBPU1NJQklMSVRZIE9GIFNVQ0ggREFNQUdFLlxuXG5leHBlY3QgPSByZXF1aXJlKCdjaGFpJykuZXhwZWN0XG5lc3ByaW1hID0gcmVxdWlyZSAnZXNwcmltYSdcbmhhcm1vbnkgPSByZXF1aXJlICcuLi90aGlyZF9wYXJ0eS9lc3ByaW1hJ1xuZXNjb3BlID0gcmVxdWlyZSAnLi4nXG5cbmRlc2NyaWJlICdnbG9iYWwgaW5jcmVtZW50JywgLT5cbiAgICBpdCAnYmVjb21lcyByZWFkL3dyaXRlJywgLT5cbiAgICAgICAgYXN0ID0gZXNwcmltYS5wYXJzZSBcIlwiXCJcbiAgICAgICAgYisrO1xuICAgICAgICBcIlwiXCJcblxuICAgICAgICBzY29wZU1hbmFnZXIgPSBlc2NvcGUuYW5hbHl6ZSBhc3RcbiAgICAgICAgZXhwZWN0KHNjb3BlTWFuYWdlci5zY29wZXMpLnRvLmhhdmUubGVuZ3RoIDFcbiAgICAgICAgZ2xvYmFsU2NvcGUgPSBzY29wZU1hbmFnZXIuc2NvcGVzWzBdXG4gICAgICAgIGV4cGVjdChnbG9iYWxTY29wZS50eXBlKS50by5iZS5lcXVhbCAnZ2xvYmFsJ1xuICAgICAgICBleHBlY3QoZ2xvYmFsU2NvcGUudmFyaWFibGVzKS50by5oYXZlLmxlbmd0aCAwXG4gICAgICAgIGV4cGVjdChnbG9iYWxTY29wZS5yZWZlcmVuY2VzKS50by5oYXZlLmxlbmd0aCAxXG4gICAgICAgIGV4cGVjdChnbG9iYWxTY29wZS5yZWZlcmVuY2VzWzBdLmlzUmVhZFdyaXRlKCkpLnRvLmJlLnRydWVcblxuIyB2aW06IHNldCBzdz00IHRzPTQgZXQgdHc9ODAgOlxuIl19

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,56 @@
(function() {
'use strict';
var escope, expect;
expect = require('chai').expect;
escope = require('..');
describe('object expression', function() {
return it('doesn\'t require property type', function() {
var ast, scope;
ast = {
type: 'Program',
body: [
{
type: 'VariableDeclaration',
declarations: [
{
type: 'VariableDeclarator',
id: {
type: 'Identifier',
name: 'a'
},
init: {
type: 'ObjectExpression',
properties: [
{
kind: 'init',
key: {
type: 'Identifier',
name: 'foo'
},
value: {
type: 'Identifier',
name: 'a'
}
}
]
}
}
]
}
]
};
scope = escope.analyze(ast).scopes[0];
expect(scope.variables).to.have.length(1);
expect(scope.references).to.have.length(2);
expect(scope.variables[0].name).to.be.equal('a');
expect(scope.references[0].identifier.name).to.be.equal('a');
return expect(scope.references[1].identifier.name).to.be.equal('a');
});
});
}).call(this);
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm9iamVjdC1leHByZXNzaW9uLmNvZmZlZSJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQztBQUFBLEVBQUEsWUFBQSxDQUFBO0FBQUEsTUFBQSxjQUFBOztBQUFBLEVBRUQsTUFBQSxHQUFTLE9BQUEsQ0FBUyxNQUFULENBQWUsQ0FBQyxNQUZ4QixDQUFBOztBQUFBLEVBR0QsTUFBQSxHQUFTLE9BQUEsQ0FBUyxJQUFULENBSFIsQ0FBQTs7QUFBQSxFQUtELFFBQUEsQ0FBVSxtQkFBVixFQUE4QixTQUFBLEdBQUE7V0FDMUIsRUFBQSxDQUFJLGdDQUFKLEVBQXFDLFNBQUEsR0FBQTtBQUlqQyxVQUFBLFVBQUE7QUFBQSxNQUFBLEdBQUEsR0FDSTtBQUFBLFFBQUEsSUFBQSxFQUFPLFNBQVA7QUFBQSxRQUNBLElBQUEsRUFBTTtVQUFDO0FBQUEsWUFDSCxJQUFBLEVBQU8scUJBREo7QUFBQSxZQUVILFlBQUEsRUFBYztjQUFDO0FBQUEsZ0JBQ1gsSUFBQSxFQUFPLG9CQURJO0FBQUEsZ0JBRVgsRUF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G4gICAgICAgICAgICAgICAgICAgIHR5cGU6ICdWYXJpYWJsZURlY2xhcmF0b3InXG4gICAgICAgICAgICAgICAgICAgIGlkOlxuICAgICAgICAgICAgICAgICAgICAgICAgdHlwZTogJ0lkZW50aWZpZXInXG4gICAgICAgICAgICAgICAgICAgICAgICBuYW1lOiAnYSdcbiAgICAgICAgICAgICAgICAgICAgaW5pdDpcbiAgICAgICAgICAgICAgICAgICAgICAgIHR5cGU6ICdPYmplY3RFeHByZXNzaW9uJ1xuICAgICAgICAgICAgICAgICAgICAgICAgcHJvcGVydGllczogW3tcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBraW5kOiAnaW5pdCdcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBrZXk6XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHR5cGU6ICdJZGVudGlmaWVyJ1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBuYW1lOiAnZm9vJ1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHZhbHVlOlxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB0eXBlOiAnSWRlbnRpZmllcidcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbmFtZTogJ2EnXG4gICAgICAgICAgICAgICAgICAgICAgICB9XVxuICAgICAgICAgICAgICAgIH1dXG4gICAgICAgICAgICB9XVxuXG4gICAgICAgIHNjb3BlID0gZXNjb3BlLmFuYWx5emUoYXN0KS5zY29wZXNbMF1cbiAgICAgICAgZXhwZWN0KHNjb3BlLnZhcmlhYmxlcykudG8uaGF2ZS5sZW5ndGgoMSlcbiAgICAgICAgZXhwZWN0KHNjb3BlLnJlZmVyZW5jZXMpLnRvLmhhdmUubGVuZ3RoKDIpXG4gICAgICAgIGV4cGVjdChzY29wZS52YXJpYWJsZXNbMF0ubmFtZSkudG8uYmUuZXF1YWwoJ2EnKVxuICAgICAgICBleHBlY3Qoc2NvcGUucmVmZXJlbmNlc1swXS5pZGVudGlmaWVyLm5hbWUpLnRvLmJlLmVxdWFsKCdhJylcbiAgICAgICAgZXhwZWN0KHNjb3BlLnJlZmVyZW5jZXNbMV0uaWRlbnRpZmllci5uYW1lKS50by5iZS5lcXVhbCgnYScpXG4iXX0=

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,78 @@
/*
Copyright (C) 2015 Yusuke Suzuki <utatane.tea@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* 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.
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.
*/
import Variable from './variable';
/**
* @class Definition
*/
export default class Definition {
constructor(type, name, node, parent, index, kind) {
/**
* @member {String} Definition#type - type of the occurrence (e.g. "Parameter", "Variable", ...).
*/
this.type = type;
/**
* @member {esprima.Identifier} Definition#name - the identifier AST node of the occurrence.
*/
this.name = name;
/**
* @member {esprima.Node} Definition#node - the enclosing node of the identifier.
*/
this.node = node;
/**
* @member {esprima.Node?} Definition#parent - the enclosing statement node of the identifier.
*/
this.parent = parent;
/**
* @member {Number?} Definition#index - the index in the declaration statement.
*/
this.index = index;
/**
* @member {String?} Definition#kind - the kind of the declaration statement.
*/
this.kind = kind;
}
}
/**
* @class ParameterDefinition
*/
class ParameterDefinition extends Definition {
constructor(name, node, index, rest) {
super(Variable.Parameter, name, node, null, index, null);
/**
* Whether the parameter definition is a part of a rest parameter.
* @member {boolean} ParameterDefinition#rest
*/
this.rest = rest;
}
}
export {
ParameterDefinition,
Definition
}
/* vim: set sw=4 ts=4 et tw=80 : */

View File

@@ -0,0 +1,146 @@
/*
Copyright (C) 2012-2014 Yusuke Suzuki <utatane.tea@gmail.com>
Copyright (C) 2013 Alex Seville <hi@alexanderseville.com>
Copyright (C) 2014 Thiago de Arruda <tpadilha84@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* 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.
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.
*/
/**
* Escope (<a href="http://github.com/estools/escope">escope</a>) is an <a
* href="http://www.ecma-international.org/publications/standards/Ecma-262.htm">ECMAScript</a>
* scope analyzer extracted from the <a
* href="http://github.com/estools/esmangle">esmangle project</a/>.
* <p>
* <em>escope</em> finds lexical scopes in a source program, i.e. areas of that
* program where different occurrences of the same identifier refer to the same
* variable. With each scope the contained variables are collected, and each
* identifier reference in code is linked to its corresponding variable (if
* possible).
* <p>
* <em>escope</em> works on a syntax tree of the parsed source code which has
* to adhere to the <a
* href="https://developer.mozilla.org/en-US/docs/SpiderMonkey/Parser_API">
* Mozilla Parser API</a>. E.g. <a href="http://esprima.org">esprima</a> is a parser
* that produces such syntax trees.
* <p>
* The main interface is the {@link analyze} function.
* @module escope
*/
/*jslint bitwise:true */
import assert from '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';
function defaultOptions() {
return {
optimistic: false,
directive: false,
nodejsScope: false,
impliedStrict: false,
sourceType: 'script', // one of ['script', 'module']
ecmaVersion: 5,
childVisitorKeys: null,
fallback: 'iteration'
};
}
function updateDeeply(target, override) {
var key, val;
function isHashObject(target) {
return typeof target === 'object' && target instanceof Object && !(target instanceof Array) && !(target instanceof RegExp);
}
for (key in override) {
if (override.hasOwnProperty(key)) {
val = override[key];
if (isHashObject(val)) {
if (isHashObject(target[key])) {
updateDeeply(target[key], val);
} else {
target[key] = updateDeeply({}, val);
}
} else {
target[key] = val;
}
}
}
return target;
}
/**
* Main interface function. Takes an Esprima syntax tree and returns the
* analyzed scopes.
* @function analyze
* @param {esprima.Tree} tree
* @param {Object} providedOptions - Options that tailor the scope analysis
* @param {boolean} [providedOptions.optimistic=false] - the optimistic flag
* @param {boolean} [providedOptions.directive=false]- the directive flag
* @param {boolean} [providedOptions.ignoreEval=false]- whether to check 'eval()' calls
* @param {boolean} [providedOptions.nodejsScope=false]- whether the whole
* script is executed under node.js environment. When enabled, escope adds
* a function scope immediately following the global scope.
* @param {boolean} [providedOptions.impliedStrict=false]- implied strict mode
* (if ecmaVersion >= 5).
* @param {string} [providedOptions.sourceType='script']- the source type of the script. one of 'script' and 'module'
* @param {number} [providedOptions.ecmaVersion=5]- which ECMAScript version is considered
* @param {Object} [providedOptions.childVisitorKeys=null] - Additional known visitor keys. See [esrecurse](https://github.com/estools/esrecurse)'s the `childVisitorKeys` option.
* @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) {
var scopeManager, referencer, options;
options = updateDeeply(defaultOptions(), providedOptions);
scopeManager = new ScopeManager(options);
referencer = new Referencer(options, scopeManager);
referencer.visit(tree);
assert(scopeManager.__currentScope === null, 'currentScope should be null.');
return scopeManager;
}
export {
/** @name module:escope.version */
version,
/** @name module:escope.Reference */
Reference,
/** @name module:escope.Variable */
Variable,
/** @name module:escope.Scope */
Scope,
/** @name module:escope.ScopeManager */
ScopeManager
};
/* vim: set sw=4 ts=4 et tw=80 : */

View File

@@ -0,0 +1,134 @@
/*
Copyright (C) 2015 Yusuke Suzuki <utatane.tea@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* 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.
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.
*/
import { Syntax } from 'estraverse';
import esrecurse from 'esrecurse';
function getLast(xs) {
return xs[xs.length - 1] || null;
}
export default class PatternVisitor extends esrecurse.Visitor {
static isPattern(node) {
var nodeType = node.type;
return (
nodeType === Syntax.Identifier ||
nodeType === Syntax.ObjectPattern ||
nodeType === Syntax.ArrayPattern ||
nodeType === Syntax.SpreadElement ||
nodeType === Syntax.RestElement ||
nodeType === Syntax.AssignmentPattern
);
}
constructor(options, rootPattern, callback) {
super(null, options);
this.rootPattern = rootPattern;
this.callback = callback;
this.assignments = [];
this.rightHandNodes = [];
this.restElements = [];
}
Identifier(pattern) {
const lastRestElement = getLast(this.restElements);
this.callback(pattern, {
topLevel: pattern === this.rootPattern,
rest: lastRestElement != null && lastRestElement.argument === pattern,
assignments: this.assignments
});
}
Property(property) {
// Computed property's key is a right hand node.
if (property.computed) {
this.rightHandNodes.push(property.key);
}
// If it's shorthand, its key is same as its value.
// If it's shorthand and has its default value, its key is same as its value.left (the value is AssignmentPattern).
// If it's not shorthand, the name of new variable is its value's.
this.visit(property.value);
}
ArrayPattern(pattern) {
var i, iz, element;
for (i = 0, iz = pattern.elements.length; i < iz; ++i) {
element = pattern.elements[i];
this.visit(element);
}
}
AssignmentPattern(pattern) {
this.assignments.push(pattern);
this.visit(pattern.left);
this.rightHandNodes.push(pattern.right);
this.assignments.pop();
}
RestElement(pattern) {
this.restElements.push(pattern);
this.visit(pattern.argument);
this.restElements.pop();
}
MemberExpression(node) {
// Computed property's key is a right hand node.
if (node.computed) {
this.rightHandNodes.push(node.property);
}
// the object is only read, write to its property.
this.rightHandNodes.push(node.object);
}
//
// ForInStatement.left and AssignmentExpression.left are LeftHandSideExpression.
// By spec, LeftHandSideExpression is Pattern or MemberExpression.
// (see also: https://github.com/estree/estree/pull/20#issuecomment-74584758)
// But espree 2.0 and esprima 2.0 parse to ArrayExpression, ObjectExpression, etc...
//
SpreadElement(node) {
this.visit(node.argument);
}
ArrayExpression(node) {
node.elements.forEach(this.visit, this);
}
AssignmentExpression(node) {
this.assignments.push(node);
this.visit(node.left);
this.rightHandNodes.push(node.right);
this.assignments.pop();
}
CallExpression(node) {
// arguments are right hand nodes.
node.arguments.forEach(a => { this.rightHandNodes.push(a); });
this.visit(node.callee);
}
}
/* vim: set sw=4 ts=4 et tw=80 : */

View File

@@ -0,0 +1,154 @@
/*
Copyright (C) 2015 Yusuke Suzuki <utatane.tea@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* 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.
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.
*/
const READ = 0x1;
const WRITE = 0x2;
const RW = READ | WRITE;
/**
* A Reference represents a single occurrence of an identifier in code.
* @class Reference
*/
export default class Reference {
constructor(ident, scope, flag, writeExpr, maybeImplicitGlobal, partial, init) {
/**
* Identifier syntax node.
* @member {esprima#Identifier} Reference#identifier
*/
this.identifier = ident;
/**
* Reference to the enclosing Scope.
* @member {Scope} Reference#from
*/
this.from = scope;
/**
* Whether the reference comes from a dynamic scope (such as 'eval',
* 'with', etc.), and may be trapped by dynamic scopes.
* @member {boolean} Reference#tainted
*/
this.tainted = false;
/**
* The variable this reference is resolved with.
* @member {Variable} Reference#resolved
*/
this.resolved = null;
/**
* The read-write mode of the reference. (Value is one of {@link
* Reference.READ}, {@link Reference.RW}, {@link Reference.WRITE}).
* @member {number} Reference#flag
* @private
*/
this.flag = flag;
if (this.isWrite()) {
/**
* If reference is writeable, this is the tree being written to it.
* @member {esprima#Node} Reference#writeExpr
*/
this.writeExpr = writeExpr;
/**
* Whether the Reference might refer to a partial value of writeExpr.
* @member {boolean} Reference#partial
*/
this.partial = partial;
/**
* Whether the Reference is to write of initialization.
* @member {boolean} Reference#init
*/
this.init = init;
}
this.__maybeImplicitGlobal = maybeImplicitGlobal;
}
/**
* Whether the reference is static.
* @method Reference#isStatic
* @return {boolean}
*/
isStatic() {
return !this.tainted && this.resolved && this.resolved.scope.isStatic();
}
/**
* Whether the reference is writeable.
* @method Reference#isWrite
* @return {boolean}
*/
isWrite() {
return !!(this.flag & Reference.WRITE);
}
/**
* Whether the reference is readable.
* @method Reference#isRead
* @return {boolean}
*/
isRead() {
return !!(this.flag & Reference.READ);
}
/**
* Whether the reference is read-only.
* @method Reference#isReadOnly
* @return {boolean}
*/
isReadOnly() {
return this.flag === Reference.READ;
}
/**
* Whether the reference is write-only.
* @method Reference#isWriteOnly
* @return {boolean}
*/
isWriteOnly() {
return this.flag === Reference.WRITE;
}
/**
* Whether the reference is read-write.
* @method Reference#isReadWrite
* @return {boolean}
*/
isReadWrite() {
return this.flag === Reference.RW;
}
}
/**
* @constant Reference.READ
* @private
*/
Reference.READ = READ;
/**
* @constant Reference.WRITE
* @private
*/
Reference.WRITE = WRITE;
/**
* @constant Reference.RW
* @private
*/
Reference.RW = RW;
/* vim: set sw=4 ts=4 et tw=80 : */

View File

@@ -0,0 +1,584 @@
/*
Copyright (C) 2015 Yusuke Suzuki <utatane.tea@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* 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.
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.
*/
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';
function traverseIdentifierInPattern(options, rootPattern, referencer, callback) {
// Call the callback at left hand identifier nodes, and Collect right hand nodes.
var visitor = new PatternVisitor(options, rootPattern, callback);
visitor.visit(rootPattern);
// Process the right hand nodes recursively.
if (referencer != null) {
visitor.rightHandNodes.forEach(referencer.visit, referencer);
}
}
// Importing ImportDeclaration.
// http://people.mozilla.org/~jorendorff/es6-draft.html#sec-moduledeclarationinstantiation
// https://github.com/estree/estree/blob/master/es6.md#importdeclaration
// FIXME: Now, we don't create module environment, because the context is
// implementation dependent.
class Importer extends esrecurse.Visitor {
constructor(declaration, referencer) {
super(null, referencer.options);
this.declaration = declaration;
this.referencer = referencer;
}
visitImport(id, specifier) {
this.referencer.visitPattern(id, (pattern) => {
this.referencer.currentScope().__define(pattern,
new Definition(
Variable.ImportBinding,
pattern,
specifier,
this.declaration,
null,
null
));
});
}
ImportNamespaceSpecifier(node) {
let local = (node.local || node.id);
if (local) {
this.visitImport(local, node);
}
}
ImportDefaultSpecifier(node) {
let local = (node.local || node.id);
this.visitImport(local, node);
}
ImportSpecifier(node) {
let local = (node.local || node.id);
if (node.name) {
this.visitImport(node.name, node);
} else {
this.visitImport(local, node);
}
}
}
// Referencing variables and creating bindings.
export default class Referencer extends esrecurse.Visitor {
constructor(options, scopeManager) {
super(null, options);
this.options = options;
this.scopeManager = scopeManager;
this.parent = null;
this.isInnerMethodDefinition = false;
}
currentScope() {
return this.scopeManager.__currentScope;
}
close(node) {
while (this.currentScope() && node === this.currentScope().block) {
this.scopeManager.__currentScope = this.currentScope().__close(this.scopeManager);
}
}
pushInnerMethodDefinition(isInnerMethodDefinition) {
var previous = this.isInnerMethodDefinition;
this.isInnerMethodDefinition = isInnerMethodDefinition;
return previous;
}
popInnerMethodDefinition(isInnerMethodDefinition) {
this.isInnerMethodDefinition = isInnerMethodDefinition;
}
materializeTDZScope(node, iterationNode) {
// http://people.mozilla.org/~jorendorff/es6-draft.html#sec-runtime-semantics-forin-div-ofexpressionevaluation-abstract-operation
// TDZ scope hides the declaration's names.
this.scopeManager.__nestTDZScope(node, iterationNode);
this.visitVariableDeclaration(this.currentScope(), Variable.TDZ, iterationNode.left, 0, true);
}
materializeIterationScope(node) {
// Generate iteration scope for upper ForIn/ForOf Statements.
var letOrConstDecl;
this.scopeManager.__nestForScope(node);
letOrConstDecl = node.left;
this.visitVariableDeclaration(this.currentScope(), Variable.Variable, letOrConstDecl, 0);
this.visitPattern(letOrConstDecl.declarations[0].id, (pattern) => {
this.currentScope().__referencing(pattern, Reference.WRITE, node.right, null, true, true);
});
}
referencingDefaultValue(pattern, assignments, maybeImplicitGlobal, init) {
const scope = this.currentScope();
assignments.forEach(assignment => {
scope.__referencing(
pattern,
Reference.WRITE,
assignment.right,
maybeImplicitGlobal,
pattern !== assignment.left,
init);
});
}
visitPattern(node, options, callback) {
if (typeof options === 'function') {
callback = options;
options = {processRightHandNodes: false}
}
traverseIdentifierInPattern(
this.options,
node,
options.processRightHandNodes ? this : null,
callback);
}
visitFunction(node) {
var i, iz;
// FunctionDeclaration name is defined in upper scope
// NOTE: Not referring variableScope. It is intended.
// Since
// in ES5, FunctionDeclaration should be in FunctionBody.
// in ES6, FunctionDeclaration should be block scoped.
if (node.type === Syntax.FunctionDeclaration) {
// id is defined in upper scope
this.currentScope().__define(node.id,
new Definition(
Variable.FunctionName,
node.id,
node,
null,
null,
null
));
}
// FunctionExpression with name creates its special scope;
// FunctionExpressionNameScope.
if (node.type === Syntax.FunctionExpression && node.id) {
this.scopeManager.__nestFunctionExpressionNameScope(node);
}
// Consider this function is in the MethodDefinition.
this.scopeManager.__nestFunctionScope(node, this.isInnerMethodDefinition);
// Process parameter declarations.
for (i = 0, iz = node.params.length; i < iz; ++i) {
this.visitPattern(node.params[i], {processRightHandNodes: true}, (pattern, info) => {
this.currentScope().__define(pattern,
new ParameterDefinition(
pattern,
node,
i,
info.rest
));
this.referencingDefaultValue(pattern, info.assignments, null, true);
});
}
// if there's a rest argument, add that
if (node.rest) {
this.visitPattern({
type: 'RestElement',
argument: node.rest
}, (pattern) => {
this.currentScope().__define(pattern,
new ParameterDefinition(
pattern,
node,
node.params.length,
true
));
});
}
// 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);
}
visitClass(node) {
if (node.type === Syntax.ClassDeclaration) {
this.currentScope().__define(node.id,
new Definition(
Variable.ClassName,
node.id,
node,
null,
null,
null
));
}
// FIXME: Maybe consider TDZ.
this.visit(node.superClass);
this.scopeManager.__nestClassScope(node);
if (node.id) {
this.currentScope().__define(node.id,
new Definition(
Variable.ClassName,
node.id,
node
));
}
this.visit(node.body);
this.close(node);
}
visitProperty(node) {
var previous, isMethodDefinition;
if (node.computed) {
this.visit(node.key);
}
isMethodDefinition = node.type === Syntax.MethodDefinition;
if (isMethodDefinition) {
previous = this.pushInnerMethodDefinition(true);
}
this.visit(node.value);
if (isMethodDefinition) {
this.popInnerMethodDefinition(previous);
}
}
visitForIn(node) {
if (node.left.type === Syntax.VariableDeclaration && node.left.kind !== 'var') {
this.materializeTDZScope(node.right, node);
this.visit(node.right);
this.close(node.right);
this.materializeIterationScope(node);
this.visit(node.body);
this.close(node);
} else {
if (node.left.type === Syntax.VariableDeclaration) {
this.visit(node.left);
this.visitPattern(node.left.declarations[0].id, (pattern) => {
this.currentScope().__referencing(pattern, Reference.WRITE, node.right, null, true, true);
});
} else {
this.visitPattern(node.left, {processRightHandNodes: true}, (pattern, info) => {
var maybeImplicitGlobal = null;
if (!this.currentScope().isStrict) {
maybeImplicitGlobal = {
pattern: pattern,
node: node
};
}
this.referencingDefaultValue(pattern, info.assignments, maybeImplicitGlobal, false);
this.currentScope().__referencing(pattern, Reference.WRITE, node.right, maybeImplicitGlobal, true, false);
});
}
this.visit(node.right);
this.visit(node.body);
}
}
visitVariableDeclaration(variableTargetScope, type, node, index, fromTDZ) {
// If this was called to initialize a TDZ scope, this needs to make definitions, but doesn't make references.
var decl, init;
decl = node.declarations[index];
init = decl.init;
this.visitPattern(decl.id, {processRightHandNodes: !fromTDZ}, (pattern, info) => {
variableTargetScope.__define(pattern,
new Definition(
type,
pattern,
decl,
node,
index,
node.kind
));
if (!fromTDZ) {
this.referencingDefaultValue(pattern, info.assignments, null, true);
}
if (init) {
this.currentScope().__referencing(pattern, Reference.WRITE, init, null, !info.topLevel, true);
}
});
}
AssignmentExpression(node) {
if (PatternVisitor.isPattern(node.left)) {
if (node.operator === '=') {
this.visitPattern(node.left, {processRightHandNodes: true}, (pattern, info) => {
var maybeImplicitGlobal = null;
if (!this.currentScope().isStrict) {
maybeImplicitGlobal = {
pattern: pattern,
node: node
};
}
this.referencingDefaultValue(pattern, info.assignments, maybeImplicitGlobal, false);
this.currentScope().__referencing(pattern, Reference.WRITE, node.right, maybeImplicitGlobal, !info.topLevel, false);
});
} else {
this.currentScope().__referencing(node.left, Reference.RW, node.right);
}
} else {
this.visit(node.left);
}
this.visit(node.right);
}
CatchClause(node) {
this.scopeManager.__nestCatchScope(node);
this.visitPattern(node.param, {processRightHandNodes: true}, (pattern, info) => {
this.currentScope().__define(pattern,
new Definition(
Variable.CatchClause,
node.param,
node,
null,
null,
null
));
this.referencingDefaultValue(pattern, info.assignments, null, true);
});
this.visit(node.body);
this.close(node);
}
Program(node) {
this.scopeManager.__nestGlobalScope(node);
if (this.scopeManager.__isNodejsScope()) {
// Force strictness of GlobalScope to false when using node.js scope.
this.currentScope().isStrict = false;
this.scopeManager.__nestFunctionScope(node, false);
}
if (this.scopeManager.__isES6() && this.scopeManager.isModule()) {
this.scopeManager.__nestModuleScope(node);
}
if (this.scopeManager.isStrictModeSupported() && this.scopeManager.isImpliedStrict()) {
this.currentScope().isStrict = true;
}
this.visitChildren(node);
this.close(node);
}
Identifier(node) {
this.currentScope().__referencing(node);
}
UpdateExpression(node) {
if (PatternVisitor.isPattern(node.argument)) {
this.currentScope().__referencing(node.argument, Reference.RW, null);
} else {
this.visitChildren(node);
}
}
MemberExpression(node) {
this.visit(node.object);
if (node.computed) {
this.visit(node.property);
}
}
Property(node) {
this.visitProperty(node);
}
MethodDefinition(node) {
this.visitProperty(node);
}
BreakStatement() {}
ContinueStatement() {}
LabeledStatement(node) {
this.visit(node.body);
}
ForStatement(node) {
// Create ForStatement declaration.
// NOTE: In ES6, ForStatement dynamically generates
// per iteration environment. However, escope is
// a static analyzer, we only generate one scope for ForStatement.
if (node.init && node.init.type === Syntax.VariableDeclaration && node.init.kind !== 'var') {
this.scopeManager.__nestForScope(node);
}
this.visitChildren(node);
this.close(node);
}
ClassExpression(node) {
this.visitClass(node);
}
ClassDeclaration(node) {
this.visitClass(node);
}
CallExpression(node) {
// Check this is direct call to eval
if (!this.scopeManager.__ignoreEval() && node.callee.type === Syntax.Identifier && node.callee.name === 'eval') {
// NOTE: This should be `variableScope`. Since direct eval call always creates Lexical environment and
// let / const should be enclosed into it. Only VariableDeclaration affects on the caller's environment.
this.currentScope().variableScope.__detectEval();
}
this.visitChildren(node);
}
BlockStatement(node) {
if (this.scopeManager.__isES6()) {
this.scopeManager.__nestBlockScope(node);
}
this.visitChildren(node);
this.close(node);
}
ThisExpression() {
this.currentScope().variableScope.__detectThis();
}
WithStatement(node) {
this.visit(node.object);
// Then nest scope for WithStatement.
this.scopeManager.__nestWithScope(node);
this.visit(node.body);
this.close(node);
}
VariableDeclaration(node) {
var variableTargetScope, i, iz, decl;
variableTargetScope = (node.kind === 'var') ? this.currentScope().variableScope : this.currentScope();
for (i = 0, iz = node.declarations.length; i < iz; ++i) {
decl = node.declarations[i];
this.visitVariableDeclaration(variableTargetScope, Variable.Variable, node, i);
if (decl.init) {
this.visit(decl.init);
}
}
}
// sec 13.11.8
SwitchStatement(node) {
var i, iz;
this.visit(node.discriminant);
if (this.scopeManager.__isES6()) {
this.scopeManager.__nestSwitchScope(node);
}
for (i = 0, iz = node.cases.length; i < iz; ++i) {
this.visit(node.cases[i]);
}
this.close(node);
}
FunctionDeclaration(node) {
this.visitFunction(node);
}
FunctionExpression(node) {
this.visitFunction(node);
}
ForOfStatement(node) {
this.visitForIn(node);
}
ForInStatement(node) {
this.visitForIn(node);
}
ArrowFunctionExpression(node) {
this.visitFunction(node);
}
ImportDeclaration(node) {
var importer;
assert(this.scopeManager.__isES6() && this.scopeManager.isModule(), 'ImportDeclaration should appear when the mode is ES6 and in the module context.');
importer = new Importer(node, this);
importer.visit(node);
}
visitExportDeclaration(node) {
if (node.source) {
return;
}
if (node.declaration) {
this.visit(node.declaration);
return;
}
this.visitChildren(node);
}
ExportDeclaration(node) {
this.visitExportDeclaration(node);
}
ExportNamedDeclaration(node) {
this.visitExportDeclaration(node);
}
ExportSpecifier(node) {
let local = (node.id || node.local);
this.visit(local);
}
MetaProperty() {
// do nothing.
}
}
/* vim: set sw=4 ts=4 et tw=80 : */

View File

@@ -0,0 +1,245 @@
/*
Copyright (C) 2015 Yusuke Suzuki <utatane.tea@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* 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.
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.
*/
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';
/**
* @class ScopeManager
*/
export default class ScopeManager {
constructor(options) {
this.scopes = [];
this.globalScope = null;
this.__nodeToScope = new WeakMap();
this.__currentScope = null;
this.__options = options;
this.__declaredVariables = new WeakMap();
}
__useDirective() {
return this.__options.directive;
}
__isOptimistic() {
return this.__options.optimistic;
}
__ignoreEval() {
return this.__options.ignoreEval;
}
__isNodejsScope() {
return this.__options.nodejsScope;
}
isModule() {
return this.__options.sourceType === 'module';
}
isImpliedStrict() {
return this.__options.impliedStrict;
}
isStrictModeSupported() {
return this.__options.ecmaVersion >= 5;
}
// Returns appropriate scope for this node.
__get(node) {
return this.__nodeToScope.get(node);
}
/**
* Get variables that are declared by the node.
*
* "are declared by the node" means the node is same as `Variable.defs[].node` or `Variable.defs[].parent`.
* If the node declares nothing, this method returns an empty array.
* CAUTION: This API is experimental. See https://github.com/estools/escope/pull/69 for more details.
*
* @param {Esprima.Node} node - a node to get.
* @returns {Variable[]} variables that declared by the node.
*/
getDeclaredVariables(node) {
return this.__declaredVariables.get(node) || [];
}
/**
* acquire scope from node.
* @method ScopeManager#acquire
* @param {Esprima.Node} node - node for the acquired scope.
* @param {boolean=} inner - look up the most inner scope, default value is false.
* @return {Scope?}
*/
acquire(node, inner) {
var scopes, scope, i, iz;
function predicate(scope) {
if (scope.type === 'function' && scope.functionExpressionScope) {
return false;
}
if (scope.type === 'TDZ') {
return false;
}
return true;
}
scopes = this.__get(node);
if (!scopes || scopes.length === 0) {
return null;
}
// Heuristic selection from all scopes.
// If you would like to get all scopes, please use ScopeManager#acquireAll.
if (scopes.length === 1) {
return scopes[0];
}
if (inner) {
for (i = scopes.length - 1; i >= 0; --i) {
scope = scopes[i];
if (predicate(scope)) {
return scope;
}
}
} else {
for (i = 0, iz = scopes.length; i < iz; ++i) {
scope = scopes[i];
if (predicate(scope)) {
return scope;
}
}
}
return null;
}
/**
* acquire all scopes from node.
* @method ScopeManager#acquireAll
* @param {Esprima.Node} node - node for the acquired scope.
* @return {Scope[]?}
*/
acquireAll(node) {
return this.__get(node);
}
/**
* release the node.
* @method ScopeManager#release
* @param {Esprima.Node} node - releasing node.
* @param {boolean=} inner - look up the most inner scope, default value is false.
* @return {Scope?} upper scope for the node.
*/
release(node, inner) {
var scopes, scope;
scopes = this.__get(node);
if (scopes && scopes.length) {
scope = scopes[0].upper;
if (!scope) {
return null;
}
return this.acquire(scope.block, inner);
}
return null;
}
attach() { }
detach() { }
__nestScope(scope) {
if (scope instanceof GlobalScope) {
assert(this.__currentScope === null);
this.globalScope = scope;
}
this.__currentScope = scope;
return scope;
}
__nestGlobalScope(node) {
return this.__nestScope(new GlobalScope(this, node));
}
__nestBlockScope(node, isMethodDefinition) {
return this.__nestScope(new BlockScope(this, this.__currentScope, node));
}
__nestFunctionScope(node, isMethodDefinition) {
return this.__nestScope(new FunctionScope(this, this.__currentScope, node, isMethodDefinition));
}
__nestForScope(node) {
return this.__nestScope(new ForScope(this, this.__currentScope, node));
}
__nestCatchScope(node) {
return this.__nestScope(new CatchScope(this, this.__currentScope, node));
}
__nestWithScope(node) {
return this.__nestScope(new WithScope(this, this.__currentScope, node));
}
__nestClassScope(node) {
return this.__nestScope(new ClassScope(this, this.__currentScope, node));
}
__nestSwitchScope(node) {
return this.__nestScope(new SwitchScope(this, this.__currentScope, node));
}
__nestModuleScope(node) {
return this.__nestScope(new ModuleScope(this, this.__currentScope, node));
}
__nestTDZScope(node) {
return this.__nestScope(new TDZScope(this, this.__currentScope, node));
}
__nestFunctionExpressionNameScope(node) {
return this.__nestScope(new FunctionExpressionNameScope(this, this.__currentScope, node));
}
__isES6() {
return this.__options.ecmaVersion >= 6;
}
}
/* vim: set sw=4 ts=4 et tw=80 : */

View File

@@ -0,0 +1,647 @@
/*
Copyright (C) 2015 Yusuke Suzuki <utatane.tea@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* 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.
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.
*/
import { Syntax } from 'estraverse';
import Map from 'es6-map';
import Reference from './reference';
import Variable from './variable';
import Definition from './definition';
import assert from 'assert';
function isStrictScope(scope, block, isMethodDefinition, useDirective) {
var body, i, iz, stmt, expr;
// When upper scope is exists and strict, inner scope is also strict.
if (scope.upper && scope.upper.isStrict) {
return true;
}
// ArrowFunctionExpression's scope is always strict scope.
if (block.type === Syntax.ArrowFunctionExpression) {
return true;
}
if (isMethodDefinition) {
return true;
}
if (scope.type === 'class' || scope.type === 'module') {
return true;
}
if (scope.type === 'block' || scope.type === 'switch') {
return false;
}
if (scope.type === 'function') {
if (block.type === Syntax.Program) {
body = block;
} else {
body = block.body;
}
} else if (scope.type === 'global') {
body = block;
} else {
return false;
}
// Search 'use strict' directive.
if (useDirective) {
for (i = 0, iz = body.body.length; i < iz; ++i) {
stmt = body.body[i];
if (stmt.type !== Syntax.DirectiveStatement) {
break;
}
if (stmt.raw === '"use strict"' || stmt.raw === '\'use strict\'') {
return true;
}
}
} else {
for (i = 0, iz = body.body.length; i < iz; ++i) {
stmt = body.body[i];
if (stmt.type !== Syntax.ExpressionStatement) {
break;
}
expr = stmt.expression;
if (expr.type !== Syntax.Literal || typeof expr.value !== 'string') {
break;
}
if (expr.raw != null) {
if (expr.raw === '"use strict"' || expr.raw === '\'use strict\'') {
return true;
}
} else {
if (expr.value === 'use strict') {
return true;
}
}
}
}
return false;
}
function registerScope(scopeManager, scope) {
var scopes;
scopeManager.scopes.push(scope);
scopes = scopeManager.__nodeToScope.get(scope.block);
if (scopes) {
scopes.push(scope);
} else {
scopeManager.__nodeToScope.set(scope.block, [ scope ]);
}
}
function shouldBeStatically(def) {
return (
(def.type === Variable.ClassName) ||
(def.type === Variable.Variable && def.parent.kind !== 'var')
);
}
/**
* @class Scope
*/
export default class Scope {
constructor(scopeManager, type, upperScope, block, isMethodDefinition) {
/**
* One of 'TDZ', 'module', 'block', 'switch', 'function', 'catch', 'with', 'function', 'class', 'global'.
* @member {String} Scope#type
*/
this.type = type;
/**
* The scoped {@link Variable}s of this scope, as <code>{ Variable.name
* : Variable }</code>.
* @member {Map} Scope#set
*/
this.set = new Map();
/**
* The tainted variables of this scope, as <code>{ Variable.name :
* boolean }</code>.
* @member {Map} Scope#taints */
this.taints = new Map();
/**
* Generally, through the lexical scoping of JS you can always know
* which variable an identifier in the source code refers to. There are
* a few exceptions to this rule. With 'global' and 'with' scopes you
* can only decide at runtime which variable a reference refers to.
* Moreover, if 'eval()' is used in a scope, it might introduce new
* bindings in this or its parent scopes.
* All those scopes are considered 'dynamic'.
* @member {boolean} Scope#dynamic
*/
this.dynamic = this.type === 'global' || this.type === 'with';
/**
* A reference to the scope-defining syntax node.
* @member {esprima.Node} Scope#block
*/
this.block = block;
/**
* The {@link Reference|references} that are not resolved with this scope.
* @member {Reference[]} Scope#through
*/
this.through = [];
/**
* The scoped {@link Variable}s of this scope. In the case of a
* 'function' scope this includes the automatic argument <em>arguments</em> as
* its first element, as well as all further formal arguments.
* @member {Variable[]} Scope#variables
*/
this.variables = [];
/**
* Any variable {@link Reference|reference} found in this scope. This
* includes occurrences of local variables as well as variables from
* parent scopes (including the global scope). For local variables
* this also includes defining occurrences (like in a 'var' statement).
* In a 'function' scope this does not include the occurrences of the
* formal parameter in the parameter list.
* @member {Reference[]} Scope#references
*/
this.references = [];
/**
* For 'global' and 'function' scopes, this is a self-reference. For
* other scope types this is the <em>variableScope</em> value of the
* parent scope.
* @member {Scope} Scope#variableScope
*/
this.variableScope =
(this.type === 'global' || this.type === 'function' || this.type === 'module') ? this : upperScope.variableScope;
/**
* Whether this scope is created by a FunctionExpression.
* @member {boolean} Scope#functionExpressionScope
*/
this.functionExpressionScope = false;
/**
* Whether this is a scope that contains an 'eval()' invocation.
* @member {boolean} Scope#directCallToEvalScope
*/
this.directCallToEvalScope = false;
/**
* @member {boolean} Scope#thisFound
*/
this.thisFound = false;
this.__left = [];
/**
* Reference to the parent {@link Scope|scope}.
* @member {Scope} Scope#upper
*/
this.upper = upperScope;
/**
* Whether 'use strict' is in effect in this scope.
* @member {boolean} Scope#isStrict
*/
this.isStrict = isStrictScope(this, block, isMethodDefinition, scopeManager.__useDirective());
/**
* List of nested {@link Scope}s.
* @member {Scope[]} Scope#childScopes
*/
this.childScopes = [];
if (this.upper) {
this.upper.childScopes.push(this);
}
this.__declaredVariables = scopeManager.__declaredVariables;
registerScope(scopeManager, this);
}
__shouldStaticallyClose(scopeManager) {
return (!this.dynamic || scopeManager.__isOptimistic());
}
__shouldStaticallyCloseForGlobal(ref) {
// On global scope, let/const/class declarations should be resolved statically.
var name = ref.identifier.name;
if (!this.set.has(name)) {
return false;
}
var variable = this.set.get(name);
var defs = variable.defs;
return defs.length > 0 && defs.every(shouldBeStatically);
}
__staticCloseRef(ref) {
if (!this.__resolve(ref)) {
this.__delegateToUpperScope(ref);
}
}
__dynamicCloseRef(ref) {
// notify all names are through to global
let current = this;
do {
current.through.push(ref);
current = current.upper;
} while (current);
}
__globalCloseRef(ref) {
// let/const/class declarations should be resolved statically.
// others should be resolved dynamically.
if (this.__shouldStaticallyCloseForGlobal(ref)) {
this.__staticCloseRef(ref);
} else {
this.__dynamicCloseRef(ref);
}
}
__close(scopeManager) {
var closeRef;
if (this.__shouldStaticallyClose(scopeManager)) {
closeRef = this.__staticCloseRef;
} else if (this.type !== 'global') {
closeRef = this.__dynamicCloseRef;
} else {
closeRef = this.__globalCloseRef;
}
// Try Resolving all references in this scope.
for (let i = 0, iz = this.__left.length; i < iz; ++i) {
let ref = this.__left[i];
closeRef.call(this, ref);
}
this.__left = null;
return this.upper;
}
__resolve(ref) {
var variable, name;
name = ref.identifier.name;
if (this.set.has(name)) {
variable = this.set.get(name);
variable.references.push(ref);
variable.stack = variable.stack && ref.from.variableScope === this.variableScope;
if (ref.tainted) {
variable.tainted = true;
this.taints.set(variable.name, true);
}
ref.resolved = variable;
return true;
}
return false;
}
__delegateToUpperScope(ref) {
if (this.upper) {
this.upper.__left.push(ref);
}
this.through.push(ref);
}
__addDeclaredVariablesOfNode(variable, node) {
if (node == null) {
return;
}
var variables = this.__declaredVariables.get(node);
if (variables == null) {
variables = [];
this.__declaredVariables.set(node, variables);
}
if (variables.indexOf(variable) === -1) {
variables.push(variable);
}
}
__defineGeneric(name, set, variables, node, def) {
var variable;
variable = set.get(name);
if (!variable) {
variable = new Variable(name, this);
set.set(name, variable);
variables.push(variable);
}
if (def) {
variable.defs.push(def);
if (def.type !== Variable.TDZ) {
this.__addDeclaredVariablesOfNode(variable, def.node);
this.__addDeclaredVariablesOfNode(variable, def.parent);
}
}
if (node) {
variable.identifiers.push(node);
}
}
__define(node, def) {
if (node && node.type === Syntax.Identifier) {
this.__defineGeneric(
node.name,
this.set,
this.variables,
node,
def);
}
}
__referencing(node, assign, writeExpr, maybeImplicitGlobal, partial, init) {
// because Array element may be null
if (!node || node.type !== Syntax.Identifier) {
return;
}
// Specially handle like `this`.
if (node.name === 'super') {
return;
}
let ref = new Reference(node, this, assign || Reference.READ, writeExpr, maybeImplicitGlobal, !!partial, !!init);
this.references.push(ref);
this.__left.push(ref);
}
__detectEval() {
var current;
current = this;
this.directCallToEvalScope = true;
do {
current.dynamic = true;
current = current.upper;
} while (current);
}
__detectThis() {
this.thisFound = true;
}
__isClosed() {
return this.__left === null;
}
/**
* returns resolved {Reference}
* @method Scope#resolve
* @param {Esprima.Identifier} ident - identifier to be resolved.
* @return {Reference}
*/
resolve(ident) {
var ref, i, iz;
assert(this.__isClosed(), 'Scope should be closed.');
assert(ident.type === Syntax.Identifier, 'Target should be identifier.');
for (i = 0, iz = this.references.length; i < iz; ++i) {
ref = this.references[i];
if (ref.identifier === ident) {
return ref;
}
}
return null;
}
/**
* returns this scope is static
* @method Scope#isStatic
* @return {boolean}
*/
isStatic() {
return !this.dynamic;
}
/**
* returns this scope has materialized arguments
* @method Scope#isArgumentsMaterialized
* @return {boolean}
*/
isArgumentsMaterialized() {
return true;
}
/**
* returns this scope has materialized `this` reference
* @method Scope#isThisMaterialized
* @return {boolean}
*/
isThisMaterialized() {
return true;
}
isUsedName(name) {
if (this.set.has(name)) {
return true;
}
for (var i = 0, iz = this.through.length; i < iz; ++i) {
if (this.through[i].identifier.name === name) {
return true;
}
}
return false;
}
}
export class GlobalScope extends Scope {
constructor(scopeManager, block) {
super(scopeManager, 'global', null, block, false);
this.implicit = {
set: new Map(),
variables: [],
/**
* List of {@link Reference}s that are left to be resolved (i.e. which
* need to be linked to the variable they refer to).
* @member {Reference[]} Scope#implicit#left
*/
left: []
};
}
__close(scopeManager) {
let implicit = [];
for (let i = 0, iz = this.__left.length; i < iz; ++i) {
let ref = this.__left[i];
if (ref.__maybeImplicitGlobal && !this.set.has(ref.identifier.name)) {
implicit.push(ref.__maybeImplicitGlobal);
}
}
// create an implicit global variable from assignment expression
for (let i = 0, iz = implicit.length; i < iz; ++i) {
let info = implicit[i];
this.__defineImplicit(info.pattern,
new Definition(
Variable.ImplicitGlobalVariable,
info.pattern,
info.node,
null,
null,
null
));
}
this.implicit.left = this.__left;
return super.__close(scopeManager);
}
__defineImplicit(node, def) {
if (node && node.type === Syntax.Identifier) {
this.__defineGeneric(
node.name,
this.implicit.set,
this.implicit.variables,
node,
def);
}
}
}
export class ModuleScope extends Scope {
constructor(scopeManager, upperScope, block) {
super(scopeManager, 'module', upperScope, block, false);
}
}
export class FunctionExpressionNameScope extends Scope {
constructor(scopeManager, upperScope, block) {
super(scopeManager, 'function-expression-name', upperScope, block, false);
this.__define(block.id,
new Definition(
Variable.FunctionName,
block.id,
block,
null,
null,
null
));
this.functionExpressionScope = true;
}
}
export class CatchScope extends Scope {
constructor(scopeManager, upperScope, block) {
super(scopeManager, 'catch', upperScope, block, false);
}
}
export class WithScope extends Scope {
constructor(scopeManager, upperScope, block) {
super(scopeManager, 'with', upperScope, block, false);
}
__close(scopeManager) {
if (this.__shouldStaticallyClose(scopeManager)) {
return super.__close(scopeManager);
}
for (let i = 0, iz = this.__left.length; i < iz; ++i) {
let ref = this.__left[i];
ref.tainted = true;
this.__delegateToUpperScope(ref);
}
this.__left = null;
return this.upper;
}
}
export class TDZScope extends Scope {
constructor(scopeManager, upperScope, block) {
super(scopeManager, 'TDZ', upperScope, block, false);
}
}
export class BlockScope extends Scope {
constructor(scopeManager, upperScope, block) {
super(scopeManager, 'block', upperScope, block, false);
}
}
export class SwitchScope extends Scope {
constructor(scopeManager, upperScope, block) {
super(scopeManager, 'switch', upperScope, block, false);
}
}
export class FunctionScope extends Scope {
constructor(scopeManager, upperScope, block, isMethodDefinition) {
super(scopeManager, 'function', upperScope, block, isMethodDefinition);
// section 9.2.13, FunctionDeclarationInstantiation.
// NOTE Arrow functions never have an arguments objects.
if (this.block.type !== Syntax.ArrowFunctionExpression) {
this.__defineArguments();
}
}
isArgumentsMaterialized() {
// TODO(Constellation)
// We can more aggressive on this condition like this.
//
// function t() {
// // arguments of t is always hidden.
// function arguments() {
// }
// }
if (this.block.type === Syntax.ArrowFunctionExpression) {
return false;
}
if (!this.isStatic()) {
return true;
}
let variable = this.set.get('arguments');
assert(variable, 'Always have arguments variable.');
return variable.tainted || variable.references.length !== 0;
}
isThisMaterialized() {
if (!this.isStatic()) {
return true;
}
return this.thisFound;
}
__defineArguments() {
this.__defineGeneric(
'arguments',
this.set,
this.variables,
null,
null);
this.taints.set('arguments', true);
}
}
export class ForScope extends Scope {
constructor(scopeManager, upperScope, block) {
super(scopeManager, 'for', upperScope, block, false);
}
}
export class ClassScope extends Scope {
constructor(scopeManager, upperScope, block) {
super(scopeManager, 'class', upperScope, block, false);
}
}
/* vim: set sw=4 ts=4 et tw=80 : */

View File

@@ -0,0 +1,81 @@
/*
Copyright (C) 2015 Yusuke Suzuki <utatane.tea@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* 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.
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.
*/
/**
* A Variable represents a locally scoped identifier. These include arguments to
* functions.
* @class Variable
*/
export default class Variable {
constructor(name, scope) {
/**
* The variable name, as given in the source code.
* @member {String} Variable#name
*/
this.name = name;
/**
* List of defining occurrences of this variable (like in 'var ...'
* statements or as parameter), as AST nodes.
* @member {esprima.Identifier[]} Variable#identifiers
*/
this.identifiers = [];
/**
* List of {@link Reference|references} of this variable (excluding parameter entries)
* in its defining scope and all nested scopes. For defining
* occurrences only see {@link Variable#defs}.
* @member {Reference[]} Variable#references
*/
this.references = [];
/**
* List of defining occurrences of this variable (like in 'var ...'
* statements or as parameter), as custom objects.
* @member {Definition[]} Variable#defs
*/
this.defs = [];
this.tainted = false;
/**
* Whether this is a stack variable.
* @member {boolean} Variable#stack
*/
this.stack = true;
/**
* Reference to the enclosing Scope.
* @member {Scope} Variable#scope
*/
this.scope = scope;
}
}
Variable.CatchClause = 'CatchClause';
Variable.Parameter = 'Parameter';
Variable.FunctionName = 'FunctionName';
Variable.ClassName = 'ClassName';
Variable.Variable = 'Variable';
Variable.ImportBinding = 'ImportBinding';
Variable.TDZ = 'TDZ';
Variable.ImplicitGlobalVariable = 'ImplicitGlobalVariable';
/* vim: set sw=4 ts=4 et tw=80 : */

View File

@@ -0,0 +1,56 @@
/*
Copyright (C) 2015 Yusuke Suzuki <utatane.tea@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* 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.
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.
*/
var espree = require('espree');
module.exports = function (code) {
return espree.parse(code, {
// attach range information to each node
range: true,
// attach line/column location information to each node
loc: true,
// create a top-level comments array containing all comments
comments: true,
// attach comments to the closest relevant node as leadingComments and
// trailingComments
attachComment: true,
// create a top-level tokens array containing all tokens
tokens: true,
// try to continue parsing if an error is encountered, store errors in a
// top-level errors array
tolerant: true,
// enable es6 features.
ecmaVersion: 6,
sourceType: "module"
});
};
/* vim: set sw=4 ts=4 et tw=80 : */