# babel-to-go

> Standalone build of babylon, babel-traverse, babel-types and babel-generate for use in browsers.

Latest version **6.24.3** (published 2017-06-04) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install babel-to-go
pnpm add babel-to-go
yarn add babel-to-go
bun add babel-to-go
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 6.24.3 |
| Published | 2017-06-04 |
| First published | 2017-06-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | alastairpatrick |
| Keywords | babel |

## Links

- npm: https://www.npmjs.com/package/babel-to-go
- Repository: https://github.com/alastairpatrick/babel-to-go
- Issues: https://github.com/alastairpatrick/babel-to-go/issues
- npm.io page: https://npm.io/package/babel-to-go

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 6.24.3 (latest) — 2017-06-04
- 6.24.2 — 2017-06-03

## README

babel-to-go
===========

Standalone build of babylon (babel's parser), babel-traverse, babel-types and babel-generate. It is intended to provide only enough functionality for a browser to round trip JavaScript source code to an AST and back,
using babylon-traverse to examine and modify the tree. To reduce code size, much support for JSX, flow and other language features is removed. Additionally, source map support is removed from babel-generate.

This project is a fork of [babel-standalone](https://github.com/babel/babel-standalone), though modified to serve a different purpose. Unlike babel-standalone, Babel-to-go does _not_ search for and compile code found in the loading web page's DOM.

After gzip compression, babel-to-go.min.js is about 100KB in size. For comparison, [babel.min.js](https://github.com/babel/babel-standalone/releases) is about 200KB after compression but has 100KB more features!

Example Usage
=============

```html
<script src="babel-to-go.min.js"></script>
<script>
  var babylon = Babel.babylon;
  var traverse = Babel.traverse;
  var types = Babel.types;
  var generate = Babel.generate;

  var source = "for (var i = 0; i !== 3; ++i) {\n" +
               "  console.log('Hello, World!');\n" +
               "}\n";

  var ast = babylon.parse(source);

  traverse(ast, {
    StringLiteral: {
      exit(path) {
        path.replaceWith(types.stringLiteral(
          path.node.value.toUpperCase()));
        path.skip();
      }
    }
  });

  var result = generate(ast);
  var fn = new Function(result.code);
  fn();

  // Console output:
  // HELLO, WORLD!
  // HELLO, WORLD!
  // HELLO, WORLD!
</script>
```

Installing
==========

Installing with npm is straightforward and probably what you want to do:

```
npm install babel-to-go --save
```

Alternatively, if building babel-to-go yourself, keep in mind that babylon is a [submodule](https://github.com/blog/2104-working-with-submodules) that needs to be initialized and updated. You could do something like this to build everything, passing `--recursive` to `git clone` to initialize and update submodules:

```
$ git clone --recursive https://github.com/alastairpatrick/babel-to-go.git babel-to-go
$ cd babel-to-go
$ npm install
$ npm run build
$ npm test
```

While dependencies like babel-traverse are simply listed in package.json, babylon is a submodule. The reason is because babylon is bundled as a single packed source file, which makes it difficult to subtract the unneeded plugin code, e.g. JSX and flow. By taking the babylon code directly from its git repository via a submodule, it is possible to extract the JavaScript parser minus its plugins.

---
_Source: https://npm.io/package/babel-to-go · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
