'use strict';
let fs = require('fs');
let path = require('path');

/* For regular JS files */
//let esprima = require('esprima');
//let escodegen = require('escodegen');

/* For files with JSX syntax */
let esprimaFb = require('esprima-fb');
let escodegenJsx = require('escodegen-wallaby');

const read = function(path) {
  const data = fs.readFileSync(path, 'utf8');
  const options = {
    sourceType: 'module',
    range: true,
    tokens: true,
    comment: true
  };

  return esprimaFb.parse(data, options);
};

const write = function(path, tree) {
  tree = escodegenJsx.attachComments(tree, tree.comments, tree.tokens);
  let options = { comment: true, format: { indent: { style: '  ' } } };
  let code = escodegenJsx.generate(tree, options) + '\n';
  fs.writeFileSync(path, code, 'utf8');
};

const getDestinationPath = function(name, type, suffix) {
  const prefix = path.join('src', type, name);
  return [prefix, suffix].join('.');
};

const getRelativePath = function(name, type, suffix) {
  const filePath = path.join('..', type, name);
  return [filePath, suffix].join('.');
};

const getBaseName = function(path) {
  const items = path.split('/');
  return items[items.length - 1];
}

module.exports = {
  read: read,
  write: write,
  getDestinationPath: getDestinationPath,
  getBaseName: getBaseName,
  getRelativePath: getRelativePath
}

@@ -7,18 +7,20 @@
 trict';%0A
-le
+cons
 t fs = r
@@ -33,18 +33,20 @@
 ('fs');%0A
-le
+cons
 t path =
@@ -93,18 +93,20 @@
 es */%0A//
-le
+cons
 t esprim
@@ -131,18 +131,20 @@
 ma');%0A//
-le
+cons
 t escode
@@ -204,18 +204,20 @@
 ntax */%0A
-le
+cons
 t esprim
@@ -245,18 +245,20 @@
 a-fb');%0A
-le
+cons
 t escode
@@ -634,18 +634,20 @@
 ens);%0A  
-le
+cons
 t option
@@ -708,18 +708,20 @@
  %7D %7D;%0A  
-le
+cons
 t code =

All requires are constant