Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get parsed data ( key -> value) of Class Decorator #99

Open
knlodha opened this issue Sep 11, 2018 · 2 comments
Open

How to get parsed data ( key -> value) of Class Decorator #99

knlodha opened this issue Sep 11, 2018 · 2 comments

Comments

@knlodha
Copy link

knlodha commented Sep 11, 2018

Hi @buehler ,
I can see that, I am not getting parsed data for class decorator. How can I get this data provided in decorator. I am using it for angular files

e.g.
import { Component } from '@angular/core';

@component({
selector: 'app-root',
template: <h1>{{title}}</h1> <h2>My favorite hero is: {{myHero}}</h2>

})
export class AppComponent {
title = 'Tour of Heroes';
myHero = 'Windstorm';
}

Here , I need selector and template values from decorator. Is there any way / configuration to get this data using parseSource or parseFile ?

@buehler
Copy link
Owner

buehler commented Sep 18, 2018

Hey @knlodha
Right now, there is no possibility to get decorators (or preciser input values that are given into a decorator).

What you could do: search for the classes (and therefore the files) that have components in them and then use a string search to parse those elements.

@knlodha
Copy link
Author

knlodha commented Sep 19, 2018

Hi @buehler ,
Thanks a lot for the inputs. Currently, I am doing exactly what you suggested ( string parsing ).
However, in certain scenarios like below,

Angular Code:
const routes: Routes = [
{ path: '', redirectTo: '/dashboard', pathMatch: 'full' },
{ path: 'dashboard', component: DashboardComponent },
{ path: 'detail/:id', component: HeroDetailComponent },
{ path: 'heroes', component: HeroesComponent }
];

where I need individual objects like the one highlighted above, string parsing becomes more complex.
Also, I can not covert the parsed string into Javascript object using JSON.parse as it will not find the individual references like DashboardComponent in this case.

Why I can't get the values of variables like routes using typescript parser. I can see, I only get the datatype. Is there any other way to get such information.

Also, do we have something like esprima ( http://esprima.org/ )for typescript code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants