Giter VIP home page Giter VIP logo

babel-plugin-angular2-annotations's Introduction

build status npm version npm downloads

babel-plugin-angular2-annotations

A babel transformer plugin for Angular 2 annotations.

Use babel-plugin-transform-decorators-legacy to support Babel 5 decorators.

Make sure to load reflect-metadata for browser in order to polyfill Metadata Reflection API in your app.

Install

npm install --save-dev babel-plugin-angular2-annotations
npm install --save-dev babel-plugin-transform-decorators-legacy babel-plugin-transform-flow-strip-types

.babelrc

{
  "plugins": [
    "angular2-annotations",
    "transform-decorators-legacy",
    "transform-flow-strip-types"
  ]
}

npm 3

That's it.

npm 2

To monkey-patch babylon, the parser of babel, should be installed at the top level. This is an ugly hack but inevitable to support parameter decorators, which is not currently supported by babel, by monkey-patching.

npm install --save-dev babylon

Supported annotations

  • Class decorators (@Component()): works without this plugin
  • Type annotations for constructor parameters (constructor(foo: Foo, bar: Bar) {})
  • Decorators for constructor parameters (constructor(@Attriute('name') name, @Parent() parent) {})

Example

Before:

class HelloComponent {
  constructor(@Something({ hello: 'world' }) foo: Foo, bar: Bar) {
  }
}

After:

class HelloComponent {
}

Something({ hello: 'world' })(HelloComponent, null, 0);
Reflect.defineMetadata('design:paramtypes', [Foo, Bar]);

See babel-angular2-app for more complete example.

babel-plugin-angular2-annotations's People

Contributors

dgreif avatar jgodi avatar mgcrea avatar shuhei avatar

Watchers

 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.