lib/index.js
/**
 * Transform the given next-generation JavaScript AST into a JavaScript AST
 * usable in today's runtime environments. Pass options to control which
 * features to include. By default, all options are enabled.
 *
 * Options
 *
 *   arrowFunction - Compile ES6 arrow functions into normal functions.
 *   class - Compile ES6 classes into ES5 constructors.
 *   computedPropertyKeys - Compile ES6 computed property keys.
 *   defaultParams - Compile ES6 default parameters to ES5.
 *   destructuring - Compile ES6 destructuring assignment.
 *   generator - Compile generator functions into ES5.
 *   objectConcise - Compile object literal concise method definitions.
 *   objectShorthand - Compile ES6 object literal shorthand assignment.
 *   rest - Compile rest params into ES5.
 *   spread - Compile spread operator.
 *   templates - Compile template strings into ES5.
 *
 * @param {object} ast
 * @param {object} options
 * @return {object}
 */
Transform the given next-generation JavaScript AST into a JavaScript AST
usable in today's runtime environments. Pass options to control which
features to include. By default, all options are enabled.

Options

Compile ES6 arrow functions into normal functions.
class - Compile ES6 classes into ES5 constructors.
computedPropertyKeys - Compile ES6 computed property keys.
defaultParams - Compile ES6 default parameters to ES5.
destructuring - Compile ES6 destructuring assignment.
generator - Compile generator functions into ES5.
objectConcise - Compile object literal concise method definitions.
objectShorthand - Compile ES6 object literal shorthand assignment.
rest - Compile rest params into ES5.
spread - Compile spread operator.
templates - Compile template strings into ES5.


Transform the given next - generation JavaScript AST into a JavaScript AST usable in today ' s runtime environments . Pass options to control which features to include . By default all options are enabled . Options Compile ES6 arrow functions into normal functions . class - Compile ES6 classes into ES5 constructors . computedPropertyKeys - Compile ES6 computed property keys . defaultParams - Compile ES6 default parameters to ES5 . destructuring - Compile ES6 destructuring assignment . generator - Compile generator functions into ES5 . objectConcise - Compile object literal concise method definitions . objectShorthand - Compile ES6 object literal shorthand assignment . rest - Compile rest params into ES5 . spread - Compile spread operator . templates - Compile template strings into ES5 .
function transform(ast, options) {
  if (!options) { options = {}; }
  if (options.computedPropertyKeys !== false) {
    ast = es6computedProperties.transform(ast);
  }
  if (options.arrowFunction !== false) {
    ast = es6arrowfn.transform(ast);
  }
  if (options['class'] !== false) {
    ast = es6class.transform(ast);
  }
  if (options.rest !== false) {
    ast = es6restParams.transform(ast);
  }
  if (options.defaultParams !== false) {
    ast = es6defaultParams.transform(ast);
  }
  if (options.generator !== false) {
    ast = regenerator.transform(ast);
  }
  if (options.regexpu !== false) {
    ast = regexpu.transform(ast);
  }
  if (options.spread !== false) {
    ast = es6spread.transform(ast);
  }
  if (options.templates !== false) {
    ast = es6templates.transform(ast);
  }
  if (options.generator !== false && options.includeRuntime) {
    var runtime = fs.readFileSync(regenerator.runtime.path, 'utf8');
    injectRuntime(runtime, regenerator.runtime.path, ast.program);
  }
  if (options.destructuring !== false) {
    ast = es6destructuring.transform(ast);
  }
  if (options.objectShorthand !== false) {
    ast = es6objectShort.transform(ast);
  }
  if (options.objectConcise !== false) {
    ast = es6objectConcise.transform(ast);
  }
  return ast;
}
function transform ( ast , options ) { if ( ! options ) { options = { } ; } if ( options . computedPropertyKeys !== false ) { ast = es6computedProperties . transform ( ast ) ; } if ( options . arrowFunction !== false ) { ast = es6arrowfn . transform ( ast ) ; } if ( options [ 'class' ] !== false ) { ast = es6class . transform ( ast ) ; } if ( options . rest !== false ) { ast = es6restParams . transform ( ast ) ; } if ( options . defaultParams !== false ) { ast = es6defaultParams . transform ( ast ) ; } if ( options . generator !== false ) { ast = regenerator . transform ( ast ) ; } if ( options . regexpu !== false ) { ast = regexpu . transform ( ast ) ; } if ( options . spread !== false ) { ast = es6spread . transform ( ast ) ; } if ( options . templates !== false ) { ast = es6templates . transform ( ast ) ; } if ( options . generator !== false && options . includeRuntime ) { var runtime = fs . readFileSync ( regenerator . runtime . path , 'utf8' ) ; injectRuntime ( runtime , regenerator . runtime . path , ast . program ) ; } if ( options . destructuring !== false ) { ast = es6destructuring . transform ( ast ) ; } if ( options . objectShorthand !== false ) { ast = es6objectShort . transform ( ast ) ; } if ( options . objectConcise !== false ) { ast = es6objectConcise . transform ( ast ) ; } return ast ; }
Transform the given next-generation JavaScript AST into a JavaScript AST
 usable in today's runtime environments.
Transform the given next - generation JavaScript AST into a JavaScript AST usable in today ' s runtime environments .