Giter Club home page Giter Club logo

acorn-to-esprima's Introduction

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

acorn-to-esprima's People

Contributors

benmosher avatar hzoo avatar jmm avatar mickalot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

acorn-to-esprima's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.