Skip to content

Commit

Permalink
Backport changes to previous versions
Browse files Browse the repository at this point in the history
  • Loading branch information
existentialism committed Jul 10, 2019
1 parent 4605a08 commit 5a3e804
Show file tree
Hide file tree
Showing 13 changed files with 902 additions and 12 deletions.
3 changes: 0 additions & 3 deletions docs/config-files.md
Expand Up @@ -318,7 +318,6 @@ It has a few different forms:

> **Note:** This function internally makes use of [`api.cache`](#apicache) mentioned above to ensure that Babel is aware that this build depends on a specific `envName`. You should not use it alongside with `api.cache.forever()` or `api.cache.never()`.

### `api.caller(cb)`

This API is used as a way to access the `caller` data that has been passed to Babel.
Expand Down Expand Up @@ -356,5 +355,3 @@ module.exports = function(api) {
};
};
```


3 changes: 2 additions & 1 deletion docs/core.md
Expand Up @@ -303,9 +303,10 @@ Each `ConfigItem` exposes all of the information Babel knows. The fields are:
> babel.DEFAULT_EXTENSIONS: ReadonlyArray<string>
A list of default extensions supported by babel (".js", ".jsx", ".es6", ".es", ".mjs").
This list is used by @babel/register and @babel/cli to determine which files need transpiling.
This list is used by @babel/register and @babel/cli to determine which files need transpiling.
Extending this list isn't possible, however @babel/cli does provide ways to support other extensions with `--extensions`.

## Options

See [the full option list here](options.md).

26 changes: 26 additions & 0 deletions docs/plugin-syntax-dynamic-import.md
Expand Up @@ -40,6 +40,8 @@ require("@babel/core").transform("code", {

Currently, `@babel/preset-env` is unaware that using `import()` with [Webpack relies on `Promise` internally](https://webpack.js.org/guides/code-splitting/#dynamic-imports). Environments which do not have builtin support for `Promise`, like Internet Explorer, will require both the `promise` and `iterator` polyfills be added manually.

For example, with `core-js@3`:

```js
// webpack config
const config = {
Expand All @@ -61,3 +63,27 @@ import "core-js/modules/es.array.iterator";

// ...
```

This is the same for `core-js@2`, except the imports paths are slightly different:

```js
// webpack config
const config = {
entry: [
"core-js/modules/es6.promise",
"core-js/modules/es6.array.iterator",
path.resolve(__dirname, "src/main.js"),
],
// ...
};
```

or

```js
// src/main.js
import "core-js/modules/es6.promise";
import "core-js/modules/es6.array.iterator";

// ...
```
2 changes: 1 addition & 1 deletion docs/plugin-transform-runtime.md
Expand Up @@ -101,7 +101,7 @@ By default, `@babel/plugin-transform-runtime` doesn't polyfill proposals. If you
This option requires changing the dependency used to provide the necessary runtime helpers:

| `corejs` option | Install command |
|-----------------|---------------------------------------------|
| --------------- | ------------------------------------------- |
| `false` | `npm install --save @babel/runtime` |
| `2` | `npm install --save @babel/runtime-corejs2` |
| `3` | `npm install --save @babel/runtime-corejs3` |
Expand Down
3 changes: 2 additions & 1 deletion docs/preset-env.md
Expand Up @@ -197,7 +197,7 @@ Valid options include any:

- [Babel plugins](https://github.com/babel/babel/blob/master/packages/babel-preset-env/data/plugin-features.js) - both with (`@babel/plugin-transform-spread`) and without prefix (`plugin-transform-spread`) are supported.

- Built-ins (both for [core-js@2](https://github.com/babel/babel/blob/master/packages/babel-preset-env/src/polyfills/corejs2/built-in-definitions.js) and [core-js@3]([https://github.com/babel/babel/blob/master/packages/babel-preset-env/src/polyfills/corejs3/built-in-definitions.js](https://github.com/babel/babel/blob/master/packages/babel-preset-env/src/polyfills/corejs3/built-in-definitions.js)))), such as `es.map`, `es.set`, or `es.object.assign`.
- Built-ins (both for [core-js@2](https://github.com/babel/babel/blob/master/packages/babel-preset-env/src/polyfills/corejs2/built-in-definitions.js) and [core-js@3](https://github.com/babel/babel/blob/master/packages/babel-preset-env/src/polyfills/corejs3/built-in-definitions.js), such as `es.map`, `es.set`, or `es.object.assign`.

Plugin names can be fully or partially specified (or using `RegExp`).

Expand Down Expand Up @@ -344,6 +344,7 @@ Don't add polyfills automatically per file, and don't transform `import "core-js
This option only has an effect when used alongside `useBuiltIns: usage` or `useBuiltIns: entry`, and ensures `@babel/preset-env` injects the correct imports for your `core-js` version.

By default, only polyfills for stable ECMAScript features are injected: if you want to polyfill them, you have three different options:

- when using `useBuiltIns: "entry"`, you can directly import a [proposal polyfill](https://github.com/zloirock/core-js/tree/master/packages/core-js/proposals): `import "core-js/proposals/string-replace-all"`.
- when using `useBuiltIns: "usage"` you have two different alternatives:
- set the [`shippedProposals`](#shippedproposals) option to `true`. This will enable polyfills and transforms for proposal which have already been shipped in browsers for a while.
Expand Down
5 changes: 3 additions & 2 deletions website/versioned_docs/version-7.0.0/node.md
Expand Up @@ -47,13 +47,13 @@ npx @babel/node test
> **Tip:** Use `rlwrap` to get a REPL with input history
>
> ```sh
> rlwrap npx @babel/node
> npx rlwrap @babel/node
> ```
>
> On some platforms (like OSX), extra arguments may be required for `rlwrap` to function properly, eg:
>
> ```sh
> NODE_NO_READLINE=1 rlwrap --always-readline npx @babel/node
> NODE_NO_READLINE=1 npx rlwrap --always-readline @babel/node
> ```
### Usage
Expand All @@ -80,3 +80,4 @@ npx @babel/node --debug --presets es2015 -- script.js --debug
| `--plugins` | `[]` | Comma-separated list of [plugins](plugins.md) to load and use. |
| `--config-file [path]` | `[]` | Path to the babel config file to use. Defaults to working directory babel.config.js |
| `--env-name [name]` | `[]` | The name of the 'env' to use when loading configs and plugins. Defaults to the value of BABEL_ENV, or else NODE_ENV, or else 'development'. |

Expand Up @@ -153,4 +153,6 @@ Bork.b = void 0;
## References

* [Proposal: ES Class Fields & Static Properties](https://github.com/jeffmo/es-class-static-properties-and-fields)
* [Proposal: Public and private instance fields](https://github.com/tc39/proposal-class-fields)
* [Proposal: Static class features](https://github.com/tc39/proposal-static-class-features)

Expand Up @@ -10,7 +10,7 @@ original_id: babel-plugin-transform-member-expression-literals
**In**

```javascript
obj["foo"] = "isValid";
obj.foo = "isValid";

obj.const = "isKeyword";
obj["var"] = "isKeyword";
Expand Down
Expand Up @@ -5,6 +5,8 @@ sidebar_label: transform-modules-commonjs
original_id: babel-plugin-transform-modules-commonjs
---

This plugin transforms ES2015 modules to [CommonJS](http://wiki.commonjs.org/wiki/Modules/1.1).

## Example

**In**
Expand Down
4 changes: 2 additions & 2 deletions website/versioned_docs/version-7.0.0/v7-migration.md
Expand Up @@ -599,8 +599,8 @@ npm install --save-dev @babel/register
Upgrading with Mocha:
```diff
- mocha --compilers js:babel-core/register
+ mocha --compilers js:@babel/register
- mocha --require babel-core/register
+ mocha --require @babel/register
```
`@babel/register` will also now only compile files in the current working directly (was done to fix issues with symlinking).
Expand Down
@@ -0,0 +1,90 @@
---
id: version-7.4.0-babel-plugin-syntax-dynamic-import
title: @babel/plugin-syntax-dynamic-import
sidebar_label: syntax-dynamic-import
original_id: babel-plugin-syntax-dynamic-import
---

## Installation

```sh
npm install --save-dev @babel/plugin-syntax-dynamic-import
```

## Usage

### Via `.babelrc` (Recommended)

**.babelrc**

```json
{
"plugins": ["@babel/plugin-syntax-dynamic-import"]
}
```

### Via CLI

```sh
babel --plugins @babel/plugin-syntax-dynamic-import script.js
```

### Via Node API

```javascript
require("@babel/core").transform("code", {
plugins: ["@babel/plugin-syntax-dynamic-import"],
});
```

## Working with Webpack and @babel/preset-env

Currently, `@babel/preset-env` is unaware that using `import()` with [Webpack relies on `Promise` internally](https://webpack.js.org/guides/code-splitting/#dynamic-imports). Environments which do not have builtin support for `Promise`, like Internet Explorer, will require both the `promise` and `iterator` polyfills be added manually.

For example, with `core-js@3`:

```js
// webpack config
const config = {
entry: [
"core-js/modules/es.promise",
"core-js/modules/es.array.iterator",
path.resolve(__dirname, "src/main.js"),
],
// ...
};
```

or

```js
// src/main.js
import "core-js/modules/es.promise";
import "core-js/modules/es.array.iterator";

// ...
```

This is the same for `core-js@2`, except the imports paths are slightly different:

```js
// webpack config
const config = {
entry: [
"core-js/modules/es6.promise",
"core-js/modules/es6.array.iterator",
path.resolve(__dirname, "src/main.js"),
],
// ...
};
```

or

```js
// src/main.js
import "core-js/modules/es6.promise";
import "core-js/modules/es6.array.iterator";

// ...
```

0 comments on commit 5a3e804

Please sign in to comment.