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 |
|
7 | Escodegen ([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))
|
10 | code generator from [Mozilla's Parser API](https://developer.mozilla.org/en/SpiderMonkey/Parser_API)
|
11 | AST. See the [online generator](https://estools.github.io/escodegen/demo/index.html)
|
12 | for a demo.
|
13 |
|
14 |
|
15 | ### Install
|
16 |
|
17 | Escodegen can be used in a web browser:
|
18 |
|
19 | <script src="escodegen.browser.js"></script>
|
20 |
|
21 | escodegen.browser.js can be found in tagged revisions on GitHub.
|
22 |
|
23 | Or in a Node.js application via npm:
|
24 |
|
25 | npm install escodegen
|
26 |
|
27 | ### Usage
|
28 |
|
29 | A 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 |
|
38 | produces the string `'40 + 2'`.
|
39 |
|
40 | See the [API page](https://github.com/estools/escodegen/wiki/API) for
|
41 | options. To run the tests, execute `npm test` in the root directory.
|
42 |
|
43 | ### Building browser bundle / minified browser bundle
|
44 |
|
45 | At first, execute `npm install` to install the all dev dependencies.
|
46 | After that,
|
47 |
|
48 | npm run-script build
|
49 |
|
50 | will generate `escodegen.browser.js`, which can be used in browser environments.
|
51 |
|
52 | And,
|
53 |
|
54 | npm run-script build-min
|
55 |
|
56 | will generate the minified file `escodegen.browser.min.js`.
|
57 |
|
58 | ### License
|
59 |
|
60 | #### Escodegen
|
61 |
|
62 | Copyright (C) 2012 [Yusuke Suzuki](http://github.com/Constellation)
|
63 | (twitter: [@Constellation](http://twitter.com/Constellation)) and other contributors.
|
64 |
|
65 | Redistribution and use in source and binary forms, with or without
|
66 | modification, 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 |
|
75 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
76 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
77 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
78 | ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
79 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
80 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
81 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
82 | ON 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
|
84 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
85 |
|
86 | #### source-map
|
87 |
|
88 | SourceNodeMocks has a limited interface of mozilla/source-map SourceNode implementations.
|
89 |
|
90 | Copyright (c) 2009-2011, Mozilla Foundation and contributors
|
91 | All rights reserved.
|
92 |
|
93 | Redistribution and use in source and binary forms, with or without
|
94 | modification, are permitted provided that the following conditions are met:
|
95 |
|
96 | * Redistributions of source code must retain the above copyright notice, this
|
97 | list of conditions and the following disclaimer.
|
98 |
|
99 | * Redistributions in binary form must reproduce the above copyright notice,
|
100 | this list of conditions and the following disclaimer in the documentation
|
101 | and/or other materials provided with the distribution.
|
102 |
|
103 | * Neither the names of the Mozilla Foundation nor the names of project
|
104 | contributors may be used to endorse or promote products derived from this
|
105 | software without specific prior written permission.
|
106 |
|
107 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
108 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
109 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
110 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
111 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
112 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
113 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
114 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
115 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
116 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|