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.

84 lines
3.2 KiB

  1. ## Escodegen
  2. [![npm version](https://badge.fury.io/js/escodegen.svg)](http://badge.fury.io/js/escodegen)
  3. [![Build Status](https://secure.travis-ci.org/estools/escodegen.svg)](http://travis-ci.org/estools/escodegen)
  4. [![Dependency Status](https://david-dm.org/estools/escodegen.svg)](https://david-dm.org/estools/escodegen)
  5. [![devDependency Status](https://david-dm.org/estools/escodegen/dev-status.svg)](https://david-dm.org/estools/escodegen#info=devDependencies)
  6. Escodegen ([escodegen](http://github.com/estools/escodegen)) is an
  7. [ECMAScript](http://www.ecma-international.org/publications/standards/Ecma-262.htm)
  8. (also popularly known as [JavaScript](http://en.wikipedia.org/wiki/JavaScript))
  9. code generator from [Mozilla's Parser API](https://developer.mozilla.org/en/SpiderMonkey/Parser_API)
  10. AST. See the [online generator](https://estools.github.io/escodegen/demo/index.html)
  11. for a demo.
  12. ### Install
  13. Escodegen can be used in a web browser:
  14. <script src="escodegen.browser.js"></script>
  15. escodegen.browser.js can be found in tagged revisions on GitHub.
  16. Or in a Node.js application via npm:
  17. npm install escodegen
  18. ### Usage
  19. A simple example: the program
  20. escodegen.generate({
  21. type: 'BinaryExpression',
  22. operator: '+',
  23. left: { type: 'Literal', value: 40 },
  24. right: { type: 'Literal', value: 2 }
  25. });
  26. produces the string `'40 + 2'`.
  27. See the [API page](https://github.com/estools/escodegen/wiki/API) for
  28. options. To run the tests, execute `npm test` in the root directory.
  29. ### Building browser bundle / minified browser bundle
  30. At first, execute `npm install` to install the all dev dependencies.
  31. After that,
  32. npm run-script build
  33. will generate `escodegen.browser.js`, which can be used in browser environments.
  34. And,
  35. npm run-script build-min
  36. will generate the minified file `escodegen.browser.min.js`.
  37. ### License
  38. #### Escodegen
  39. Copyright (C) 2012 [Yusuke Suzuki](http://github.com/Constellation)
  40. (twitter: [@Constellation](http://twitter.com/Constellation)) and other contributors.
  41. Redistribution and use in source and binary forms, with or without
  42. modification, are permitted provided that the following conditions are met:
  43. * Redistributions of source code must retain the above copyright
  44. notice, this list of conditions and the following disclaimer.
  45. * Redistributions in binary form must reproduce the above copyright
  46. notice, this list of conditions and the following disclaimer in the
  47. documentation and/or other materials provided with the distribution.
  48. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  49. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  50. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  51. ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  52. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  53. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  54. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  55. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  56. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  57. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.