CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-lebab

JavaScript ES5 to ES6/ES7 transpiler that performs the opposite function of Babel

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

safe-transforms.mddocs/

Safe Transforms

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.

Capabilities

Arrow Functions

Converts callbacks to arrow functions while preserving behavior.

// Transform name: "arrow"

What it transforms:

  • Function expressions to arrow functions
  • Bound functions like function(){}.bind(this) to arrow functions
  • Preserves this context correctly

Limitations:

  • Not applied to unbound functions that use this
  • Not applied to functions that use arguments
  • Not applied to object properties (use obj-method transform)
  • Can mess up prototype-based classes (run 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;
};

Arrow Return

Drops return statements in arrow functions for more concise syntax.

// Transform name: "arrow-return"

What it transforms:

  • Immediate return statements { return x; } to => x
  • Applies to arrow functions and nested arrow functions

Limitations:

  • Only applies to arrow functions (run 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;

For-Of Loops

Converts traditional for loops to for-of loops.

// Transform name: "for-of"

What it transforms:

  • For loops iterating over arrays to for-of syntax
  • Uses variable name from var item = array[i]; pattern when present

Limitations:

  • Requires let/const variables (run let transform first)
  • Does not work when no alias is defined at start of loop body

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);
}

For-Each Loops

Converts for loops to Array.forEach() calls.

// Transform name: "for-each"

What it transforms:

  • For loops iterating over arrays to .forEach() method calls
  • Uses variable name from var item = array[i]; pattern when present
  • Adds index parameter when loop body uses the index variable

Limitations:

  • Requires let/const variables (run let transform first)
  • Does not work when no alias is defined at start of loop body

Usage Example:

// Before
for (var i = 0; i < items.length; i++) {
  var item = items[i];
  process(item);
}

// After
items.forEach((item) => {
  process(item);
});

Rest Parameters

Converts arguments usage to rest parameters.

// Transform name: "arg-rest"

What it transforms:

  • Functions using arguments to rest parameter syntax function(...args)

Limitations:

  • Does not transform when args variable already exists
  • Always names the rest parameter as args
  • Does not transform functions with formal parameters
  • Does not remove uses of Array.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;
}

Spread Operator

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);

Object Methods

Converts function values in objects to method syntax.

// Transform name: "obj-method"

What it transforms:

  • Object properties with function values to method shorthand

Limitations:

  • Does not convert named function expressions
  • Does not convert arrow functions

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');
  }
};

Object Shorthand

Converts {foo: foo} patterns to {foo} shorthand.

// Transform name: "obj-shorthand"

What it transforms:

  • Object properties where key and value have the same name

Limitations:

  • Ignores numeric and NaN properties
  • Does not convert string properties

Usage 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
};

Remove Strict Mode

Removes unnecessary "use strict" directives.

// Transform name: "no-strict"

What it transforms:

  • Removes "use strict"; directives
  • Does not touch assignments like x = "use strict";

Usage Example:

// Before
"use strict";

function myFunction() {
  "use strict";
  return 42;
}

// After

function myFunction() {
  return 42;
}

Exponentiation Operator

Converts Math.pow() to exponentiation operator (ES7).

// Transform name: "exponent"

What it transforms:

  • Math.pow(base, exponent) to base ** exponent

Usage 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);

Multiple Variable Declarations

Splits single variable declarations to multiple declarations.

// Transform name: "multi-var"

What it transforms:

  • Single var x, y; declarations to multiple var x; var y; declarations

Usage Example:

// Before
var a = 1, b = 2, c;

// After
var a = 1;
var b = 2;
var c;

docs

cli-usage.md

index.md

safe-transforms.md

unsafe-transforms.md

tile.json