acorn-to-esprima
Some functions to help transform an acorn/babel ast to esprima format.
Primarily for use in babel-eslint, babel-jscs, and ast explorer
There are no dependencies (the methods were changed to pass in dependencies instead)
The current functions exposed are:
function attachComments(ast, comments, tokens)
- This modifies the comments passed in.
function toTokens(tokens, tt)
tt
isrequire("babel-core").acorn.tokTypes
- Converts template string tokens (
convertTemplateType
) - filters out comment tokens
- runs
toToken
over each token
function toToken(token, tt)
- Sets
token.type
,token.range
, andtoken.value
- Sets
function toAST(ast, traverse)
traverse
isrequire("babel-core").traverse;
- traverses over the ast and makes any necessary changes (usually es6+)
function convertComments(comments)
- Modifies
comment.type
- Modifies
How to use:
Check out the parse method of https://github.com/babel/babel-eslint/blob/master/index.js
// exampleexports { var comments = optsonComment = ; var tokens = optsonToken = ; var ast; try ast = ; catch err throw err; tokens; asttokens = acornToEsprima; acornToEsprima; astcomments = comments; acornToEsprima; acornToEsprima; return ast;}