acorn-to-esprima
Convert acorn tokens to esprima
Last updated 9 years ago by hzoo .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install acorn-to-esprima 
SYNC missed versions from official npm registry.

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 is require("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, and token.value
  • function toAST(ast, traverse)
    • traverse is require("babel-core").traverse;
    • traverses over the ast and makes any necessary changes (usually es6+)
  • function convertComments(comments)
    • Modifies comment.type

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;
}

Current Tags

  • 2.0.8                                ...           latest (9 years ago)

15 Versions

  • 2.0.8                                ...           9 years ago
  • 2.0.7                                ...           9 years ago
  • 2.0.6                                ...           9 years ago
  • 2.0.4                                ...           9 years ago
  • 2.0.3                                ...           9 years ago
  • 2.0.2                                ...           9 years ago
  • 2.0.1                                ...           9 years ago
  • 2.0.0                                ...           9 years ago
  • 1.0.7                                ...           9 years ago
  • 1.0.6                                ...           9 years ago
  • 1.0.5                                ...           9 years ago
  • 1.0.4                                ...           9 years ago
  • 1.0.3                                ...           9 years ago
  • 1.0.2                                ...           9 years ago
  • 1.0.1                                ...           9 years ago
Maintainers (2)
Downloads
Total 0
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (0)
None

© 2010 - cnpmjs.org x YWFE | Home | YWFE