index.js 779 B

123456789101112131415161718192021222324252627282930
  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. // convert tokens
  8. ast.tokens = toTokens(ast.tokens, tt, code);
  9. // add comments
  10. convertComments(ast.comments);
  11. // transform esprima and acorn divergent nodes
  12. toAST(ast, traverse, code);
  13. // ast.program.tokens = ast.tokens;
  14. // ast.program.comments = ast.comments;
  15. // ast = ast.program;
  16. // remove File
  17. ast.type = "Program";
  18. ast.sourceType = ast.program.sourceType;
  19. ast.directives = ast.program.directives;
  20. ast.body = ast.program.body;
  21. delete ast.program;
  22. attachComments(ast, ast.comments, ast.tokens);
  23. };