Giter Club home page Giter Club logo

astexplorer's Introduction

AST explorer

Gitpod ready-to-code Join the chat at https://gitter.im/astexplorer/Lobby Build Status

Paste or drop code into the editor and inspect the generated AST on https://astexplorer.net/

The AST explorer provides following code parsers:

Experimental / custom syntax

Depending on the parser settings, it not only supports ES5/CSS3 but also

Transforms

Since future syntax is supported, the AST explorer is a useful tool for developers who want to create AST transforms. In fact, following transformers are included so you can prototype your own plugins:

More Features

  • Save and fork code snippets. Copy the URL to share them.
  • Copying an AST or dropping a file containing an AST into the window will parse the AST and update the code using escodegen.
  • Otherwise, the content of text editor will be replaced with the content of the file (i.e. you can drag and drop JS files).
  • Choose between multiple parsers and configure them.
  • shift+click on a node expands the full subtree.
  • Hovering over a node highlights the corresponding text in the source code
  • Editing the source or moving the cursor around will automatically highlight the corresponding AST node (or its ancestors of it isn't expanded)
  • You can use $node in the console to refer to the last opened/toggled AST node.

Contributions

I'm happy about any feedback, feature request or PR to make this tool as useful as possible!


How to add a new parser

  1. Go to website/.
  2. Install the new parser as dependency: yarn add theParser
  3. Copy one of the existing examples in src/parsers/{language}.
  4. Adjust the code as necessary:
  • Update metadata.
  • Load the right parser (loadParser).
  • Call the right parsing method with the right/necessary options in parse.
  • Implement the nodeToRange method (this is for highlighting).
  • Implement the getNodeName method (this is for quick look through the tree).
  • Implement opensByDefault method for auto-expansion of specific properties.
  • Define _ignoredProperties set or implement forEachProperty generator method for filtering.
  • Provide a renderSettings method if applicable.

How to add a new transformer

  1. Go to website/.
  2. Install the new transformer as dependency.
  3. Copy one of the existing examples in src/parsers/{language}/transformers.
  4. Adjust the code as necessary:
  • Update metadata and defaultParserID.
  • Load the right transformer (loadTransformer).
  • Call the transformation method in transform.
  • Change sample transformation code in codeExample.txt.

Build your own version for development

IMPORTANT: For various reasons the project still requires Node.js version 16 (see .tools-versions). If you use a tool like asdf switching versions will happen automatically.

  1. Clone the repository.
  2. Go to website/.
  3. Install all dependencies with yarn install

Run yarn run build for the final minimized version. Run yarn run watch for incremental builds.

Run yarn start to start a simple static webserver.

astexplorer's People

Contributors

aceslick911 avatar aladdin-add avatar btmills avatar christianmurphy avatar danez avatar fkling avatar gabelevi avatar gabro avatar gengjiawen avatar hzoo avatar irustm avatar iwanabethatguy avatar jeffmo avatar jlhwung avatar josephfrazier avatar lahmatiy avatar metonym avatar motiz88 avatar mroch avatar nmalaguti avatar nzakas avatar rreverser avatar rundevelopment avatar rwjblue avatar skratchdot avatar smelukov avatar timothygu avatar turbo87 avatar vtrushin avatar wooorm 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  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  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  avatar

Watchers

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

astexplorer's Issues

Feature request: Show a diff between parsers

Not sure how we would show this or if we could make it look good but it would be useful (for me at least) to compare the AST tree between different parsers (in particular babel/esprima for babel-eslint). 😄

Issue with removing the transform panes when switching

When you switch between languages, should the transform change automatically (ex: after switching from js/babel to html, the babel transform pane is still there). In the case of switching to html the pane stays on the screen even though the transform toggle is disabled.

Switch to CloudFlare?

@fkling Would you be interested in putting astexplorer.net behind CloudFlare? Free plan should work perfectly, and will give HTTPS, HTTP/2 + SPDY and CDN out of the box which should speed up loading our bundles for users.

Let tools specify parser settings

Currently tools can only specify which parser to use (so it is selected by default) but not parser settings, which is required as well sometimes.

Make astexplorer standalone / embeddable

People reached out to be and showed interest in an embeddable version of astexplorer. This thread should explore how this would look like and what needs to be done.

I think there are two ways to achieve this and ideally we can support both:

  1. Make astexplorer configurable via the URL so it can be embedded via an <iframe>.
  2. Create a (more) reusable React component that can be used wherever React can be rendered.
  3. ?

1. <iframe>

This should be fairly straightforward. The URL could contain UI options, such as the chosen parser, chosen transform, which visualization to show, whether switching parsers is allowed or not, etc. Basically just ways to configure how astexplorer looks like and optimize it a bit for smaller space (e.g. instead of side-by-side panes we could have tabs).

2. Dedicated React component

This probably requires bigger refactoring but could also be the most flexible solution since it could be used outside of browser environments (e.g. Electron apps). The component would be close to the main component in app.js but provide more configuration options. There some open questions:

  • Should the toolbar be part of such a component?
  • If yes, how would lazy loading the parsers work if we don't have any control over the build step?

Maybe the easier solution is to let the calling code pass the available parsers to the component. They would have to comply with our interface, but that shouldn't be too bad.

It would also be great if the calling code could add custom visualization / output panes (e.g. the transpiled code like in https://babeljs.io/repl/).

Feature Request: Indication if transform is stable or not

Would be nice to run the transform script twice, once on the original source, and then again on the transformed source. Then show a warning if the source changes on the second transform. If it does change that means it's probably not safe to run the script multiple times over the same codebase.

Add support for shareable URLs

We could either encode the source code in the URL if it's short enough, or use something like Parse.com to store documents (or both!).

Shows errors for valid jscodeshift transform

Hi,

Thanks for this amazing tool.

This transform is passing tests on my machine locally. But I get this error Cannot read property 'node' of undefined in astexplorer. This is my original repo and the transform is initializer-arity.

Sometime missing a semicolon at the end of statement seems to trigger similar kind of errors. Here is reproducable example And the semicolon is missing for the statement root.find(j.FunctionDeclaration, ...).....

Persist parser and parser settings in URL

To make sharing code snippets easier, it would be convenient to store the selected parser and parser settings in the URL.

However, I don't really like to update the current URI with that information, since it will look ugly and mess with the browser history. Instead, we could add a "share" button that shows a copyable version of the URL, just like jsfiddle does.

I'm already working on this.

Suggestions

This project is a nice playground for all those parsers. Thank you for making this!

I believe that for most people who stumble upon it, we are trying to find the best AST parser for our specific tasks.

And as far as the decision-making goes, your project is missing some key information that would simplify things for a researcher.

I understand you want your project to stay neutral about all the existing AST projects, but at least some basic statistics would have been really helpful:

  • Performance charts
  • Memory consumption charts
  • Level of support for ES5, ES6, ES7
  • Tree-Navigation features, performance

Not only this would be a great help to those who is trying to make the best pick among AST parsers, but also for the developers of AST projects to be able to see where their project has weaknesses.

Add more tools

There are many more tools besides jscodeshift which could be added to the ast explorer for quick prototyping / testing. For example:

  • eslint plugin development
  • babel plugin development

To make adding new tools easy, some refactoring of the client side code and the DB schema is necessary. I already have a proof of concept commit locally but it still needs more tweaking.

The current idea/plan is that "tools" are React components which are rendered below the code editor and ast panel (just like the transform tool now) and which have access to

  • The current parser
  • The current code
  • An API to highlight parts and show errors in the code editor

Tools would also be able to specify which parsers they work together with. They could render whatever interface they need.

Add inline documentation for ast-type constructors

I've been thinking about how to best document jscodeshift and i think that having auto-complete/typeahead inside of astexplorer.net would be huge.

My biggest annoyance when writing codemods is that I want to create a node of type Something
but i don't know what arguments it takes.

Being able to do t.something(<list of arguments from ast-types>) would be great or, maybe at the bottom of the screen, when you select t.something, it shows the type definition.

Add Babel 6

Because Babel 6 uses a slightly different AST and plugin definition, I think it makes sense to add it as separate option (parser and transformer) instead of just upgrading Babel.

Can't recover from infinite loops

For example, just write while(true); in the transform script and the whole browser will freeze when the code is run.

(practically I ran into this by introducing some accidental infinite recursion)

Instead of solving the halting problem, it would be cool if we just put a timeout on the transform and killed it after 30 seconds or so.

Chrome DevTools fails to set breakpoints

when i try to set a breakpoint in Devtools, it's either not set of jumps to a bad place in the source map. Is this something you're seeing as well?

gif

P.S. Other than that, I really like the breakdown of the app. Really clean

can't run locally

I ran npm install and either npm run watch or npm run build and in another tab terminal I run npm start yet this is the contents of index.html:

<!DOCTYPE html>
<html>
  <head>
    <title>AST explorer</title>
    <meta charset="UTF-8">
    <meta name="description" content="An online AST explorer.">
    <script>
      window.webpackManifest = {%# o.manifest %}
    </script>
  </head>
  <body>
    <div id="page">
      <div id="container"></div>
      <div id="contribution">
        Built using
        <a href="http://facebook.github.io/react/">React</a>,
        <a href="http://babeljs.io/">Babel</a>,
        <a href="http://fortawesome.github.io/Font-Awesome/">Font Awesome</a>,
        <a href="https://parse.com">Parse.com</a>,
        <a href="http://codemirror.net/">CodeMirror</a>
        and
        <a href="https://webpack.github.io/">WebPack</a>
        |
        <a href="https://github.com/fkling/esprima_ast_explorer">GitHub</a>
      </div>
    </div>
  </body>
</html>

it looks like it's not modifying window.webpackManifest = {%# o.manifest %}

I'm on mac os with node v5.1.0 and npm 3.3.12
I'm also getting the same issue on node v4 too

URL for special language

Maybe we should have some shortcut to enable features. Like if you go to http://astexplorer.net/#postcss it will enable CSS and PostCSS.

Can't run locally for modifications

Tried to build & run locally, but got:

TypeError: $def is not a function in browser console in following context:

loadjs.d("323",function(require,module,exports){
// 19.1.3.1 Object.assign(target, source)
var $def = require('./$.def');

$def($def.S + $def.F, 'Object', {assign: require('./$.assign')});
},{"./$.assign":210,"./$.def":219});

loadjs.d("949",function(require,module,exports){

Minification error

Webpack (therefore UglifyJS) has problems minifying some files:

ERROR in app-6fe76ad4fb1070d5cdee.js from UglifyJs
Unexpected token punc «,», expected arrow «=>» [./~/codemirror/mode/javascript/javascript.js:363,0]

ERROR in 1-595b1745447d2e8d1d87.js from UglifyJs
Unexpected token punc «;», expected arrow «=>» [./~/codemirror/addon/tern/tern.js:324,0]

ERROR in 15-97b6ed0349ff4e6be2c6.js from UglifyJs
Unexpected token punc «;», expected arrow «=>» [./~/recast/lib/printer.js:196,0]

ERROR in 16-9ab0ec6c3bb5ef480ff7.js from UglifyJs
Unexpected token punc «)», expected arrow «=>» [./~/shift-parser/dist/pattern-acceptor.js:146,0]

ERROR in 18-4a8de760966ccf94578c.js from UglifyJs
Unexpected token punc «;», expected arrow «=>» [./~/babel-generator/lib/printer.js:79,0]

ERROR in 19-80325d20605b9cfcf9bf.js from UglifyJs
Unexpected token punc «;», expected arrow «=>» [./~/recast/lib/printer.js:196,0]

ERROR in 20-dc214efd0de9edbdb9bd.js from UglifyJs
Unexpected token punc «;», expected arrow «=>» [./~/typescript/lib/typescript.js:30938,0]

ERROR in 22-2661016f44c06a5eb7c6.js from UglifyJs
Unexpected token punc «)», expected arrow «=>» [./~/webidl2/lib/webidl2.js:234,0]

ERROR in 23-5b2dcb9b24f8a5691072.js from UglifyJs
Unexpected token punc «;», expected arrow «=>» [./~/escodegen/escodegen.js:907,0]

ERROR in 26-6d6700619899083ed12c.js from UglifyJs
Unexpected token punc «;», expected arrow «=>» [./~/esprima/esprima.js:2925,0]

Idea: Run recast transformations

Let the visitor write recast code to transform the AST. Maybe even animate the changes somehow? (e.g. step by step walk through).

Change placement of parser information

The toolbar is now so wide that parser information is not always shown properly on narrow screens. This is from a 13" screen:

screen shot 2015-12-08 at 10 33 05 am

Any suggestions for how/where to put this? Or should we simply break on white space?

not working?

none of the buttons in the nav seems to be working...

Time to rename repo?

Since it's not just Esprima anymore, maybe it's worth to rename the repo to make it less confusing? Github takes care of redirects after renamings, so it should be harmless.

Feature request: settings for transformer

Transformer doesn't work for some ES7 features like decorators. But parser works fine, as has option for it.

Simple example:

@decorator
class A {}

This cose cause to error in transformer:

image

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.