6.19.0 Released

object-rest-spread works standalone and a few new plugin options APIs were added!


This content originally appeared on Babel Blog and was authored by Henry Zhu

object-rest-spread works standalone and a few new plugin options APIs were added!

v6.19.0 Summary (2016-11-16)

🚀 New Feature

#4755 Make object-rest-spread work as an independent plugin. (@hzoo)

This rewrite fixes a long standing issue where the object-rest-spread plugin was depending on 2 other plugins to compile RestProperty properly.

This fix important given the assumption that plugins should be independent and is vital for the use of babel-preset-env since new environments support destructuring natively.

In

JavaScript
const { a, ...b } = c;

Out

JavaScript
const { a } = c; // remove the `...b`
const b = _objectWithoutProperties(c, ["a"]); // use the helper

It's interesting to see all the places where you can destructure!

RestProperty

function a({ b, ...c }) {} // Parameters
JavaScript
const { a, ...b } = c; // VariableDeclaration
JavaScript
export var { a, ...b } = c; // ExportNamedDeclaration
JavaScript
try {} catch ({a, ...b}) {} // CatchClause
JavaScript
({a, ...b} = c); // AssignmentExpression
JavaScript
for ({a, ...b} of []) {} // ForXStatement

SpreadProperty

JavaScript
var a = { ...b, ...c } // ObjectExpression

#4544 Add the spec option to "transform-class-properties". (@motiz88)

Class properties will use Object.defineProperty instead of a simple this.x = y. Static fields are will use value: undefined even if they are not initialized.

Usage

JavaScript
{
"plugins": [
["transform-class-properties", {
"spec": true
}]
]
}

In

JavaScript
class Foo {
static bar;
baz = 'guy';
}

Out

JavaScript
var Foo = function Foo() {
_classCallCheck(this, Foo);
this.baz = 'guy';
};

Out w/ "spec": true

JavaScript
var Foo = function Foo() {
babelHelpers.classCallCheck(this, Foo);
_initialiseProps.call(this);
};

Object.defineProperty(Foo, "bar", {
enumerable: true,
writable: true,
value: undefined
});

var _initialiseProps = function () {
Object.defineProperty(this, "bar", {
enumerable: true,
writable: true,
value: foo
});
};

#4836 Add path utilities path.isAncestor and path.isDescendant. (@boopathi)

We've added 2 similar "ancestry" path methods to path.findParent:

Usage

JavaScript
let programPath, numberPath;
traverse(ast, {
Program(path) { programPath = path; },
NumberPath(path) { numberPath = path; },
});

programPath.isAncestor(numberPath); // true
numberPath.isDescendant(programPath); // true

#4835 Add clearCache and clearPath as separate APIs under traverse. (@boopathi)

Usage

JavaScript
traverse.clearCache(); // clears both path's and scope cache
traverse.clearCache.clearPath();
traverse.clearCache.clearScope();

#4827 Add jsonCompatibleStrings option to babel-generator. (@kangax)

Usage

JavaScript
{
"generatorOpts": {
"jsonCompatibleStrings": true // defaults to false
}
}

Set to true for the generator to use jsesc with "json": true. This will make it print "\u00A9" vs. "©";


#3547 Added flowCommaSeparator to babel-generator. (@sampepose)

Usage

JavaScript
{
"generatorOpts": {
"flowCommaSeparator": true // defaults to false
}
}

Currently there are 2 supported syntaxes (, and ;) in Flow Object Types. The use of commas is in line with the more popular style and matches how objects are defined in JavaScript, making it a bit more natural to write.

JavaScript
var a: { param1: number; param2: string }
var a: { param1: number, param2: string }

#3553 Add t.isNodesEquivalent. (@hzoo)

Usage

JavaScript
assert(t.isNodesEquivalent(parse("1 + 1"), parse("1+1")) === true);

#4789 Support stage-2 import() as contextual import in transform-es2015-modules-systemjs. (@guybedford)

You'll want to add the stage-2 preset or explicitly include babel-plugin-syntax-dynamic-import (not enabled by default).

JavaScript
export function lazyLoadOperation () {
return import('./x')
.then(function (x) {
x.y();
});
}

🐛 Bug Fixes

#4830 Will print the shorter of the NumericLiterals if using the minified option. (@shinew)

Input

JavaScript
5e1;
5e4;

Output

JavaScript
50;
5e4;

#4832 Fix transform-es2015-modules-systemjs to ensure consistent modules iteration. (@guybedford)

JavaScript
import "2"; // should be imported first
import "1"; // second

#4813 Fix binding kind of destructured variables relating to transform-react-constant-elements (@STRML)

Fixes an issue with destructuring parameters being hoisted incorrectly.

Input

JavaScript
function render({ text }) {
return () => (<Component text={text} />);
}

Output

JavaScript
function render(_ref) {
let text = _ref.text;
var _ref2 = <Component text={text} />;
return () => _ref2;
}

🌏 Committers: 10


Check out Github for the whole changelog!


This content originally appeared on Babel Blog and was authored by Henry Zhu


Print Share Comment Cite Upload Translate Updates
APA

Henry Zhu | Sciencx (2016-11-16T11:00:00+00:00) 6.19.0 Released. Retrieved from https://www.scien.cx/2016/11/16/6-19-0-released-2/

MLA
" » 6.19.0 Released." Henry Zhu | Sciencx - Wednesday November 16, 2016, https://www.scien.cx/2016/11/16/6-19-0-released-2/
HARVARD
Henry Zhu | Sciencx Wednesday November 16, 2016 » 6.19.0 Released., viewed ,<https://www.scien.cx/2016/11/16/6-19-0-released-2/>
VANCOUVER
Henry Zhu | Sciencx - » 6.19.0 Released. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2016/11/16/6-19-0-released-2/
CHICAGO
" » 6.19.0 Released." Henry Zhu | Sciencx - Accessed . https://www.scien.cx/2016/11/16/6-19-0-released-2/
IEEE
" » 6.19.0 Released." Henry Zhu | Sciencx [Online]. Available: https://www.scien.cx/2016/11/16/6-19-0-released-2/. [Accessed: ]
rf:citation
» 6.19.0 Released | Henry Zhu | Sciencx | https://www.scien.cx/2016/11/16/6-19-0-released-2/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.