/**
 * Copyright 2004-present Facebook. All Rights Reserved.
 *
 * Note: This is a fork of the fb-specific transform.js
 */
'use strict';

var jstransform = require('jstransform').transform;

var reactVisitors =
  require('react-tools/vendor/fbtransform/visitors').getAllVisitors();
var staticTypeSyntax =
  require('jstransform/visitors/type-syntax').visitorList;
// Note that reactVisitors now handles ES6 classes, rest parameters, arrow
// functions, template strings, and object short notation.
var visitorList = reactVisitors;


function transform(transformSets, srcTxt, options) {
  options = options || {};

  // These tranforms mostly just erase type annotations and static typing
  // related statements, but they were conflicting with other tranforms.
  // Running them first solves that problem
  var staticTypeSyntaxResult = jstransform(
    staticTypeSyntax,
    srcTxt
  );

  return jstransform(visitorList, staticTypeSyntaxResult.code);
}

module.exports = function(data, callback) {
  var result;
  try {
    result = transform(
      data.transformSets,
      data.sourceCode,
      data.options
    );
  } catch (e) {
    return callback(null, {
      error: {
        lineNumber: e.lineNumber,
        column: e.column,
        message: e.message,
        stack: e.stack,
        description: e.description
      }
    });
  }

  callback(null, result);
};

// export for use in jest
module.exports.transform = transform;

@@ -571,23 +571,18 @@
 cTxt
-, options
 ) %7B%0A  
+var 
 opti
@@ -591,20 +591,61 @@
 s = 
-options %7C%7C %7B
+%7B%0A    es3: true,%0A    sourceType: 'nonStrictModule'%0A  
 %7D;%0A%0A
@@ -911,16 +911,29 @@
   srcTxt
+,%0A    options
 %0A  );%0A%0A 
@@ -952,16 +952,21 @@
 ansform(
+%0A    
 visitorL
@@ -969,16 +969,20 @@
 torList,
+%0A   
  staticT
@@ -1001,16 +1001,32 @@
 ult.code
+,%0A    options%0A  
 );%0A%7D%0A%0Amo
@@ -1164,28 +1164,8 @@
 Code
-,%0A      data.options
 %0A   

Update jstransform/esprima