Update your project to the latest ECMAScript syntax.
npm install esnextBring your JavaScript into the future.
``npm
$ yarn global add esnextor, with
:`
$ npm install -g esnext
After installing, run esnext -h for comprehensive usage instructions.
Translate some regular functions to arrow functions:
`js
list.map(function(item) { return item.name; });
// ↑ becomes ↓
list.map(item => item.name);
`
Convert var declarations to let or const as appropriate:
`js
var arr = [];
for (var i = 0; i < 5; i++) {
arr.push(i);
}
// ↑ becomes ↓
const arr = [];
for (let i = 0; i < 5; i++) {
arr.push(i);
}
`
Use shorthand syntax for various object constructs:
`js${first} ${last}
let person = {
first: first,
last: last,
fullName: function() {
return ;
}
};
// ↑ becomes ↓
let person = {
first,
last,
fullName() {
return ${first} ${last};`
}
};
Convert string concatenation to string or template literals:
`js
let name = 'Brian' + ' ' + 'Donovan';
let greeting = 'Hello, ' + name;
// ↑ becomes ↓
let name = 'Brian Donovan';
let greeting = Hello, ${name};`
Convert assignments and declarations to use object destructuring syntax:
`js
let a = obj.a, b = obj.b;
a = obj2.a, b = obj2.b;
// ↑ becomes ↓
let { a, b } = obj;
({ a, b } = obj2);
`
Translate CommonJS modules into ES6 modules:
`js
var readFile = require('fs').readFile;
const MagicString = require('magic-string');
let { ok, strictEqual: eq } = require('assert');
exports.doSomething = function() {
ok(1);
};
// ↑ becomes ↓
import { readFile } from 'fs';
import MagicString from 'magic-string';
import { ok, strictEqual as eq } from 'assert';
export function doSomething() {
ok(1);
}
`
`jstrue
{
'declarations.block-scope': {
/**
* Set this to to only turn var into let, never const.``
*/
disableConst: boolean
}
}