index.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. "use strict";
  2. var attachComments = require("./attachComments");
  3. var convertComments = require("./convertComments");
  4. var toTokens = require("./toTokens");
  5. var toAST = require("./toAST");
  6. module.exports = function (ast, traverse, tt, code) {
  7. // remove EOF token, eslint doesn't use this for anything and it interferes
  8. // with some rules see https://github.com/babel/babel-eslint/issues/2
  9. // todo: find a more elegant way to do this
  10. ast.tokens.pop();
  11. // convert tokens
  12. ast.tokens = toTokens(ast.tokens, tt, code);
  13. // add comments
  14. convertComments(ast.comments);
  15. // transform esprima and acorn divergent nodes
  16. toAST(ast, traverse, code);
  17. // ast.program.tokens = ast.tokens;
  18. // ast.program.comments = ast.comments;
  19. // ast = ast.program;
  20. // remove File
  21. ast.type = "Program";
  22. ast.sourceType = ast.program.sourceType;
  23. ast.directives = ast.program.directives;
  24. ast.body = ast.program.body;
  25. delete ast.program;
  26. delete ast._paths;
  27. attachComments(ast, ast.comments, ast.tokens);
  28. };