8000 Angular2 & TypeScript Tern Support · Issue #652 · ternjs/tern · GitHub 8000
[go: up one dir, main page]

Skip to content
Angular2 & TypeScript Tern Support #652
@angelozerr

Description

@angelozerr

@marijnh I create this issue just to share with you my study how to support Angular2 with tern. You can close it if you wish.

Angular2 uses TypeScript >= 1.5 if I have understood. Here a sample code:

/// <reference path="typings/angular2/angular2.d.ts" />

import {HTTP_BINDINGS} from 'angular2/http';
import {Component, View, bootstrap, bind} from 'angular2/angular2';
import {DemoPage} from './demo-page';
import {About} from './components/about/about';
import {ROUTER_BINDINGS, LocationStrategy, HashLocationStrategy} from 'angular2/router';
import {RouterLink, RouteConfig, Router, RouterOutlet, Location, RouteParams} from 'angular2/router';

@Component({
   selector: 'demo-app'
})

@View({
    templateUrl: './demo-app.html',
    directives:[DemoPage, RouterLink, RouterOutlet, About]
})

@RouteConfig([
    {path: '/', component: DemoPage, as: 'home'},
    {path: '/about/:id', component: About, as: 'about'}
])

class MyDemoApp {

    router: Router;
    location: Location;

    constructor(router: Router, location: Location) {
        this.router = router;
        this.location = location;
    }

    getLinkStyle(path) {
        return this.location.path() === path;
    }
}

bootstrap(MyDemoApp,[HTTP_BINDINGS,ROUTER_BINDINGS, bind(LocationStrategy).toClass(HashLocationStrategy)]);

This sample uses the type declaration (eg: router: Router) and the decorator (if I have understood, ES7 should provide that).

If tern wishes one day to support Angular2, it needs to support:

  • typescript syntax with acorn (by developping a plugin acorn-ts like acorn-jsx)
  • supports ES7 decorator

I think you will not have time to support those features that's why I'm studying TypeScript LanguageService. My idea is to study if we could have the same information than tern (for completion, definition, etc) and if it's possible my idea is to create a TernTypeScriptServer which will support the same query than tern server but the implementation will use typescript language service. In other words if I can create my idea, any tern client (Emcas, Vim, Sublime, etc) could use TernTypeScriptServer .

If someone are interested with this idea, I have created the project at https://github.com/angelozerr/tern-typescript

@marijnh is it ok that I call this project tern-script? It will not use tern but will provides the same tern server API.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0