|
1 |
| -exports.attachComments = require("./attachComments"); |
| 1 | +var attachComments = require("./attachComments"); |
| 2 | +var convertComments = require("./convertComments"); |
| 3 | +var toTokens = require("./toTokens"); |
| 4 | +var toAST = require("./toAST"); |
2 | 5 |
|
3 |
| -exports.toTokens = require("./toTokens"); |
4 |
| -exports.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(); |
5 | 11 |
|
6 |
| -exports.convertComments = require("./convertComments"); |
| 12 | + // convert tokens |
| 13 | + ast.tokens = toTokens(ast.tokens, tt, code); |
| 14 | + |
| 15 | + // add comments |
| 16 | + convertComments(ast.comments); |
| 17 | + |
| 18 | + // transform esprima and acorn divergent nodes |
| 19 | + toAST(ast, traverse, code); |
| 20 | + |
| 21 | + // ast.program.tokens = ast.tokens; |
| 22 | + // ast.program.comments = ast.comments; |
| 23 | + // ast = ast.program; |
| 24 | + |
| 25 | + // remove File |
| 26 | + ast.type = "Program"; |
| 27 | + ast.sourceType = ast.program.sourceType; |
| 28 | + ast.directives = ast.program.directives; |
| 29 | + ast.body = ast.program.body; |
| 30 | + delete ast.program; |
| 31 | + delete ast._paths; |
| 32 | + |
| 33 | + attachComments(ast, ast.comments, ast.tokens); |
| 34 | +}; |
0 commit comments