JavaScript ES5 to ES6/ES7 transpiler that performs the opposite function of Babel
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Safe transforms can be applied with relatively high confidence. They use strict rules for changing code and the resulting code should be nearly 100% equivalent to the original.
Converts callbacks to arrow functions while preserving behavior.
// Transform name: "arrow"What it transforms:
function(){}.bind(this) to arrow functionsthis context correctlyLimitations:
thisargumentsobj-method transform)class transform first)Usage Example:
// Before
var callback = function(x) {
return x * 2;
};
var bound = function() {
return this.value;
}.bind(this);
// After
const callback = x => {
return x * 2;
};
const bound = () => {
return this.value;
};Drops return statements in arrow functions for more concise syntax.
// Transform name: "arrow-return"What it transforms:
{ return x; } to => xLimitations:
arrow transform first)Usage Example:
// Before
const double = x => { return x * 2; };
const add = (a, b) => { return a + b; };
// After
const double = x => x * 2;
const add = (a, b) => a + b;Converts traditional for loops to for-of loops.
// Transform name: "for-of"What it transforms:
var item = array[i]; pattern when presentLimitations:
let transform first)Usage Example:
// Before
for (var i = 0; i < items.length; i++) {
var item = items[i];
console.log(item);
}
// After
for (const item of items) {
console.log(item);
}Converts for loops to Array.forEach() calls.
// Transform name: "for-each"What it transforms:
.forEach() method callsvar item = array[i]; pattern when presentLimitations:
let transform first)Usage Example:
// Before
for (var i = 0; i < items.length; i++) {
var item = items[i];
process(item);
}
// After
items.forEach((item) => {
process(item);
});Converts arguments usage to rest parameters.
// Transform name: "arg-rest"What it transforms:
arguments to rest parameter syntax function(...args)Limitations:
args variable already existsargsArray.slice.call(arguments)Usage Example:
// Before
function sum() {
var total = 0;
for (var i = 0; i < arguments.length; i++) {
total += arguments[i];
}
return total;
}
// After
function sum(...args) {
var total = 0;
for (var i = 0; i < args.length; i++) {
total += args[i];
}
return total;
}Converts apply() usage to spread operator.
// Transform name: "arg-spread"What it transforms:
obj.method.apply(obj, args) to obj.method(...args)func.apply(undefined, args) to func(...args)Usage Example:
// Before
Math.max.apply(Math, numbers);
callback.apply(undefined, args);
obj.method.apply(obj, params);
// After
Math.max(...numbers);
callback(...args);
obj.method(...params);Converts function values in objects to method syntax.
// Transform name: "obj-method"What it transforms:
Limitations:
Usage Example:
// Before
var obj = {
method: function(x) {
return x * 2;
},
other: function() {
console.log('hello');
}
};
// After
var obj = {
method(x) {
return x * 2;
},
other() {
console.log('hello');
}
};Converts {foo: foo} patterns to {foo} shorthand.
// Transform name: "obj-shorthand"What it transforms:
Limitations:
NaN propertiesUsage Example:
// Before
var name = 'John';
var age = 30;
var obj = {
name: name,
age: age,
active: active
};
// After
var name = 'John';
var age = 30;
var obj = {
name,
age,
active
};Removes unnecessary "use strict" directives.
// Transform name: "no-strict"What it transforms:
"use strict"; directivesx = "use strict";Usage Example:
// Before
"use strict";
function myFunction() {
"use strict";
return 42;
}
// After
function myFunction() {
return 42;
}Converts Math.pow() to exponentiation operator (ES7).
// Transform name: "exponent"What it transforms:
Math.pow(base, exponent) to base ** exponentUsage Example:
// Before
var result = Math.pow(2, 8);
var complex = Math.pow(x + 1, y * 2);
// After
var result = 2 ** 8;
var complex = (x + 1) ** (y * 2);Splits single variable declarations to multiple declarations.
// Transform name: "multi-var"What it transforms:
var x, y; declarations to multiple var x; var y; declarationsUsage Example:
// Before
var a = 1, b = 2, c;
// After
var a = 1;
var b = 2;
var c;