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

docs: user guide #45

Open
craigryan opened this issue Nov 4, 2017 · 6 comments
Open

docs: user guide #45

craigryan opened this issue Nov 4, 2017 · 6 comments

Comments

@craigryan
Copy link

I'm using this parser within a yeoman generator to parse angular 4 services, components, along with their usual decorators, but I'm finding it time consuming learning how to best drive your parser interface relying solely on deep diving into your code base, unit tests and the various reference style html docs.

I'd much appreciate any links you might have to additional material, user guide style docs, tutorials, extensive code samples and anything else to help. Cheers guys, a nice project and very useful, thanks for your efforts.

@buehler
Copy link
Owner

buehler commented Nov 6, 2017

Hey @craigryan
Thanks for reaching out! By now, I don't have any more documentation, but I'd be happy to provide some! Could you describe - in a little more specific way - what resources would be helpful?

Then I can take the time and documentate the stuff you need.

Cheers

@fwouts
Copy link

fwouts commented Nov 8, 2017

Something I'd find useful is a quick FAQ, specifically to the question "Why would I use this and not the TypeScript Compiler API?" (see https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API)

@craigryan
Copy link
Author

Thanks for responding Christoph,

I specifically need a guide on how best to examine a typescript source file to determine what imports it contains, what (angular) decorators it has (@Injectable for services, @component for components, @input fields etc), what private constructor params are passed in, all public methods and their params, basic logic to scan blocks of code within a method to try locate some commonly used statements I'm looking for (eg calls made to this.http.get or maybe this.ngRedux.dispatch).

Example of what isn't clear to me, say when looking for @Injectable where to look in the parsed data ('usages' contains it, but along with a lot of other identifiers?), also code samples of how to iterate through parsed data for the various items of interest above. Hope that's clear, if not let me know.

What follows is some sample code of some methods I am implementing to examine the parsed source, consider it pseudo code.

const NamedImport = require('typescript-parser/imports/NamedImport');
... etc

class Example {

lookForServicesAndImports() {
  let parsed = tparser.parseFile(tsSourceFile, tsRoot).then((p) => {
    this.parsed = p;
    return this.parsed;
  });

  for (var u of parsed.usages) {
	if (u === 'Injectable') {
	  console.log('hey I have an Injectable ng service!!');
	}
  }

  for (let imp of parsed.imports) {
    if (imp instanceof NamedImport.NamedImport) {
      this.namedImport(imp, t, mods);
    } else if (imp instanceof StringImport.StringImport) {
      ... etc
    }
  }
}

namedImport(imp, t, mods) {
  const mod = imp.libraryName;
  const specs = this.specifiers(imp.specifiers);
 // do something with a named import
}
... etc

@craigryan
Copy link
Author

Have you had a chance to make any progress on guide material? I've managed to progress further by console dumps and have a better picture of navigating declarations but now need to parse block statements for specific calls like this.http.get within class methods and from what I can see the parser doesn't expose this information so hoping to get some guide on how I might be able to do this.

@enomado
Copy link

enomado commented Mar 22, 2018

HI. I have a question. I'm doing poor man swagger with code generator and noticed that there is properties on InterfaceDeclaration buy nothing in TypeAliasDeclaration except (start,end). How can i get type declaration on node itself ? Or i should use ts api for that purpose ?

@buehler
Copy link
Owner

buehler commented Mar 27, 2018

Hey @enomado
Actually the real type declaration (aka properties and derived types) are not part of this parser. For this information, you should use the typescript compiler and use it to get the actual types of your file.

I guess. The type alias declaration is only for recognizing types, not the types that they alias.

@buehler buehler changed the title User guide? docs: user guide Aug 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants