Vai al contenuto principale

6.19.0 Rilasciato

· Lettura di 5 min
Traduzione Beta Non Ufficiale

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

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

Output

JavaScript
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
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 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

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

Input

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

Output

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

Output con "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 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

JavaScript
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

JavaScript
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

JavaScript
{
"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

JavaScript
{
"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.

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

#3553 Aggiungere t.isNodesEquivalent. (@hzoo)

Utilizzo

JavaScript
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).

JavaScript
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

JavaScript
5e1;
5e4;

Output

JavaScript
50;
5e4;

#4832 Correzione di transform-es2015-modules-systemjs per garantire iterazione consistente dei moduli. (@guybedford)

JavaScript
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

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

Output

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

🌏 Collaboratori: 10


Consulta GitHub per il changelog completo!