Home

Awesome

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:

How to use:

Check out the parse method of https://github.com/babel/babel-eslint/blob/master/index.js

// example
exports.parse = function (code) {
  var comments = opts.onComment = [];
  var tokens = opts.onToken = [];

  var ast;
  try {
    ast = parse(code, {
        locations: true,
        ranges: true
    });
  } catch (err) { throw err; }

  tokens.pop();
  ast.tokens = acornToEsprima.toTokens(tokens, tt);

  acornToEsprima.convertComments(comments);
  ast.comments = comments;
  acornToEsprima.attachComments(ast, comments, ast.tokens);

  acornToEsprima.toAST(ast, traverse);

  return ast;
}