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
const { a, ...b } = c;
Out
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
const { a, ...b } = c; // VariableDeclaration
export var { a, ...b } = c; // ExportNamedDeclaration
try {} catch ({a, ...b}) {} // CatchClause
({a, ...b} = c); // AssignmentExpression
for ({a, ...b} of []) {} // ForXStatement
SpreadProperty
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
{
"plugins": [
["transform-class-properties", {
"spec": true
}]
]
}
In
class Foo {
static bar;
baz = 'guy';
}
Out
var Foo = function Foo() {
_classCallCheck(this, Foo);
this.baz = 'guy';
};
Out w/ "spec": true
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
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
traverse.clearCache(); // clears both path's and scope cache
traverse.clearCache.clearPath();
traverse.clearCache.clearScope();
#4827 Add jsonCompatibleStrings
option to babel-generator
. (@kangax)
Usage
{
"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
{
"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.
var a: { param1: number; param2: string }
var a: { param1: number, param2: string }
#3553 Add t.isNodesEquivalent
. (@hzoo)
Usage
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).
export function lazyLoadOperation () {
return import('./x')
.then(function (x) {
x.y();
});
}
๐ Bug Fixesโ
#4830 Will print the shorter of the NumericLiteral
s if using the minified
option. (@shinew)
Input
5e1;
5e4;
Output
50;
5e4;
#4832 Fix transform-es2015-modules-systemjs
to ensure consistent modules iteration. (@guybedford)
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
function render({ text }) {
return () => (<Component text={text} />);
}
Output
function render(_ref) {
let text = _ref.text;
var _ref2 = <Component text={text} />;
return () => _ref2;
}
๐ Committers: 10โ
- Boopathi Rajaa (boopathi)
- Guy Bedford (guybedford)
- Henry Zhu (hzoo)
- Juriy Zaytsev (kangax)
- Moti Zilberman (motiz88)
- Sam Pepose (sampepose)
- Samuel Reed (STRML)
- Scott Stern (sstern6)
- Shine Wang (shinew)
- lion (lion-man44)
Check out Github for the whole changelog!