1 | Shift Code Generator
|
2 | ====================
|
3 |
|
4 | ## About
|
5 |
|
6 | This module provides a code generator for [Shift format](https://github.com/shapesecurity/shift-spec) ASTs.
|
7 |
|
8 | ## Status
|
9 |
|
10 | [Stable](http://nodejs.org/api/documentation.html#documentation_stability_index).
|
11 |
|
12 |
|
13 | ## Installation
|
14 |
|
15 | ```sh
|
16 | npm install shift-codegen
|
17 | ```
|
18 |
|
19 |
|
20 | ## Usage
|
21 |
|
22 | ```js
|
23 | import codegen from "shift-codegen";
|
24 | let programSource = codegen(/* Shift format AST */);
|
25 | ```
|
26 |
|
27 |
|
28 | ## Note on IfStatements
|
29 |
|
30 | When presented with a valid structure that represents an IfStatement nested inside the consequent of an IfStatement that also has an alternate, we choose to generate code that preserves the intent of the AST rather than generate
|
31 | valid code that executes in an unintended manner.
|
32 |
|
33 | e.g., when generating code for an AST that *looks* like it represents this:
|
34 |
|
35 | ```js
|
36 | if (a)
|
37 | if (b) foo()
|
38 | else bar()
|
39 | ```
|
40 |
|
41 | We generate the following instead:
|
42 |
|
43 | ```js
|
44 | if (a) {
|
45 | if (b) foo()
|
46 | } else bar()
|
47 | ```
|
48 |
|
49 | The following parse of this code includes a BlockStatement and a Block wrapping the consequent of the outer IfStatement. This is considered optimal because the original AST is impossible to have been generated by a parse of actual JavaScript and could only occur from programmatic generation and that this resulting structure would have been the original intent.
|
50 |
|
51 |
|
52 | ## Contributing
|
53 |
|
54 | * Open a Github issue with a description of your desired change. If one exists already, leave a message stating that you are working on it with the date you expect it to be complete.
|
55 | * Fork this repo, and clone the forked repo.
|
56 | * Install dependencies with `npm install`.
|
57 | * Build and test in your environment with `npm run build && npm test`.
|
58 | * Create a feature branch. Make your changes. Add tests.
|
59 | * Build and test in your environment with `npm run build && npm test`.
|
60 | * Make a commit that includes the text "fixes #*XX*" where *XX* is the Github issue.
|
61 | * Open a Pull Request on Github.
|
62 |
|
63 |
|
64 | ## License
|
65 |
|
66 | Copyright 2014 Shape Security, Inc.
|
67 |
|
68 | Licensed under the Apache License, Version 2.0 (the "License");
|
69 | you may not use this file except in compliance with the License.
|
70 | You may obtain a copy of the License at
|
71 |
|
72 | http://www.apache.org/licenses/LICENSE-2.0
|
73 |
|
74 | Unless required by applicable law or agreed to in writing, software
|
75 | distributed under the License is distributed on an "AS IS" BASIS,
|
76 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
77 | See the License for the specific language governing permissions and
|
78 | limitations under the License.
|