Package Exports
- shift-codegen
- shift-codegen/dist/token_stream
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (shift-codegen) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Shift Code Generator
About
This module provides a code generator for Shift format ASTs.
Status
Installation
npm install shift-codegen
Usage
import codegen from "shift-codegen";
let programSource = codegen(/* Shift format AST */);
Note on IfStatements
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 valid code that executes in an unintended manner.
e.g., when generating code for an AST that looks like it represents this:
if (a)
if (b) foo()
else bar()
We generate the following instead:
if (a) {
if (b) foo()
} else bar()
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.
Contributing
- 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.
- Fork this repo, and clone the forked repo.
- Install dependencies with
npm install
. - Build and test in your environment with
npm run build && npm test
. - Create a feature branch. Make your changes. Add tests.
- Build and test in your environment with
npm run build && npm test
. - Make a commit that includes the text "fixes #XX" where XX is the Github issue.
- Open a Pull Request on Github.
License
Copyright 2014 Shape Security, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.