项目原始demo,不改动
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

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