From d40cb31685cfa627bae3a4fd001aa0129befb5ff Mon Sep 17 00:00:00 2001 From: Sven SAULEAU Date: Sat, 8 Apr 2017 10:13:20 +0200 Subject: [PATCH 1/8] Update transform-es2015-modules-commonjs doc #5588 --- .../babel-plugin-transform-es2015-modules-commonjs/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/babel-plugin-transform-es2015-modules-commonjs/README.md b/packages/babel-plugin-transform-es2015-modules-commonjs/README.md index 33088cc8682c..bdad88967004 100644 --- a/packages/babel-plugin-transform-es2015-modules-commonjs/README.md +++ b/packages/babel-plugin-transform-es2015-modules-commonjs/README.md @@ -82,7 +82,7 @@ Object.defineProperty(exports, "__esModule", { }); ``` -In environments that don't support this you can enable loose mode on `babel-plugin-transform-es20150-modules-commonjs` +In environments that don't support this you can enable loose mode on `babel-plugin-transform-es2015-modules-commonjs` and instead of using `Object.defineProperty` an assignment will be used instead. ```javascript From 149acc40bdac5ac42bb4e49ff71192274b69de26 Mon Sep 17 00:00:00 2001 From: Sven SAULEAU Date: Sat, 8 Apr 2017 10:13:47 +0200 Subject: [PATCH 2/8] Remove incorrect docs. #5580 --- .../README.md | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/packages/babel-plugin-transform-es2015-spread/README.md b/packages/babel-plugin-transform-es2015-spread/README.md index e33a1db7cff7..ad1fd70d1683 100644 --- a/packages/babel-plugin-transform-es2015-spread/README.md +++ b/packages/babel-plugin-transform-es2015-spread/README.md @@ -9,31 +9,13 @@ ```js var a = ['a', 'b', 'c']; var b = [...a, 'foo']; - -var c = { foo: 'bar', baz: 42 }; -var d = {...c, a: 2}; ``` **Out** ```js -var _extends = Object.assign || function (target) { - for (var i = 1; i < arguments.length; i++) { - var source = arguments[i]; - for (var key in source) { - if (Object.prototype.hasOwnProperty.call(source, key)) { - target[key] = source[key]; - } - } - } - return target; -} - var a = [ 'a', 'b', 'c' ]; var b = [].concat(a, [ 'foo' ]); - -var c = { foo: 'bar', baz: 42 }; -var d = _extends({}, c, { a: 2 }); ``` ## Installation From 2cb4d08d194040bed7345e72fa3d549518b9836f Mon Sep 17 00:00:00 2001 From: Sven SAULEAU Date: Sat, 8 Apr 2017 10:14:19 +0200 Subject: [PATCH 3/8] Improve example of babel-plugin-transform-es2015-arrow-functions #5573 --- .../README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/babel-plugin-transform-es2015-arrow-functions/README.md b/packages/babel-plugin-transform-es2015-arrow-functions/README.md index 658f413f6cb2..9a5ab5b2f5f3 100644 --- a/packages/babel-plugin-transform-es2015-arrow-functions/README.md +++ b/packages/babel-plugin-transform-es2015-arrow-functions/README.md @@ -27,12 +27,12 @@ console.log(bob.printFriends()); **Out** ```javascript -var a = function a() {}; -var a = function a(b) { +var a = function () {}; +var a = function (b) { return b; }; -var double = [1, 2, 3].map(function (num) { +const double = [1, 2, 3].map(function (num) { return num * 2; }); console.log(double); // [2,4,6] @@ -40,7 +40,7 @@ console.log(double); // [2,4,6] var bob = { _name: "Bob", _friends: ["Sally", "Tom"], - printFriends: function printFriends() { + printFriends() { var _this = this; this._friends.forEach(function (f) { From e2c2d7d7423a8823dda60ab54e0881011be6baf1 Mon Sep 17 00:00:00 2001 From: Sven SAULEAU Date: Sat, 8 Apr 2017 10:14:56 +0200 Subject: [PATCH 4/8] Update babel-generator's README #5517 --- packages/babel-generator/README.md | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/packages/babel-generator/README.md b/packages/babel-generator/README.md index a3371913532f..ff215b753f2a 100644 --- a/packages/babel-generator/README.md +++ b/packages/babel-generator/README.md @@ -54,12 +54,7 @@ sourceFileName | string | | The filename for the sourc In most cases, Babel does a 1:1 transformation of input-file to output-file. However, you may be dealing with AST constructed from multiple sources - JS files, templates, etc. If this is the case, and you want the sourcemaps to reflect the correct sources, you'll need -to make some changes to your code. - -First, each node with a `loc` property (which indicates that node's original placement in the -source document) must also include a `loc.filename` property, set to the source filename. - -Second, you should pass an object to `generate` as the `code` parameter. Keys +to pass an object to `generate` as the `code` parameter. Keys should be the source filenames, and values should be the source content. Here's an example of what that might look like: @@ -70,14 +65,14 @@ import generate from 'babel-generator'; const a = 'var a = 1;'; const b = 'var b = 2;'; -const astA = parse(a, { filename: 'a.js' }); -const astB = parse(b, { filename: 'b.js' }); +const astA = parse(a, { sourceFilename: 'a.js' }); +const astB = parse(b, { sourceFilename: 'b.js' }); const ast = { type: 'Program', - body: [].concat(astA.body, ast2.body) + body: [].concat(astA.program.body, astB.program.body) }; -const { code, map } = generate(ast, { /* options */ }, { +const { code, map } = generate(ast, { sourceMaps: true }, { 'a.js': a, 'b.js': b }); From e9bc213b140ab1a30b3bb2df1162c7ae95ee5c05 Mon Sep 17 00:00:00 2001 From: Sven SAULEAU Date: Sat, 8 Apr 2017 10:15:43 +0200 Subject: [PATCH 5/8] Update coffescript/register reference link address #5475 --- packages/babel-register/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/babel-register/README.md b/packages/babel-register/README.md index 6a4682b56801..c19e260c4095 100644 --- a/packages/babel-register/README.md +++ b/packages/babel-register/README.md @@ -5,7 +5,7 @@ One of the ways you can use Babel is through the require hook. The require hook will bind itself to node's `require` and automatically compile files on the fly. This is equivalent to CoffeeScript's -[coffee-script/register](http://coffeescript.org/documentation/docs/register.html). +[coffee-script/register](http://coffeescript.org/v2/annotated-source/register.html). ## Install From c1b374070740ff75d0f6782a12856e37746c5b4d Mon Sep 17 00:00:00 2001 From: Sven SAULEAU Date: Sat, 8 Apr 2017 10:16:55 +0200 Subject: [PATCH 6/8] document cache option for babel-register #5440 --- packages/babel-register/README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/babel-register/README.md b/packages/babel-register/README.md index c19e260c4095..413e7a6349e5 100644 --- a/packages/babel-register/README.md +++ b/packages/babel-register/README.md @@ -66,7 +66,10 @@ require("babel-register")({ // Setting this will remove the currently hooked extensions of .es6, `.es`, `.jsx` // and .js so you'll have to add them back if you want them to be used again. - extensions: [".es6", ".es", ".jsx", ".js"] + extensions: [".es6", ".es", ".jsx", ".js"], + + // Setting this to false will disable the cache. + cache: true }); ``` From 982aba38e4b13e77fd1e6639b43ce208d1296981 Mon Sep 17 00:00:00 2001 From: Sven SAULEAU Date: Sat, 8 Apr 2017 10:18:01 +0200 Subject: [PATCH 7/8] [doc] Fix: comments in usage w/ options #5400 --- packages/babel-plugin-transform-runtime/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/babel-plugin-transform-runtime/README.md b/packages/babel-plugin-transform-runtime/README.md index 011a3eab10de..fb82b38de57b 100644 --- a/packages/babel-plugin-transform-runtime/README.md +++ b/packages/babel-plugin-transform-runtime/README.md @@ -50,7 +50,7 @@ Without options: With options: -```json +```js { "plugins": [ ["transform-runtime", { From ca435b6d486f356cf8004a6bda07f28fb3c5474a Mon Sep 17 00:00:00 2001 From: Sven SAULEAU Date: Sat, 8 Apr 2017 10:18:44 +0200 Subject: [PATCH 8/8] Improve options documentation for `babel-plugin-transform-runtime` #5401 --- .../babel-plugin-transform-runtime/README.md | 64 ++++++++++++++++--- 1 file changed, 54 insertions(+), 10 deletions(-) diff --git a/packages/babel-plugin-transform-runtime/README.md b/packages/babel-plugin-transform-runtime/README.md index fb82b38de57b..2ab8ae89204f 100644 --- a/packages/babel-plugin-transform-runtime/README.md +++ b/packages/babel-plugin-transform-runtime/README.md @@ -1,8 +1,8 @@ # babel-plugin-transform-runtime -> Externalise references to helpers and builtins, automatically polyfilling your code without polluting globals. (This plugin is recommended in a library/tool) +> Externalise references to helpers and built-ins, automatically polyfilling your code without polluting globals. (This plugin is recommended in a library/tool) -NOTE: Instance methods such as `"foobar".includes("foo")` will not work since that would require modification of existing builtins (Use [`babel-polyfill`](http://babeljs.io/docs/usage/polyfill) for that). +NOTE: Instance methods such as `"foobar".includes("foo")` will not work since that would require modification of existing built-ins (Use [`babel-polyfill`](http://babeljs.io/docs/usage/polyfill) for that). ## Why? @@ -50,14 +50,14 @@ Without options: With options: -```js +```json { "plugins": [ ["transform-runtime", { - "helpers": false, // defaults to true - "polyfill": false, // defaults to true - "regenerator": true, // defaults to true - "moduleName": "babel-runtime" // defaults to "babel-runtime" + "helpers": false, + "polyfill": false, + "regenerator": true, + "moduleName": "babel-runtime" }] ] } @@ -77,15 +77,59 @@ require("babel-core").transform("code", { }); ``` +## Options + +### `helpers` + +`boolean`, defaults to `true`. + +Toggles whether or not inlined Babel helpers (`classCallCheck`, `extends`, etc.) are replaced with calls to `moduleName`. + +For more information, see [Helper aliasing](#helper-aliasing). + +### `polyfill` + +`boolean`, defaults to `true`. + +Toggles whether or not new built-ins (`Promise`, `Set`, `Map`, etc.) are transformed to use a non-global polluting polyfill. + +For more information, see [`core-js` aliasing](#core-js-aliasing). + +### `regenerator` + +`boolean`, defaults to `true`. + +Toggles whether or not generator functions are transformed to use a regenerator runtime that does not pollute the global scope. + +For more information, see [Regenerator aliasing](#regenerator-aliasing). + +### `moduleName` + +`string`, defaults to `"babel-runtime"`. + +Sets the name/path of the module used when importing helpers. + +Example: + +```json +{ + "moduleName": "flavortown/runtime" +} +``` + +```js +import extends from 'flavortown/runtime/helpers/extends'; +``` + ## Technical details The `runtime` transformer plugin does three things: * Automatically requires `babel-runtime/regenerator` when you use generators/async functions. * Automatically requires `babel-runtime/core-js` and maps ES6 static methods and built-ins. -* Removes the inline babel helpers and uses the module `babel-runtime/helpers` instead. +* Removes the inline Babel helpers and uses the module `babel-runtime/helpers` instead. -What does this actually mean though? Basically, you can use built-ins such as `Promise`, `Set`, `Symbol` etc as well use all the Babel features that require a polyfill seamlessly, without global pollution, making it extremely suitable for libraries. +What does this actually mean though? Basically, you can use built-ins such as `Promise`, `Set`, `Symbol`, etc., as well use all the Babel features that require a polyfill seamlessly, without global pollution, making it extremely suitable for libraries. Make sure you include `babel-runtime` as a dependency. @@ -194,7 +238,7 @@ without worrying about where they come from. ### Helper aliasing -Usually babel will place helpers at the top of your file to do common tasks to avoid +Usually Babel will place helpers at the top of your file to do common tasks to avoid duplicating the code around in the current file. Sometimes these helpers can get a little bulky and add unnecessary duplication across files. The `runtime` transformer replaces all the helper calls to a module.