UNPKG

3.27 kBMarkdownView Raw
1Escope ([escope](http://github.com/estools/escope)) is
2[ECMAScript](http://www.ecma-international.org/publications/standards/Ecma-262.htm)
3scope analyzer extracted from [esmangle project](http://github.com/estools/esmangle).
4
5[![Build Status](https://travis-ci.org/estools/escope.png?branch=master)](https://travis-ci.org/estools/escope)
6
7### Example
8
9```js
10var escope = require('escope');
11var esprima = require('esprima');
12var estraverse = require('estraverse');
13
14var ast = esprima.parse(code);
15var scopeManager = escope.analyze(ast);
16
17var currentScope = scopeManager.acquire(ast); // global scope
18
19estraverse.traverse(ast, {
20 enter: function(node, parent) {
21 // do stuff
22
23 if (/Function/.test(node.type)) {
24 currentScope = scopeManager.acquire(node); // get current function scope
25 }
26 },
27 leave: function(node, parent) {
28 if (/Function/.test(node.type)) {
29 currentScope = currentScope.upper; // set to parent scope
30 }
31
32 // do stuff
33 }
34});
35```
36
37### Document
38
39Generated JSDoc is [here](http://estools.github.io/escope/).
40
41### Demos and Tools
42
43Demonstration 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)
44
45![Demo](https://f.cloud.github.com/assets/75759/462920/7aa6dd40-b4f5-11e2-9f07-9f4e8d0415f9.gif)
46
47
48And there are tools constructed on Escope.
49
50- [Esmangle](https://github.com/estools/esmangle) is a minifier / mangler / optimizer.
51- [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.
52- [Esgoggles](https://github.com/keeyipchan/esgoggles) is JavaScript code browser.
53
54
55### License
56
57Copyright (C) 2012-2013 [Yusuke Suzuki](http://github.com/Constellation)
58 (twitter: [@Constellation](http://twitter.com/Constellation)) and other contributors.
59
60Redistribution and use in source and binary forms, with or without
61modification, are permitted provided that the following conditions are met:
62
63 * Redistributions of source code must retain the above copyright
64 notice, this list of conditions and the following disclaimer.
65
66 * Redistributions in binary form must reproduce the above copyright
67 notice, this list of conditions and the following disclaimer in the
68 documentation and/or other materials provided with the distribution.
69
70THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
71AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
72IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
73ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
74DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
75(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
76LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
77ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
78(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
79THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.