Skip to content

Commit b5d4bc5

Browse files
authored
add 6.x versioned docs (#1574)
1 parent 9805e73 commit b5d4bc5

File tree

161 files changed

+13778
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

161 files changed

+13778
-0
lines changed

website/pages/en/versions.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const React = require("react");
2+
3+
const CompLibrary = require("../../core/CompLibrary.js");
4+
const Container = CompLibrary.Container;
5+
6+
const CWD = process.cwd();
7+
const siteConfig = require(CWD + "/siteConfig.js");
8+
// const versions = require(CWD + "/versions.json");
9+
10+
class Versions extends React.Component {
11+
render() {
12+
return (
13+
<div className="pageContainer">
14+
<Container className="mainContainer">
15+
<h1>Babel Versions</h1>
16+
<div><a href={`${siteConfig.baseUrl}docs/en/next/index.html`}>Master Docs</a></div>
17+
<div><a href={`${siteConfig.baseUrl}docs/en/index.html`}>6.x Docs</a></div>
18+
</Container>
19+
</div>
20+
);
21+
}
22+
}
23+
24+
Versions.defaultProps = {
25+
language: "en",
26+
};
27+
28+
module.exports = Versions;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
# Don't edit this file directly, it was copied using scripts/download-readmes.js:
3+
id: version-6.x-babel
4+
title: babel
5+
sidebar_label: babel
6+
original_id: babel
7+
---
8+
9+
Currently unused in 6.x. You probably meant to use `babel-cli`.
10+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
---
2+
layout: docs
3+
title: .babelrc
4+
description: How to use the .babelrc
5+
permalink: /docs/usage/babelrc/
6+
:
7+
id: version-6.x-babelrc
8+
original_id: babelrc
9+
---
10+
11+
All Babel API [options](api.md) except the callbacks are allowed (because `.babelrc` files are serialized as [JSON5](https://github.com/json5/json5)).
12+
13+
**Example:**
14+
15+
```json
16+
{
17+
"plugins": ["transform-react-jsx"],
18+
"ignore": [
19+
"foo.js",
20+
"bar/**/*.js"
21+
]
22+
}
23+
```
24+
25+
## Use via `package.json`
26+
27+
You can alternatively choose to specify your `.babelrc` config from within `package.json` like so:
28+
29+
```json
30+
{
31+
"name": "my-package",
32+
"version": "1.0.0",
33+
"babel": {
34+
// my babel config here
35+
}
36+
}
37+
```
38+
39+
## `env` option
40+
41+
You can use the `env` option to set specific options when in a certain environment:
42+
43+
```json
44+
{
45+
"env": {
46+
"production": {
47+
"plugins": ["transform-react-constant-elements"]
48+
}
49+
}
50+
}
51+
```
52+
53+
Options specific to a certain environment are merged into and overwrite non-env specific options.
54+
55+
The `env` key will be taken from `process.env.BABEL_ENV`, when this is not available then it uses
56+
`process.env.NODE_ENV` if even that is not available then it defaults to `"development"`.
57+
58+
You can set this environment variable with the following:
59+
60+
**Unix**
61+
62+
At the start of a command:
63+
64+
```sh
65+
BABEL_ENV=production YOUR_COMMAND_HERE
66+
```
67+
68+
Or as a separate command:
69+
70+
```sh
71+
export BABEL_ENV=production
72+
```
73+
74+
```sh
75+
YOUR_COMMAND_HERE
76+
```
77+
78+
**Windows**
79+
80+
```sh
81+
SET BABEL_ENV=production
82+
```
83+
84+
```sh
85+
YOUR_COMMAND_HERE
86+
```
87+
88+
> If you want your command to work across platforms, you can use [`cross-env`](https://www.npmjs.com/package/cross-env)
89+
90+
## Lookup behavior
91+
92+
Babel will look for a `.babelrc` in the current directory of the file being transpiled. If one does not exist, it will travel up the directory tree until it finds either a `.babelrc`, or a `package.json` with a `"babel": {}` hash within.
93+
94+
Use `"babelrc": false` in [options](api.md#options) to stop lookup behavior, or provide the [`--no-babelrc` CLI flag](babel-cli.md#babel-ignoring-babelrc).
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
---
2+
# Don't edit this file directly, it was copied using scripts/download-readmes.js:
3+
id: version-6.x-babylon
4+
title: babylon
5+
sidebar_label: babylon
6+
original_id: babylon
7+
---
8+
9+
<p align="center">
10+
Babylon is a JavaScript parser used in <a href="https://github.com/babel/babel">Babel</a>.
11+
</p>
12+
13+
<p align="center">
14+
<a href="https://travis-ci.org/babel/babylon"><img alt="Travis Status" src="https://img.shields.io/travis/babel/babylon/master.svg?style=flat&label=travis"></a>
15+
<a href="https://codecov.io/gh/babel/babylon"><img alt="Codecov Status" src="https://img.shields.io/codecov/c/github/babel/babylon/master.svg?style=flat"></a>
16+
</p>
17+
18+
- The latest ECMAScript version enabled by default (ES2017).
19+
- Comment attachment.
20+
- Support for JSX and Flow.
21+
- Support for experimental language proposals (accepting PRs for anything at least [stage-0](https://github.com/tc39/proposals/blob/master/stage-0-proposals.md)).
22+
23+
## Credits
24+
25+
Heavily based on [acorn](https://github.com/marijnh/acorn) and [acorn-jsx](https://github.com/RReverser/acorn-jsx),
26+
thanks to the awesome work of [@RReverser](https://github.com/RReverser) and [@marijnh](https://github.com/marijnh).
27+
28+
Significant diversions are expected to occur in the future such as streaming, EBNF definitions, sweet.js integration, interspatial parsing and more.
29+
30+
## API
31+
32+
### `babylon.parse(code, [options])`
33+
34+
### `babylon.parseExpression(code, [options])`
35+
36+
`parse()` parses the provided `code` as an entire ECMAScript program, while
37+
`parseExpression()` tries to parse a single Expression with performance in
38+
mind. When in doubt, use `.parse()`.
39+
40+
### Options
41+
42+
- **allowImportExportEverywhere**: By default, `import` and `export`
43+
declarations can only appear at a program's top level. Setting this
44+
option to `true` allows them anywhere where a statement is allowed.
45+
46+
- **allowReturnOutsideFunction**: By default, a return statement at
47+
the top level raises an error. Set this to `true` to accept such
48+
code.
49+
50+
- **allowSuperOutsideMethod**: TODO
51+
52+
- **sourceType**: Indicate the mode the code should be parsed in. Can be
53+
either `"script"` or `"module"`.
54+
55+
- **sourceFilename**: Correlate output AST nodes with their source filename. Useful when generating code and source maps from the ASTs of multiple input files.
56+
57+
- **startLine**: By default, the first line of code parsed is treated as line 1. You can provide a line number to alternatively start with. Useful for integration with other source tools.
58+
59+
- **plugins**: Array containing the plugins that you want to enable.
60+
61+
- **strictMode**: TODO
62+
63+
### Output
64+
65+
Babylon generates AST according to [Babel AST format][].
66+
It is based on [ESTree spec][] with the following deviations:
67+
68+
> There is now an `estree` plugin which reverts these deviations
69+
70+
- [Literal][] token is replaced with [StringLiteral][], [NumericLiteral][], [BooleanLiteral][], [NullLiteral][], [RegExpLiteral][]
71+
- [Property][] token is replaced with [ObjectProperty][] and [ObjectMethod][]
72+
- [MethodDefinition][] is replaced with [ClassMethod][]
73+
- [Program][] and [BlockStatement][] contain additional `directives` field with [Directive][] and [DirectiveLiteral][]
74+
- [ClassMethod][], [ObjectProperty][], and [ObjectMethod][] value property's properties in [FunctionExpression][] is coerced/brought into the main method node.
75+
76+
AST for JSX code is based on [Facebook JSX AST][] with the addition of one node type:
77+
78+
- `JSXText`
79+
80+
[Babel AST format]: https://github.com/babel/babylon/blob/master/ast/spec.md
81+
[ESTree spec]: https://github.com/estree/estree
82+
83+
[Literal]: https://github.com/estree/estree/blob/master/es5.md#literal
84+
[Property]: https://github.com/estree/estree/blob/master/es5.md#property
85+
[MethodDefinition]: https://github.com/estree/estree/blob/master/es2015.md#methoddefinition
86+
87+
[StringLiteral]: https://github.com/babel/babylon/blob/master/ast/spec.md#stringliteral
88+
[NumericLiteral]: https://github.com/babel/babylon/blob/master/ast/spec.md#numericliteral
89+
[BooleanLiteral]: https://github.com/babel/babylon/blob/master/ast/spec.md#booleanliteral
90+
[NullLiteral]: https://github.com/babel/babylon/blob/master/ast/spec.md#nullliteral
91+
[RegExpLiteral]: https://github.com/babel/babylon/blob/master/ast/spec.md#regexpliteral
92+
[ObjectProperty]: https://github.com/babel/babylon/blob/master/ast/spec.md#objectproperty
93+
[ObjectMethod]: https://github.com/babel/babylon/blob/master/ast/spec.md#objectmethod
94+
[ClassMethod]: https://github.com/babel/babylon/blob/master/ast/spec.md#classmethod
95+
[Program]: https://github.com/babel/babylon/blob/master/ast/spec.md#programs
96+
[BlockStatement]: https://github.com/babel/babylon/blob/master/ast/spec.md#blockstatement
97+
[Directive]: https://github.com/babel/babylon/blob/master/ast/spec.md#directive
98+
[DirectiveLiteral]: https://github.com/babel/babylon/blob/master/ast/spec.md#directiveliteral
99+
[FunctionExpression]: https://github.com/babel/babylon/blob/master/ast/spec.md#functionexpression
100+
101+
[Facebook JSX AST]: https://github.com/facebook/jsx/blob/master/AST.md
102+
103+
### Semver
104+
105+
Babylon follows semver in most situations. The only thing to note is that some spec-compliancy bug fixes may be released under patch versions.
106+
107+
For example: We push a fix to early error on something like [#107](https://github.com/babel/babylon/pull/107) - multiple default exports per file. That would be considered a bug fix even though it would cause a build to fail.
108+
109+
### Example
110+
111+
```javascript
112+
require("babylon").parse("code", {
113+
// parse in strict mode and allow module declarations
114+
sourceType: "module",
115+
116+
plugins: [
117+
// enable jsx and flow syntax
118+
"jsx",
119+
"flow"
120+
]
121+
});
122+
```
123+
124+
### Plugins
125+
126+
- `estree`
127+
- `jsx`
128+
- `flow`
129+
- `doExpressions`
130+
- `objectRestSpread`
131+
- `decorators` (Based on an outdated version of the Decorators proposal. Will be removed in a future version of `Babylon`)
132+
- `classProperties`
133+
- `exportExtensions`
134+
- `asyncGenerators`
135+
- `functionBind`
136+
- `functionSent`
137+
- `dynamicImport`
138+
- `templateInvalidEscapes`
139+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
---
2+
layout: docs
3+
title: Caveats
4+
description: Just some things to keep in mind when using Babel.
5+
permalink: /docs/usage/caveats/
6+
:
7+
id: version-6.x-caveats
8+
original_id: caveats
9+
---
10+
11+
## Polyfills
12+
13+
In order for certain features to work they require certain polyfills. You can satisfy **all**
14+
Babel feature requirements by using [babel-polyfill](polyfill.md).
15+
16+
You may alternatively/selectively include what you need:
17+
18+
| Feature | Requirements |
19+
| --------------------------- | ------------------------------------------------------------------------------------- |
20+
| Async functions, Generators | [regenerator runtime](https://github.com/facebook/regenerator/tree/master/packages/regenerator-runtime) |
21+
| Array destructuring, For Of | `Symbol`, `prototype[Symbol.iterator]` |
22+
| Spread | `Array.from` |
23+
24+
There is also the `loose` option for some of these plugins.
25+
26+
## Classes
27+
28+
Built-in classes such as `Date`, `Array`, `DOM` etc cannot be properly subclassed
29+
due to limitations in ES5 (for the [es2015-classes](plugin-transform-es2015-classes.md) plugin).
30+
You can try to use [babel-plugin-transform-builtin-extend](https://github.com/loganfsmyth/babel-plugin-transform-builtin-extend) based on `Object.setPrototypeOf` and `Reflect.construct`, but it also has some limitations.
31+
32+
## ES5
33+
34+
Since Babel assumes that your code will run in an ES5 environment it uses ES5
35+
functions. So if you're using an environment that has limited or no support for
36+
ES5 such as lower versions of IE then using [babel-polyfill](polyfill.md) will add support for these methods.
37+
38+
## Internet Explorer
39+
40+
### Classes (10 and below)
41+
42+
If you're inheriting from a class then static properties are inherited from it
43+
via [\_\_proto\_\_](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/proto),
44+
this is widely supported but you may run into problems with much older browsers.
45+
46+
**NOTE:** `__proto__` is not supported on IE <= 10 so static properties
47+
**will not** be inherited. See the
48+
[protoToAssign](plugin-transform-proto-to-assign.md) for a possible work
49+
around.
50+
51+
For classes that have `super`s, the super class won't resolve correctly. You can
52+
get around this by enabling the `loose` option in the [es2015-classes](plugin-transform-es2015-classes.md) plugin.
53+
54+
### Getters/setters (8 and below)
55+
56+
In IE8 `Object.defineProperty` can only be used on DOM objects. This is
57+
unfortunate as it's required to set getters and setters. Due to this if
58+
you plan on supporting IE8 or below then the usage of getters and setters
59+
isn't recommended.
60+
61+
**Reference**: [MDN](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty#Internet_Explorer_8_specific_notes).
62+
63+
#### Modules
64+
65+
By default, when using modules with Babel a non-enumerable `__esModule` property
66+
is exported. This is done through the use of `Object.defineProperty` which is
67+
unsupported in IE8 and below. A workaround for this is to enable the `loose` option in your corresponding module plugin.

0 commit comments

Comments
 (0)