transform(tree, candidateModuleName = undefined, metadata = undefined) {

    let transformer;
    if (candidateModuleName) {
      let transformer = new AttachModuleNameTransformer(candidateModuleName);
      tree = transformer.transformAny(tree);
    }

    let errorReporter = new CollectingErrorReporter();

    if (this.options_.outputLanguage.toLowerCase() === 'es6') {
      transformer = new PureES6Transformer(errorReporter, this.options_, metadata);
    } else {
      transformer = new FromOptionsTransformer(errorReporter, this.options_);
    }

    let transformedTree = transformer.transform(tree);
    this.throwIfErrors(errorReporter);
    return transformedTree;
  }
Apply transformations selected by options to tree.
@param {ParseTree} tree
@param {string} candidateModuleName used as the moduleName iff the
   moduleName option is set true
@return {ParseTree}