or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

ast-types.mdbrowser.mdcli.mdindex.mdmodules.mdregistration.mdtransformation.mdtransformers.md
tile.json

transformers.mddocs/

Transformers

The modular transformation system with individual transformers for different ES6+ features. Each transformer handles the conversion of specific JavaScript language features from ES6+ to ES5-compatible code.

Transformer System

/**
 * Available transformers by name
 */
const transformers: { [name: string]: Transformer };

/**
 * Transformer namespaces grouping related transformers
 */
const namespaces: {
  es3: string[];
  es5: string[];
  es6: string[];
  es7: string[];
  spec: string[];
  validation: string[];
  minification: string[];
  other: string[];
  playground: string[];
  internal: string[];
};

/**
 * Mapping from transformer names to their namespace
 */
const transformerNamespaces: { [transformer: string]: string };

/**
 * Deprecated transformer names mapped to current names
 */
const deprecatedTransformerMap: { [oldName: string]: string };

ES6 Transformers

Arrow Functions

/**
 * Transform arrow functions to regular functions
 * Input: (a, b) => a + b
 * Output: function (a, b) { return a + b; }
 */
const "es6.arrowFunctions": Transformer;

Classes

/**
 * Transform ES6 classes to constructor functions and prototypes
 * Input: class Foo extends Bar { method() {} }
 * Output: function Foo() {} Foo.prototype.method = function() {}
 */
const "es6.classes": Transformer;

Template Literals

/**
 * Transform template literals to string concatenation
 * Input: `Hello ${name}!`
 * Output: "Hello " + name + "!"
 */
const "es6.templateLiterals": Transformer;

Destructuring

/**
 * Transform destructuring assignments and parameters
 * Input: const {a, b} = obj; [x, y] = arr;
 * Output: var a = obj.a, b = obj.b; x = arr[0]; y = arr[1];
 */
const "es6.destructuring": Transformer;

Block Scoping

/**
 * Transform let and const to var with proper scoping
 * Input: { let x = 1; const y = 2; }
 * Output: { var x = 1; var y = 2; }
 */
const "es6.blockScoping": Transformer;

For-Of Loops

/**
 * Transform for-of loops to for loops with iterators
 * Input: for (let item of items) {}
 * Output: for (var _iterator = items[Symbol.iterator]()...) {}
 */
const "es6.forOf": Transformer;

Spread Operator

/**
 * Transform spread operator in arrays and calls
 * Input: [...arr1, ...arr2]; fn(...args);
 * Output: arr1.concat(arr2); fn.apply(undefined, args);
 */
const "es6.spread": Transformer;

Default Parameters

/**
 * Transform default parameter values
 * Input: function fn(a = 1, b = 2) {}
 * Output: function fn(a, b) { a = a === undefined ? 1 : a; ... }
 */
const "es6.parameters.default": Transformer;

Rest Parameters

/**
 * Transform rest parameters to arguments manipulation
 * Input: function fn(a, ...rest) {}
 * Output: function fn(a) { var rest = Array.prototype.slice.call(arguments, 1); }
 */
const "es6.parameters.rest": Transformer;

Computed Properties

/**
 * Transform computed property names in object literals
 * Input: { [key]: value }
 * Output: var _obj = {}; _obj[key] = value;
 */
const "es6.properties.computed": Transformer;

Property Shorthand

/**
 * Transform property shorthand notation
 * Input: { name, age }
 * Output: { name: name, age: age }
 */
const "es6.properties.shorthand": Transformer;

Constants

/**
 * Transform const declarations to var with immutability checks
 * Input: const PI = 3.14;
 * Output: var PI = 3.14; (with assignment prevention)
 */
const "es6.constants": Transformer;

Modules

/**
 * Transform ES6 import/export to chosen module format
 * Input: import {fn} from 'module'; export default class {};
 * Output: var fn = require('module').fn; module.exports = class {};
 */
const "es6.modules": Transformer;

Object Super

/**
 * Transform super in object methods
 * Input: { method() { super.method(); } }
 * Output: { method: function() { ParentProto.method.call(this); } }
 */
const "es6.objectSuper": Transformer;

Unicode Regex

/**
 * Transform unicode flag in regular expressions
 * Input: /pattern/u
 * Output: Equivalent regex without unicode flag
 */
const "es6.unicodeRegex": Transformer;

Tail Call Optimization

/**
 * Transform tail calls to avoid stack overflow
 */
const "es6.tailCall": Transformer;

Block Scoping TDZ

/**
 * Add temporal dead zone checks for let/const
 */
const "es6.blockScopingTDZ": Transformer;

ES7 Transformers

Array/Generator Comprehensions

/**
 * Transform array and generator comprehensions
 * Input: [for (x of arr) if (x > 0) x * 2]
 * Output: Equivalent for-loop with array building
 */
const "es7.comprehensions": Transformer;

Object Rest/Spread

/**
 * Transform object rest and spread properties
 * Input: {a, ...rest} = obj; newObj = {...obj, b: 2};
 * Output: Object.assign and destructuring equivalents
 */
const "es7.objectRestSpread": Transformer;

Exponentiation Operator

/**
 * Transform exponentiation operator
 * Input: a ** b
 * Output: Math.pow(a, b)
 */
const "es7.exponentiationOperator": Transformer;

Abstract References

/**
 * Transform abstract property references
 */
const "es7.abstractReferences": Transformer;

ES5 Transformers

Property Mutators

/**
 * Transform ES5 property getters and setters for older environments
 */
const "es5.properties.mutators": Transformer;

ES3 Transformers

Property Literals

/**
 * Quote reserved words used as property names
 * Input: obj.class
 * Output: obj["class"]
 */
const "es3.propertyLiterals": Transformer;

Member Expression Literals

/**
 * Quote reserved words in member expressions
 * Input: obj.class
 * Output: obj["class"]
 */
const "es3.memberExpressionLiterals": Transformer;

Other Transformers

React

/**
 * Transform JSX to React.createElement calls
 * Input: <div className="foo">Hello</div>
 * Output: React.createElement("div", {className: "foo"}, "Hello")
 */
const react: Transformer;

Flow

/**
 * Remove Flow type annotations
 * Input: function fn(x: number): string {}
 * Output: function fn(x) {}
 */
const flow: Transformer;

Regenerator

/**
 * Transform async/await and generators using regenerator
 * Input: async function fn() { await promise; }
 * Output: regenerator-based state machine
 */
const regenerator: Transformer;

Async to Generator

/**
 * Transform async functions to generators
 * Input: async function fn() {}
 * Output: function fn() { return _asyncToGenerator(function* () {})(); }
 */
const asyncToGenerator: Transformer;

Bluebird Coroutines

/**
 * Transform async functions to Bluebird coroutines
 */
const bluebirdCoroutines: Transformer;

React Compatibility

/**
 * Make React transformer produce pre-v0.12 compatible code
 */
const reactCompat: Transformer;

Use Strict

/**
 * Add "use strict" directive to modules
 */
const useStrict: Transformer;

Self Contained

/**
 * Include helper functions inline instead of requiring runtime
 */
const selfContained: Transformer;

Validation Transformers

Undeclared Variable Check

/**
 * Check for references to undeclared variables
 */
const "validation.undeclaredVariableCheck": Transformer;

No For-In-Of Assignment

/**
 * Prevent assignment in for-in and for-of loop heads
 */
const "validation.noForInOfAssignment": Transformer;

Setters

/**
 * Validate setter method signatures
 */
const "validation.setters": Transformer;

React Validation

/**
 * Validate React JSX usage
 */
const "validation.react": Transformer;

Spec Transformers

Block Scoped Functions

/**
 * Handle block-scoped function declarations per spec
 */
const "spec.blockScopedFunctions": Transformer;

Proto to Assign

/**
 * Transform __proto__ to Object.setPrototypeOf
 */
const "spec.protoToAssign": Transformer;

Typeof Symbol

/**
 * Handle typeof Symbol correctly
 */
const "spec.typeofSymbol": Transformer;

Undefined to Void

/**
 * Transform undefined to void 0
 */
const "spec.undefinedToVoid": Transformer;

Minification Transformers

Remove Debugger

/**
 * Remove debugger statements
 */
const "minification.removeDebugger": Transformer;

Remove Console Calls

/**
 * Remove console method calls
 */
const "minification.removeConsoleCalls": Transformer;

Dead Code Elimination

/**
 * Remove unreachable code
 */
const "minification.deadCodeElimination": Transformer;

Rename Local Variables

/**
 * Rename local variables to shorter names
 */
const "minification.renameLocalVariables": Transformer;

Playground Transformers

Experimental transformers for proposed features:

/**
 * Mallet operator transformer
 */
const "playground.malletOperator": Transformer;

/**
 * Method binding transformer  
 */
const "playground.methodBinding": Transformer;

/**
 * Memoization operator transformer
 */
const "playground.memoizationOperator": Transformer;

/**
 * Object getter memoization transformer
 */
const "playground.objectGetterMemoization": Transformer;

Internal Transformers

System transformers used internally:

/**
 * Module handling transformer
 */
const _modules: Transformer;

/**
 * Block hoisting transformer
 */
const _blockHoist: Transformer;

/**
 * Declaration handling transformer
 */
const _declarations: Transformer;

/**
 * Function aliasing transformer
 */
const _aliasFunctions: Transformer;

/**
 * Module formatter application
 */
const _moduleFormatter: Transformer;

/**
 * Final cleanup transformer
 */
const _cleanUp: Transformer;

Usage Examples

Enable Specific Transformers

const to5 = require("6to5");

// Enable only arrow functions and classes
const result = to5.transform(code, {
  whitelist: ["es6.arrowFunctions", "es6.classes"]
});

// Enable all ES6 transformers
const es6Result = to5.transform(code, {
  whitelist: to5.namespaces.es6
});

Disable Specific Transformers

// Transform everything except modules
const result = to5.transform(code, {
  blacklist: ["es6.modules"]
});

// Disable all minification
const readable = to5.transform(code, {
  blacklist: to5.namespaces.minification
});

Optional Transformers

// Enable experimental ES7 features
const futuristic = to5.transform(code, {
  optional: [
    "es7.comprehensions",
    "es7.objectRestSpread",
    "es7.exponentiationOperator"
  ]
});

// Enable playground features
const experimental = to5.transform(code, {
  playground: true,
  optional: [
    "playground.methodBinding",
    "playground.memoizationOperator"
  ]
});

Loose Mode

// Enable loose mode for faster/smaller output
const loose = to5.transform(code, {
  loose: [
    "es6.classes",        // No __proto__ checks
    "es6.modules",        // Simpler module compilation
    "es6.forOf"          // Assume arrays for for-of
  ]
});

Namespace Usage

// Get all transformers in a namespace
console.log("ES6 transformers:", to5.namespaces.es6);

// Enable entire namespace
const result = to5.transform(code, {
  whitelist: to5.namespaces.es6.concat(to5.namespaces.es7)
});