This repository has been archived by the owner on Aug 18, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move ast convert steps to babylon-to-espree
- Loading branch information
Showing
2 changed files
with
33 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,34 @@ | ||
exports.attachComments = require("./attachComments"); | ||
var attachComments = require("./attachComments"); | ||
var convertComments = require("./convertComments"); | ||
var toTokens = require("./toTokens"); | ||
var toAST = require("./toAST"); | ||
|
||
exports.toTokens = require("./toTokens"); | ||
exports.toAST = require("./toAST"); | ||
module.exports = function (ast, traverse, tt, code) { | ||
// remove EOF token, eslint doesn't use this for anything and it interferes | ||
// with some rules see https://github.com/babel/babel-eslint/issues/2 | ||
// todo: find a more elegant way to do this | ||
ast.tokens.pop(); | ||
|
||
exports.convertComments = require("./convertComments"); | ||
// convert tokens | ||
ast.tokens = toTokens(ast.tokens, tt, code); | ||
|
||
// add comments | ||
convertComments(ast.comments); | ||
|
||
// transform esprima and acorn divergent nodes | ||
toAST(ast, traverse, code); | ||
|
||
// ast.program.tokens = ast.tokens; | ||
// ast.program.comments = ast.comments; | ||
// ast = ast.program; | ||
|
||
// remove File | ||
ast.type = "Program"; | ||
ast.sourceType = ast.program.sourceType; | ||
ast.directives = ast.program.directives; | ||
ast.body = ast.program.body; | ||
delete ast.program; | ||
delete ast._paths; | ||
|
||
attachComments(ast, ast.comments, ast.tokens); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters