microsoft / microsoft/TypeScript
Expose serializers from TypeScript transformer (ts.ts)
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.3k
- Ø Merge
- 2 T. 4 Std.
- Gemergte PRs (30 T.)
- 132
Beschreibung
With the introduction of the Transform API some of the logic in transformers/ts.ts needs to be exposed. (and maybe from other places...)
I'll explain by example:
@SomeDecorator()
export class MyClass {
constructor(public myInterface: MyInterface, public myClass: MyOtherClass) {}
}
If I want to transform the code so all parameter type metadata will be on a static property of the class. (this is angular DI)
@SomeDecorator()
export class MyClass {
constructor(public myInterface: MyInterface, public myClass: MyOtherClass) { }
static ctorParams: [Object, MyOtherClass];
}
This operation is currently impossible.
To get the right identifier for each type I need to serialize the type with some logic so MyInterface will become Object since it's not really a value.
The native TypeScript transformer has a lot of code for handling the logic of type serialization and it's not something one will want to copy, its huge.
Even if someone decided to replicate the logic, there's not access to the EmitResolver which is the "type checker" used by the native transformer to serialize the types.
TransformationContext.getEmitResolver() is @internal
The workaround is to actually run another Program process to get access to a TypeChecker.
It's not even possible to get a hold of the current running Program instance since TransformerFactory does not get access to it.
Is it possible to expose the serializatoin logic in the TypeScript transformer? I know it's complex, recursing and state dependant (scope) but it seems like not being able to serialize a type to create a literal is something basic
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit src/compiler/transformers/ts.ts und der Transform API und untersuche anschließend TransformationContext.getEmitResolver() sowie die im Issue beschriebene Verwendung von EmitResolver. Bestimme die erforderliche Grenze der öffentlichen API, um die Typserialisierung für benutzerdefinierte Transformer wiederzuverwenden, und verifiziere, dass Parametertypen wie MyInterface zu Object serialisiert werden, ohne ein zweites Program zu benötigen.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- typescript
- Bereich
- compilers
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 30/100