public override bool EmitTypeDeclarationHeader(DecompilerContext context, IAstEmitter astEmitter, TypeDefinition typedef, TypeInfo typeInfo) { if (!DefinitelyTypedUtilities.IsTypePublic(typedef)) { return(true); } Formatter.EmitInsideNamespace(typedef, true, isTopLevel => { if (isTopLevel) { Formatter.WriteRaw("export"); Formatter.Space(); Formatter.WriteRaw("declare"); Formatter.Space(); } Formatter.WriteRaw("let"); Formatter.Space(); Formatter.Identifier(DefinitelyTypedUtilities.GetClassName(typedef)); Formatter.Space(); Formatter.WriteRaw(":"); Formatter.Space(); Formatter.Identifier("$this"); Formatter.Dot(); foreach (var part in DefinitelyTypedUtilities.GetFullNamespace(typedef)) { Formatter.Identifier(part); Formatter.Dot(); } Formatter.Identifier(DefinitelyTypedUtilities.GetClassName(typedef)); Formatter.Dot(); Formatter.Identifier("Factory"); Formatter.Semicolon(); }); return(true); }
public override bool EmitTypeDeclarationHeader(DecompilerContext context, IAstEmitter astEmitter, TypeDefinition typedef, TypeInfo typeInfo) { if (!DefinitelyTypedUtilities.IsTypePublic(typedef)) { return(true); } Formatter.EmitInsideNamespace(typedef, false, isTopLevel => { Formatter.WriteRaw("namespace"); Formatter.Space(); Formatter.Identifier(DefinitelyTypedUtilities.GetClassName(typedef)); Formatter.OpenBrace(); EmitClassInstance(typedef); EmitClassInOutType(typedef); EmitClassStatic(typedef); EmitClassFactory(typedef); Formatter.CloseBrace(); }); Formatter.NewLine(); return(true); }
private void EmitClassInOutType(TypeDefinition typedef) { /*In*/ Formatter.WriteRaw("type"); Formatter.Space(); Formatter.WriteSelfReference(typedef, Facade.TIn); Formatter.Space(); Formatter.WriteRaw("="); Formatter.Space(); Formatter.WriteSelfReference(typedef, Facade.Instance); if (typedef.IsClass && typedef.BaseType != null) { Formatter.Space(); Formatter.WriteRaw("|"); Formatter.Space(); Formatter.WriteTypeReference(typedef.BaseType, typedef, JavascriptFormatterHelper.ReplaceMode.In, false); } var interfaces = typedef.Interfaces.Where(it => DefinitelyTypedUtilities.IsTypePublic(it) && !Translator.ShouldSkipMember(it)); foreach (var iface in interfaces) { Formatter.Space(); Formatter.WriteRaw("|"); Formatter.Space(); Formatter.WriteTypeReference(iface, typedef, JavascriptFormatterHelper.ReplaceMode.In, false); } Formatter.Semicolon(); /*Out*/ Formatter.WriteRaw("type"); Formatter.Space(); Formatter.WriteSelfReference(typedef, Facade.TOut); Formatter.Space(); Formatter.WriteRaw("="); Formatter.Space(); Formatter.WriteSelfReference(typedef, Facade.Instance); if (typedef.IsClass && typedef.BaseType != null) { Formatter.Space(); Formatter.WriteRaw("&"); Formatter.Space(); Formatter.WriteTypeReference(typedef.BaseType, typedef, JavascriptFormatterHelper.ReplaceMode.Out, false); } foreach (var iface in interfaces) { Formatter.Space(); Formatter.WriteRaw("&"); Formatter.Space(); Formatter.WriteTypeReference(iface, typedef, JavascriptFormatterHelper.ReplaceMode.Out, false); } Formatter.Semicolon(); }