UNPKG

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