dsherret / ts-type-info

TypeScript AST and code generator [Deprecated]
MIT License
94 stars 8 forks source link

Decorator Namespaces #220

Closed calebboyd closed 7 years ago

calebboyd commented 7 years ago

Great Project. It reminds me a little of Roslyn.

Found a possible issue if a decorator is accessed through a namespace. Reading and writing changes the declaration, eg.

import { DecoratorNamespace } from './my-decorators'

class Foo {
  @DecoratorNamespace.DecoratorFactory('argument')
  bar () { }
}

writes as

import { DecoratorNamespace } from './my-decorators'

class Foo {
  @DecoratorNamespace('argument')
  bar () {}
}

On an unrelated note. Is there a way to maintain the contents (code) of the file/classes methods when reading and writing? eg. Keeping the contents of bar through the read/write operation.

Cheers!

dsherret commented 7 years ago

Thanks Caleb! I'll try to think of a solution to this soon.

In response to your other question, it's not currently easy to do that... you have to do what's shown in this issue. Originally, this library was just created to get basic information about the code so it doesn't support a lot of scenarios; however, I'm thinking about moving writing to use the typescript emitter so that I don't have to maintain this stuff and it can be a lot more reliable.

calebboyd commented 7 years ago

That makes sense. (the project scope). I'd been tracking the compiler emit API as well before I found your project. Thanks for the help.

calebboyd commented 7 years ago

https://github.com/Microsoft/TypeScript/pull/13940

dsherret commented 7 years ago

@calebboyd thanks for letting me know about that. It opens the door to new possibilities.

I've been busy working on something else the past month, but I'm going to get back to this tomorrow.

dsherret commented 7 years ago

Sorry for the extremely long time fixing this. I've changed decorators to always use the fully qualified name.

calebboyd commented 7 years ago

No worries thanks!