src/node/api.js
function compile(content, options) {
  options = merge({
    outputLanguage: 'es5',
    modules: 'commonjs',
    filename: '<unknown file>',
    sourceMap: false,
    cwd: process.cwd(),
    moduleName: false
  }, options || {});

  var moduleName = options.moduleName;

  traceurOptions.reset();
  merge(traceurOptions, options);

  var errorReporter = new ErrorReporter();
  var sourceFile = new SourceFile(options.filename, content);
  var parser = new Parser(sourceFile, errorReporter);
  var tree = parser.parseModule();
  var transformer;
  if (moduleName === true || options.modules == 'register' || options.modules == 'inline') {
    moduleName = options.filename.replace(/\.js$/, '');
    moduleName = path.relative(options.cwd, moduleName).replace(/\\/g,'/');
  }
  if (moduleName) {
    transformer = new AttachModuleNameTransformer(moduleName);
    tree = transformer.transformAny(tree);
  }

  if (options.outputLanguage.toLowerCase() === 'es6') {
    transformer = new PureES6Transformer(errorReporter);
  } else {
    transformer = new FromOptionsTransformer(errorReporter);
  }

  var transformedTree = transformer.transform(tree);

  if (errorReporter.hadError()) {
    return {
      js: null,
      errors: errorReporter.errors,
      sourceMap: null
    };
  }

  var treeWriterOptions = {};

  if (options.sourceMap) {
    treeWriterOptions.sourceMapGenerator = new SourceMapGenerator({
      file: options.filename,
      sourceRoot: null
    });
  }

  return {
    js: TreeWriter.write(transformedTree, treeWriterOptions),
    errors: errorReporter.errors,
    sourceMap: treeWriterOptions.sourceMap || null
  };
}
function compile(content, options) {
  options = merge({
    outputLanguage: 'es5',
    modules: 'commonjs',
    filename: '<unknown file>',
    sourceMap: false,
    cwd: process.cwd(),
    moduleName: false
  }, options || {});

  var moduleName = options.moduleName;

  traceurOptions.reset();
  merge(traceurOptions, options);

  var errorReporter = new ErrorReporter();
  var sourceFile = new SourceFile(options.filename, content);
  var parser = new Parser(sourceFile, errorReporter);
  var tree = parser.parseModule();
  var transformer;
  if (moduleName === true || options.modules == 'register' || options.modules == 'inline') {
    moduleName = options.filename.replace(/\.js$/, '');
    moduleName = path.relative(options.cwd, moduleName).replace(/\\/g,'/');
  }
  if (moduleName) {
    transformer = new AttachModuleNameTransformer(moduleName);
    tree = transformer.transformAny(tree);
  }

  if (options.outputLanguage.toLowerCase() === 'es6') {
    transformer = new PureES6Transformer(errorReporter);
  } else {
    transformer = new FromOptionsTransformer(errorReporter);
  }

  var transformedTree = transformer.transform(tree);

  if (errorReporter.hadError()) {
    return {
      js: null,
      errors: errorReporter.errors,
      sourceMap: null
    };
  }

  var treeWriterOptions = {};

  if (options.sourceMap) {
    treeWriterOptions.sourceMapGenerator = new SourceMapGenerator({
      file: options.filename,
      sourceRoot: null
    });
  }

  return {
    js: TreeWriter.write(transformedTree, treeWriterOptions),
    errors: errorReporter.errors,
    sourceMap: treeWriterOptions.sourceMap || null
  };
}
function compile ( content , options ) { options = merge ( { outputLanguage : 'es5' , modules : 'commonjs' , filename : '<unknown file>' , sourceMap : false , cwd : process . cwd ( ) , moduleName : false } , options || { } ) ; var moduleName = options . moduleName ; traceurOptions . reset ( ) ; merge ( traceurOptions , options ) ; var errorReporter = new ErrorReporter ( ) ; var sourceFile = new SourceFile ( options . filename , content ) ; var parser = new Parser ( sourceFile , errorReporter ) ; var tree = parser . parseModule ( ) ; var transformer ; if ( moduleName === true || options . modules == 'register' || options . modules == 'inline' ) { moduleName = options . filename . replace ( / \.js$ / , '' ) ; moduleName = path . relative ( options . cwd , moduleName ) . replace ( / \\ / g , '/' ) ; } if ( moduleName ) { transformer = new AttachModuleNameTransformer ( moduleName ) ; tree = transformer . transformAny ( tree ) ; } if ( options . outputLanguage . toLowerCase ( ) === 'es6' ) { transformer = new PureES6Transformer ( errorReporter ) ; } else { transformer = new FromOptionsTransformer ( errorReporter ) ; } var transformedTree = transformer . transform ( tree ) ; if ( errorReporter . hadError ( ) ) { return { js : null , errors : errorReporter . errors , sourceMap : null } ; } var treeWriterOptions = { } ; if ( options . sourceMap ) { treeWriterOptions . sourceMapGenerator = new SourceMapGenerator ( { file : options . filename , sourceRoot : null } ) ; } return { js : TreeWriter . write ( transformedTree , treeWriterOptions ) , errors : errorReporter . errors , sourceMap : treeWriterOptions . sourceMap || null } ; }
Compile ES6 source code with Traceur.

TODO(vojta): Support source maps.

@param  {string} content ES6 source code.
@param  {Object=} options Traceur options.
@return {string} Transpiled ES5 code.
Compile ES6 source code with Traceur .