Giter Site home page Giter Site logo

travetto / compiler Goto Github PK

View Code? Open in Web Editor NEW
1.0 3.0 0.0 228 KB

Node-integration of Typescript Compiler with advanced functionality for collecting AST transformers, and detecting changes in classes and methods.

Home Page: https://travetto.io

License: MIT License

TypeScript 99.13% JavaScript 0.87%
tsc typescript compiler caching ast-transformations change-detection real-time travetto

compiler's Introduction

travetto: Compiler

The framework, while using typescript, has need of some extended functionality. The additional functionality is

  • Supports on-the-fly compilation, nothing needs to be compiled ahead of time
  • Enhanced AST transformations, and transformer registration
    • All AST transformations are single-file based, and runs without access to the TypeChecker
  • Intelligent caching of source files to minimize recompilation
  • Support for watching sources files:
    • Detecting changes to files
    • Detecting changes to specific classes
    • Detecting changes to specific methods within classes
  • Allows for hot-reloading of classes during development
    • Utilizes es2015 Proxys to allow for swapping out implementation at runtime

Additionally, there is support for common AST transformation patterns to facilitate all the transformers used throughout the framework. Functionality includes:

  • getDecoratorIdent(d: ts.Decorator): ts.Identifier Gets the name of the decorator function
  • findAnyDecorator(node: ts.Node, patterns: { [key: string]: Set<string> }, state: State): ts.Decorator | undefined Attempts to find any matching decorators as defined in patterns
  • addImport(file: ts.SourceFile, imports: Import[]) Will add an import to the existing source file
  • fromLiteral(val: any) Converts a literal value to the corresponding AST nodes
  • extendObjectLiteral(addTo: object, lit?: ts.ObjectLiteralExpression)
    Extends an AST Node via a literal value, generally used to emulate Object.assign in the AST
  • getPrimaryArgument<T = ts.Node>(node: ts.CallExpression | ts.Decorator | undefined): T | undefined Retrieves the first argument of CallExpression or Decorator
  • getObjectValue(node: ts.ObjectLiteralExpression | undefined, key: string) Extracts the literal value from an AST node if possible
  • importingVisitor Provides a transformer visitor that collects imports, and adds them to the source file as needed
  • importIfExternal<T extends State>(typeNode: ts.TypeNode, state: State) Will import a reference if the type is not defined within the file
  • buildImportAliasMap(pathToType) Will generate an import lookup to be used for simple type resolution

Transformations are defined by support/transformation.<name>.ts as the filename. The schema for a transformer is

  export class CustomerTransformer {
    priority: 1, // Lower is higher priority
    phase: 'before'|'after', // The phase as defined by Typescript's AST processing
    transformer: (context: ts.TransformationContext) => {
       return (file: ts.SourceFile) => {
         ... modify source file ...
         return file;
       }
    }
  }

compiler's People

Contributors

arciisine avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

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.