6.19.0 Rilasciato
Questa pagina è stata tradotta da PageTurner AI (beta). Non ufficialmente approvata dal progetto. Hai trovato un errore? Segnala problema →
object-rest-spread funziona autonomamente e sono state aggiunte nuove API per le opzioni dei plugin!
Riepilogo v6.19.0 (2016-11-16)
🚀 Nuova Funzionalità
#4755 Rendere object-rest-spread funzionante come plugin indipendente. (@hzoo)
Questa riscrittura risolve un problema di vecchia data in cui il plugin object-rest-spread dipendeva da altri 2 plugin per compilare correttamente RestProperty.
Questa correzione è importante dato l'assunto che i plugin debbano essere indipendenti ed è vitale per l'uso di babel-preset-env poiché i nuovi ambienti supportano nativamente il destructuring.
Input
const { a, ...b } = c;
Output
const { a } = c; // remove the `...b`
const b = _objectWithoutProperties(c, ["a"]); // use the helper
È interessante vedere tutti i contesti in cui è possibile utilizzare il destructuring!
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 Aggiungere l'opzione spec a "transform-class-properties". (@motiz88)
Le proprietà di classe utilizzeranno Object.defineProperty invece di un semplice this.x = y.
I campi statici utilizzeranno value: undefined anche se non inizializzati.
Utilizzo
{
"plugins": [
["transform-class-properties", {
"spec": true
}]
]
}
Input
class Foo {
static bar;
baz = 'guy';
}
Output
var Foo = function Foo() {
_classCallCheck(this, Foo);
this.baz = 'guy';
};
Output 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 Aggiungere utilità per i path path.isAncestor e path.isDescendant. (@boopathi)
Abbiamo aggiunto 2 metodi simili di "parentela" per i path a path.findParent:
Utilizzo
let programPath, numberPath;
traverse(ast, {
Program(path) { programPath = path; },
NumberPath(path) { numberPath = path; },
});
programPath.isAncestor(numberPath); // true
numberPath.isDescendant(programPath); // true
#4835 Aggiungere clearCache e clearPath come API separate sotto traverse. (@boopathi)
Utilizzo
traverse.clearCache(); // clears both path's and scope cache
traverse.clearCache.clearPath();
traverse.clearCache.clearScope();
#4827 Aggiungere l'opzione jsonCompatibleStrings a babel-generator. (@kangax)
Utilizzo
{
"generatorOpts": {
"jsonCompatibleStrings": true // defaults to false
}
}
Impostare su true per far sì che il generatore utilizzi jsesc con "json": true. Questo produrrà "\u00A9" invece di "©";
#3547 Aggiungere flowCommaSeparator a babel-generator. (@sampepose)
Utilizzo
{
"generatorOpts": {
"flowCommaSeparator": true // defaults to false
}
}
Attualmente sono supportate due sintassi (, e ;) nei Flow Object Types. L'uso delle virgole è allineato con lo stile più popolare e corrisponde a come gli oggetti sono definiti in JavaScript, rendendo la scrittura più naturale.
var a: { param1: number; param2: string }
var a: { param1: number, param2: string }
#3553 Aggiungere t.isNodesEquivalent. (@hzoo)
Utilizzo
assert(t.isNodesEquivalent(parse("1 + 1"), parse("1+1")) === true);
#4789 Supportare import() stage-2 come import contestuale in transform-es2015-modules-systemjs. (@guybedford)
Dovrai aggiungere il preset stage-2 o includere esplicitamente babel-plugin-syntax-dynamic-import (non abilitato di default).
export function lazyLoadOperation () {
return import('./x')
.then(function (x) {
x.y();
});
}
🐛 Correzioni di bug
#4830 Stampa il più breve tra i NumericLiteral quando si usa l'opzione minified. (@shinew)
Input
5e1;
5e4;
Output
50;
5e4;
#4832 Correzione di transform-es2015-modules-systemjs per garantire iterazione consistente dei moduli. (@guybedford)
import "2"; // should be imported first
import "1"; // second
#4813 Correzione del tipo binding per variabili destrutturate relative a transform-react-constant-elements (@STRML)
Risolto un problema con i parametri destrutturati che venivano sollevati in modo errato.
Input
function render({ text }) {
return () => (<Component text={text} />);
}
Output
function render(_ref) {
let text = _ref.text;
var _ref2 = <Component text={text} />;
return () => _ref2;
}
🌏 Collaboratori: 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 GitHub per il changelog completo!