Coder Social home page Coder Social logo

ast-parser's Introduction

My Components

  • Scena: Animation Editor (Main Project)
  • Moveable: Move tool for Drag & Resize & Rotate.
  • Scene.js: JavaScript & CSS timeline-based animation library
  • Selecto: Select elements in the drag area using the mouse or touch.
  • Infinite Viewer: Document Viewer Component with infinite scrolling
  • Guides: Draw ruler and manage guidelines.
  • Scene.js Timeline: Represents the timeline of Scene.js. You can control time, properties, and items.
  • Ruler: Draw grids and scroll infinitely
  • Gesto: drag or pinch in any browser.

ast-parser's People

Contributors

daybrush avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

ast-parser's Issues

BlockStatement is not handled correctly

tempalte: '{}'

First I have notice there is naming error temaplte vs template.
Then when content of this type of nodes is lost and can be accessed when traversing result AST.

Example for which I have tested it:

@Injectable()
export class NotesFiltersEffects {
  getFromLocalStorage$ = createEffect(() =>
    this.actions
      .pipe(
        ofType(getNotesFiltersFromLocalStorage),
        map(({defaultNoteFilter}: { defaultNoteFilter: NotesFiltersInterface}) => {
          let existingNoteFilter: NotesFiltersInterface | null = JSON.parse(localStorage.getItem(defaultNoteFilter.id));
          if (!existingNoteFilter) {
            return getNotesFiltersFromLocalStorageFail({defaultNoteFilter});
          } else {
            if (!existingNoteFilter.searchPhrases) {
              existingNoteFilter = {
                ...existingNoteFilter,
                searchPhrases: []
              };
            }
            return getNotesFiltersFromLocalStorageSuccess({existingNoteFilter});
          }
        })
      )
  );
  constructor(private actions: Actions) {
  }
}

Reproduce:

import * as fs from 'fs'
import { parse as babelParse } from '@babel/parser'
import { parse as astParse } from 'ast-parser'

function getNode(code) {
  return babelParse(code, {
    sourceType: 'module',
    plugins: [
      'classProperties',
      'typescript',
      'decorators-legacy'
    ],
  });
}

const source = fs.readFileSync('test.ts', { encoding: 'utf8' });

const ast = astParse(getNode(source));

function hereIsProblem(node) {
  console.log('NODE:', node);
  console.log('MISING FUNCTION BODY:', node.string)
}

ast.program.body
  .filter(({ nodeType }) => nodeType === 'ExportNamedDeclaration')
  .map(({ declaration }) => declaration)
  .filter(({ nodeType }) => nodeType === 'ClassDeclaration')
  .forEach((declaration) => {
    try {
      declaration.body.body.filter(({ nodeType }) => nodeType === 'ClassProperty').forEach((property) => {

        if (property.value.nodeType === 'CallExpression') {
          if (property.value.callee.name === 'createEffect') {
            const createEffectCallbackSourceAST = property.value.arguments[ 0 ].body;
            if (createEffectCallbackSourceAST.nodeType !== 'CallExpression') {
              throw Error('Unhandled createEffect body')
            }

            if (!createEffectCallbackSourceAST.callee.string.startsWith('this.actions')) {
              throw Error('None standard use of createEffect callback');
            }

            const pipe = createEffectCallbackSourceAST.arguments;

            const lastIndexOfTriggers = pipe.findIndex(({ callee: { name } }) => name === 'ofType');
            const effectActionsTriggers = pipe.slice(lastIndexOfTriggers + 1);

            effectActionsTriggers.forEach((trigger) => hereIsProblem(trigger));
          }
        } else {
          throw new Error(`Unhandled property type: ${ property.value.nodeType } `)
        }

      });
    } catch (e) {
      console.error('effect module parsing error/class property', e)
    }
  });

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.