Lanzamiento de la versión 6.19.0
Esta página fue traducida por PageTurner AI (beta). No está respaldada oficialmente por el proyecto. ¿Encontraste un error? Reportar problema →
¡object-rest-spread funciona independientemente y se añadieron nuevas APIs de opciones para plugins!
Resumen de v6.19.0 (2016-11-16)
🚀 Nueva característica
#4755 Hacer que object-rest-spread funcione como plugin independiente. (@hzoo)
Esta reescritura soluciona un problema persistente donde el plugin object-rest-spread dependía de otros 2 plugins para compilar RestProperty correctamente.
Esta corrección es importante dada la premisa de que los plugins deben ser independientes, y es vital para el uso de babel-preset-env ya que nuevos entornos soportan la desestructuración de forma nativa.
Entrada
const { a, ...b } = c;
Salida
const { a } = c; // remove the `...b`
const b = _objectWithoutProperties(c, ["a"]); // use the helper
¡Es interesante ver todos los lugares donde puedes usar desestructuración!
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 Añadir la opción spec a "transform-class-properties". (@motiz88)
Las propiedades de clase usarán Object.defineProperty en lugar de un simple this.x = y.
Los campos estáticos usarán value: undefined incluso si no están inicializados.
Uso
{
"plugins": [
["transform-class-properties", {
"spec": true
}]
]
}
Entrada
class Foo {
static bar;
baz = 'guy';
}
Salida
var Foo = function Foo() {
_classCallCheck(this, Foo);
this.baz = 'guy';
};
Salida con "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 Añadir utilidades de ruta path.isAncestor y path.isDescendant. (@boopathi)
Hemos añadido 2 métodos de ruta de "ascendencia" similares a path.findParent:
Uso
let programPath, numberPath;
traverse(ast, {
Program(path) { programPath = path; },
NumberPath(path) { numberPath = path; },
});
programPath.isAncestor(numberPath); // true
numberPath.isDescendant(programPath); // true
#4835 Añadir clearCache y clearPath como APIs separadas bajo traverse. (@boopathi)
Uso
traverse.clearCache(); // clears both path's and scope cache
traverse.clearCache.clearPath();
traverse.clearCache.clearScope();
#4827 Añadir opción jsonCompatibleStrings a babel-generator. (@kangax)
Uso
{
"generatorOpts": {
"jsonCompatibleStrings": true // defaults to false
}
}
Configurar como true para que el generador use jsesc con "json": true. Esto hará que imprima "\u00A9" en lugar de "©";
#3547 Añadido flowCommaSeparator a babel-generator. (@sampepose)
Uso
{
"generatorOpts": {
"flowCommaSeparator": true // defaults to false
}
}
Actualmente existen 2 sintaxis soportadas (, y ;) en Flow Object Types. El uso de comas sigue el estilo más popular y coincide con cómo se definen objetos en JavaScript, haciéndolo más natural para escribir.
var a: { param1: number; param2: string }
var a: { param1: number, param2: string }
#3553 Añadir t.isNodesEquivalent. (@hzoo)
Uso
assert(t.isNodesEquivalent(parse("1 + 1"), parse("1+1")) === true);
#4789 Soporte para import() en etapa-2 como import contextual en transform-es2015-modules-systemjs. (@guybedford)
Deberás añadir el preset stage-2 o incluir explícitamente babel-plugin-syntax-dynamic-import (no está habilitado por defecto).
export function lazyLoadOperation () {
return import('./x')
.then(function (x) {
x.y();
});
}
🐛 Correcciones de errores
#4830 Imprimirá el más corto de los NumericLiteral al usar la opción minified. (@shinew)
Entrada
5e1;
5e4;
Salida
50;
5e4;
#4832 Corrige transform-es2015-modules-systemjs para garantizar iteración consistente de módulos. (@guybedford)
import "2"; // should be imported first
import "1"; // second
#4813 Corrige el tipo de enlace (binding) de variables desestructuradas en transform-react-constant-elements (@STRML)
Soluciona un problema donde los parámetros desestructurados se elevaban incorrectamente.
Entrada
function render({ text }) {
return () => (<Component text={text} />);
}
Salida
function render(_ref) {
let text = _ref.text;
var _ref2 = <Component text={text} />;
return () => _ref2;
}
🌏 Colaboradores: 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)
¡Consulta el registro completo en GitHub!