/// <summary>
        /// Translate the unit into TypeScript.
        /// </summary>
        /// <returns></returns>
        public virtual string Translate()
        {
            FormatWriter writer = new FormatWriter()
            {
                Formatter = this.Formatter
            };

            // Opening declaration
            if (this.type != null)
            {
                writer.Write("{0} {1} {2} {3}",
                text => ClassDeclarationCodePerfect.RefineDeclaration(text),
                Lexems.VariableDeclaratorKeyword,
                this.name.Translate(),
                Lexems.Colon,
                this.type.Translate());
            }
            else
            {
                writer.Write("{0} {1}",
                text => ClassDeclarationCodePerfect.RefineDeclaration(text),
                Lexems.VariableDeclaratorKeyword,
                this.name.Translate());
            }

            return writer.ToString();
        }
        /// <summary>
        /// Translate the unit into TypeScript.
        /// </summary>
        /// <returns></returns>
        public virtual string Translate()
        {
            FormatWriter writer = new FormatWriter()
            {
                Formatter = this.Formatter
            };

            // Opening declaration: [<visibility>] <method-name>(<params>) : <type>
            string classVisibility = this.RenderedVisibilityModifier;

            if (this.ShouldRenderReturnType)
            {
                writer.WriteLine("{0}{1}{2} {3} {4}",
                                 classVisibility,
                                 this.RenderedName,
                                 SyntaxUtility.ToBracketEnclosedList(this.arguments.Select(unit => unit.Translate())),
                                 Lexems.Colon,
                                 this.ReturnType.Translate());
            }
            else
            {
                writer.WriteLine("{0}{1}{2}",
                                 classVisibility,
                                 this.RenderedName,
                                 SyntaxUtility.ToBracketEnclosedList(this.arguments.Select(unit => unit.Translate())));
            }

            return(writer.ToString());
        }
Example #3
0
        /// <summary>
        /// Translate the unit into TypeScript.
        /// </summary>
        /// <returns></returns>
        public override string Translate()
        {
            FormatWriter writer = new FormatWriter()
            {
                Formatter = this.Formatter
            };

            // Opening declaration
            writer.WriteLine("{0} {1} {2}{3} {4}",
                             TokenUtility.ToString(this.Visibility),
                             this.ReturnType.Translate(),
                             this.Name.Translate(),
                             SyntaxUtility.ToBracketEnclosedList(this.Arguments.Select(unit => unit.Translate())),
                             Lexems.OpenCurlyBracket);

            // Statements
            // The body, we render them as a list of semicolon/newline separated elements
            writer.WriteLine("{0}", SyntaxUtility.ToNewlineSemicolonSeparatedList(
                                 this.statements.Select(unit => unit.Translate()), true));

            // Closing declaration
            writer.WriteLine("{0}", Lexems.CloseCurlyBracket);

            return(writer.ToString());
        }
Example #4
0
        /// <summary>
        /// Translate the unit into TypeScript.
        /// </summary>
        /// <returns></returns>
        public override string Translate()
        {
            FormatWriter writer = new FormatWriter()
            {
                Formatter = this.Formatter
            };

            // Opening declaration: <visibility> constructor(<params>) {
            writer.WriteLine("{0}{1} {2}",
                             Lexems.ConstructorKeyword,
                             SyntaxUtility.ToBracketEnclosedList(this.Arguments.Select(unit => unit.Translate())),
                             Lexems.OpenCurlyBracket);

            // Statements
            // The body, we render them as a list of semicolon/newline separated elements
            foreach (ITranslationUnit statement in this.statements)
            {
                writer.WriteLine("{0}{1}",
                                 statement.Translate(),
                                 ShouldRenderSemicolon(statement) ? Lexems.Semicolon : string.Empty);
            }

            // Closing declaration
            writer.WriteLine("{0}", Lexems.CloseCurlyBracket);

            return(writer.ToString());
        }
        /// <summary>
        /// Translate the unit into TypeScript.
        /// </summary>
        /// <returns></returns>
        public virtual string Translate()
        {
            FormatWriter writer = new FormatWriter()
            {
                Formatter = this.Formatter
            };

            // Opening declaration
            if (this.type != null)
            {
                writer.Write("{0} {1} {2} {3}",
                             text => ClassDeclarationCodePerfect.RefineDeclaration(text),
                             Lexems.VariableDeclaratorKeyword,
                             this.name.Translate(),
                             Lexems.Colon,
                             this.type.Translate());
            }
            else
            {
                writer.Write("{0} {1}",
                             text => ClassDeclarationCodePerfect.RefineDeclaration(text),
                             Lexems.VariableDeclaratorKeyword,
                             this.name.Translate());
            }

            return(writer.ToString());
        }
        /// <summary>
        /// Translate the unit into TypeScript.
        /// </summary>
        /// <returns></returns>
        public virtual string Translate()
        {
            FormatWriter writer = new FormatWriter()
            {
                Formatter = this.Formatter
            };

            // Opening declaration
            string fieldVisibility = this.RenderedVisibilityModifier;

            if (this.Expression == null)
            {
                writer.Write("{0}{1} {2} {3}{4}",
                             text => ClassDeclarationCodePerfect.RefineDeclaration(text),
                             this.Visibility.ConvertToTypeScriptEquivalent().EmitOptionalVisibility(),
                             this.RenderedName,
                             Lexems.Colon,
                             this.type.Translate(), Lexems.Newline);
            }
            else
            {
                writer.Write("{0}{1} {2} {3} {4} {5}{6}",
                             text => ClassDeclarationCodePerfect.RefineDeclaration(text),
                             this.Visibility.ConvertToTypeScriptEquivalent().EmitOptionalVisibility(),
                             this.RenderedName,
                             Lexems.Colon,
                             this.type.Translate(),
                             Lexems.EqualsSign,
                             this.Expression.Translate(), Lexems.Newline);
            }

            return(writer.ToString());
        }
Example #7
0
        /// <summary>
        /// Translate the unit into TypeScript.
        /// </summary>
        /// <returns></returns>
        public override string Translate()
        {
            FormatWriter writer = new FormatWriter()
            {
                Formatter = this.Formatter
            };

            // Opening
            writer.WriteLine("switch {0}{1}{2}",
                             Lexems.OpenRoundBracket, this.switchExpression.Translate(), Lexems.CloseRoundBracket);

            writer.WriteLine("{0}",
                             Lexems.OpenCurlyBracket);

            // Body
            if (this.body != null)
            {
                writer.WriteLine("{0}",
                                 this.body.Translate());
            }

            // Closing
            writer.WriteLine("{0}",
                             Lexems.CloseCurlyBracket);

            return(writer.ToString());
        }
Example #8
0
        /// <summary>
        /// Translate the unit into TypeScript.
        /// </summary>
        /// <returns></returns>
        public override string Translate()
        {
            FormatWriter writer = new FormatWriter()
            {
                Formatter = this.Formatter
            };

            // Opening
            writer.WriteLine("try");

            writer.WriteLine("{0}",
                             Lexems.OpenCurlyBracket);

            // Block
            if (this.block != null)
            {
                writer.WriteLine("{0}",
                                 this.block.Translate());
            }

            // Closing
            writer.WriteLine("{0}",
                             Lexems.CloseCurlyBracket);

            //TODO: handle catches

            //TODO: handle finally

            return(writer.ToString());
        }
        /// <summary>
        /// Translate the unit into TypeScript.
        /// </summary>
        /// <returns></returns>
        public string Translate()
        {
            FormatWriter writer = new FormatWriter()
            {
                Formatter = this.Formatter
            };

            // Opening declaration
            writer.WriteLine("{0} {1} {2} {3}",
                             text => ClassDeclarationCodePerfect.RefineDeclaration(text),
                             this.RenderedModuleAccessorKeyword,
                             Lexems.ModuleKeyword,
                             this.name.Translate(),
                             Lexems.OpenCurlyBracket);

            // We render classes first
            var lastClass = this.classes.Count() > 0 ? this.classes.Last() : null;

            foreach (ITranslationUnit translationUnit in this.classes)
            {
                writer.WriteLine(translationUnit.Translate());

                if ((object)translationUnit != (object)lastClass)
                {
                    writer.WriteLine(string.Empty);
                }
            }

            // We render enums next
            var lastEnum = this.enums.Count() > 0 ? this.enums.Last() : null;

            foreach (ITranslationUnit translationUnit in this.enums)
            {
                writer.WriteLine(translationUnit.Translate());

                if ((object)translationUnit != (object)lastEnum)
                {
                    writer.WriteLine(string.Empty);
                }
            }

            // Then, interfaces
            var lastInterface = this.interfaces.Count() > 0 ? this.interfaces.Last() : null;

            foreach (ITranslationUnit translationUnit in this.interfaces)
            {
                writer.WriteLine(translationUnit.Translate());

                if ((object)translationUnit != (object)lastInterface)
                {
                    writer.WriteLine(string.Empty);
                }
            }

            // Closing declaration
            writer.WriteLine("{0}", Lexems.CloseCurlyBracket);

            return(writer.ToString());
        }
        /// <summary>
        /// Translate the unit into TypeScript.
        /// </summary>
        /// <returns></returns>
        public virtual string Translate()
        {
            FormatWriter writer = new FormatWriter()
            {
                Formatter = this.Formatter
            };

            // TODO: Improve this logic to make it more readable and efficient
            if (this.type != null)
            {
                if (this.Expression == null)
                {
                    // [var ]<name> : <type>
                    writer.Write("{0}{1} {2} {3}",
                                 text => ClassDeclarationCodePerfect.RefineDeclaration(text),
                                 this.shouldRenderDeclarationKeyword ? "let " : string.Empty,
                                 this.names[0].Translate(),
                                 Lexems.Colon,
                                 this.type.Translate());
                }
                else
                {
                    // [var ]<name> : <type> = <expression>
                    writer.Write("{0}{1} {2} {3} {4} {5}",
                                 text => ClassDeclarationCodePerfect.RefineDeclaration(text),
                                 this.shouldRenderDeclarationKeyword ? "let " : string.Empty,
                                 this.names[0].Translate(),
                                 Lexems.Colon,
                                 this.type.Translate(),
                                 Lexems.EqualsSign,
                                 this.Expression.Translate());
                }
            }
            else
            {
                if (this.Expression == null)
                {
                    // var <name>
                    writer.Write("{0} {1}",
                                 text => ClassDeclarationCodePerfect.RefineDeclaration(text),
                                 Lexems.VariableDeclaratorKeyword,
                                 this.names[0].Translate());
                }
                else
                {
                    // var <name> = <expression>
                    writer.Write("{0} {1} {2} {3}",
                                 text => ClassDeclarationCodePerfect.RefineDeclaration(text),
                                 Lexems.VariableDeclaratorKeyword,
                                 this.names[0].Translate(),
                                 Lexems.EqualsSign,
                                 this.Expression.Translate());
                }
            }

            return(writer.ToString());
        }
Example #11
0
        /// <summary>
        /// Translate the unit into TypeScript.
        /// </summary>
        /// <returns></returns>
        public override string Translate()
        {
            FormatWriter writer = new FormatWriter()
            {
                Formatter = this.Formatter
            };

            writer.Write("{0}",
                         this.variableDeclaration.Translate());

            return(writer.ToString());
        }
Example #12
0
        /// <summary>
        /// Translate the unit into TypeScript.
        /// </summary>
        /// <returns></returns>
        public string Translate()
        {
            FormatWriter writer = new FormatWriter()
            {
                Formatter = this.Formatter
            };

            // Opening declaration
            string enumVisibility = this.RenderedVisibilityModifier;

            if (this.injectedBefore == null)
            {
                writer.WriteLine("{0}{1} {2} {3}",
                                 text => ClassDeclarationCodePerfect.RefineDeclaration(text),
                                 enumVisibility,
                                 Lexems.EnumKeyword,
                                 this.Name.Translate(),
                                 Lexems.OpenCurlyBracket);
            }
            else
            {
                writer.WriteLine("{0} {1}{2} {3} {4}",
                                 text => ClassDeclarationCodePerfect.RefineDeclaration(text),
                                 this.injectedBefore.Translate(),
                                 enumVisibility,
                                 Lexems.EnumKeyword,
                                 this.Name.Translate(),
                                 Lexems.OpenCurlyBracket);
            }

            if (this.ShouldRenderMembers)
            {
                var lastMember = this.members.Count() > 0 ? this.members.Last() : null;
                foreach (ITranslationUnit translationUnit in this.members)
                {
                    if ((object)translationUnit == (object)lastMember)
                    {
                        writer.WriteLine("{0}", translationUnit.Translate());
                    }
                    else
                    {
                        writer.WriteLine("{0}{1}", translationUnit.Translate(), Lexems.Comma);
                    }
                }
            }

            // Closing
            writer.WriteLine("{0}",
                             text => ClassDeclarationCodePerfect.RefineDeclaration(text),
                             Lexems.CloseCurlyBracket);

            return(writer.ToString());
        }
        /// <summary>
        /// Translate the unit into TypeScript.
        /// </summary>
        /// <returns></returns>
        public override string Translate()
        {
            FormatWriter writer = new FormatWriter()
            {
                Formatter = this.Formatter
            };

            writer.Write("{0}",
                         keyword);

            return(writer.ToString());
        }
        /// <summary>
        /// Translate the unit into TypeScript.
        /// </summary>
        /// <returns></returns>
        public override string Translate()
        {
            FormatWriter writer = new FormatWriter()
            {
                Formatter = this.Formatter
            };

            writer.Write(this.unaryPosition == UnaryPosition.Postfix ? "{0}{1}" : "{1}{0}",
                         this.Operand.Translate(),
                         TokenUtility.ToString(this.operatorToken));

            return(writer.ToString());
        }
        /// <summary>
        /// Translate the unit into TypeScript.
        /// </summary>
        /// <returns></returns>
        public string Translate()
        {
            FormatWriter writer = new FormatWriter()
            {
                Formatter = this.Formatter
            };

            writer.Write("{0} {1}",
                         this.commentToken,
                         this.comment);

            return(writer.ToString());
        }
        /// <summary>
        /// Translate the unit into TypeScript.
        /// </summary>
        /// <returns></returns>
        public override string Translate()
        {
            FormatWriter writer = new FormatWriter()
            {
                Formatter = this.Formatter
            };

            writer.Write("{0}{1}",
                         this.keyword != null ? keyword + " " : string.Empty,
                         this.expression.Translate());

            return(writer.ToString());
        }
        /// <summary>
        /// Translate the unit into TypeScript.
        /// </summary>
        /// <returns></returns>
        public string Translate()
        {
            FormatWriter writer = new FormatWriter()
            {
                Formatter = this.Formatter
            };

            if (this.hasGet)
            {
                // Opening declaration: [<visibility>] get <name>() : <type> {
                // TODO: Handle case of no visibility specified
                writer.WriteLine("{0}{1} {2}{3} {4} {5} {6}",
                                 this.Visibility.ConvertToTypeScriptEquivalent().EmitOptionalVisibility(),
                                 Lexems.GetKeyword,
                                 this.Name.Translate(),
                                 Lexems.OpenRoundBracket + Lexems.CloseRoundBracket,
                                 Lexems.Colon,
                                 this.type.Translate(),
                                 Lexems.OpenCurlyBracket);

                writer.WriteLine("{0}",
                                 this.getStatements.Translate());

                // Closing declaration
                writer.WriteLine("{0}", Lexems.CloseCurlyBracket);
            }

            if (this.hasSet)
            {
                var valueParameter = ArgumentDefinitionTranslationUnit.Create(
                    this.type, IdentifierTranslationUnit.Create("value"));

                // Opening declaration: [<visibility>] set <name>(value : <type>) {
                writer.WriteLine("{0}{1} {2}{3}{4}{5} {6}",
                                 this.Visibility.ConvertToTypeScriptEquivalent().EmitOptionalVisibility(),
                                 Lexems.SetKeyword,
                                 this.Name.Translate(),
                                 Lexems.OpenRoundBracket,
                                 valueParameter.Translate(),
                                 Lexems.CloseRoundBracket,
                                 Lexems.OpenCurlyBracket);

                writer.WriteLine("{0}",
                                 this.setStatements.Translate());

                // Closing declaration
                writer.WriteLine("{0}", Lexems.CloseCurlyBracket);
            }

            return(writer.ToString());
        }
Example #18
0
        /// <summary>
        /// Translate the unit into TypeScript.
        /// </summary>
        /// <returns></returns>
        public override string Translate()
        {
            FormatWriter writer = new FormatWriter()
            {
                Formatter = this.Formatter
            };

            // Invokation: ([<initializers>])
            writer.WriteLine("{0}",
                             SyntaxUtility.ToSquareBracketEnclosedList(this.arguments.Select(unit => unit.Translate()))
                             );

            return(writer.ToString());
        }
        /// <summary>
        /// Translate the unit into TypeScript.
        /// </summary>
        /// <returns></returns>
        public override string Translate()
        {
            FormatWriter writer = new FormatWriter()
            {
                Formatter = this.Formatter
            };

            writer.Write("{0}{1}{2}",
                         Lexems.OpenRoundBracket,
                         this.WrappedExpression.Translate(),
                         Lexems.CloseRoundBracket);

            return(writer.ToString());
        }
        /// <summary>
        /// Translate the unit into TypeScript.
        /// </summary>
        /// <returns></returns>
        public string Translate()
        {
            FormatWriter writer = new FormatWriter()
            {
                Formatter = this.Formatter
            };

            // Opening declaration
            string interfaceVisibility = this.RenderedVisibilityModifier;
            string extensionList       = this.BuildInterfaceExtensionList();

            if (this.injectedBefore == null)
            {
                writer.WriteLine("{0}{1} {2} {3} {4}",
                                 text => ClassDeclarationCodePerfect.RefineDeclaration(text),
                                 interfaceVisibility,
                                 Lexems.InterfaceKeyword,
                                 this.Name.Translate(),
                                 extensionList,
                                 Lexems.OpenCurlyBracket);
            }
            else
            {
                writer.WriteLine("{0} {1}{2} {3} {4} {5}",
                                 text => ClassDeclarationCodePerfect.RefineDeclaration(text),
                                 this.injectedBefore.Translate(),
                                 interfaceVisibility,
                                 Lexems.InterfaceKeyword,
                                 this.Name.Translate(),
                                 extensionList,
                                 Lexems.OpenCurlyBracket);
            }

            // Signatures
            if (this.ShouldRenderSignatures)
            {
                foreach (ITranslationUnit translationUnit in this.signatures)
                {
                    writer.WriteLine("{0}{1}", translationUnit.Translate(), Lexems.Semicolon);
                }
            }

            // Closing
            writer.WriteLine("{0}",
                             text => ClassDeclarationCodePerfect.RefineDeclaration(text),
                             Lexems.CloseCurlyBracket);

            return(writer.ToString());
        }
Example #21
0
        /// <summary>
        /// Translate the unit into TypeScript.
        /// </summary>
        /// <returns></returns>
        public string Translate()
        {
            FormatWriter writer = new FormatWriter()
            {
                Formatter = this.Formatter
            };

            // Opening declaration
            writer.WriteLine("{0} {1} {2} {3}",
                             text => ClassDeclarationCodePerfect.RefineDeclaration(text),
                             Lexems.ExportKeyword,
                             Lexems.ModuleKeyword,
                             this.name.Translate(),
                             Lexems.OpenCurlyBracket);

            // We render classes first
            foreach (ITranslationUnit translationUnit in this.classes)
            {
                if (translationUnit as NestedElementTranslationUnit != null)
                {
                    ((NestedElementTranslationUnit)translationUnit).NestingLevel = this.NestingLevel + 1;
                }

                // Classes need injection for observing indentation
                if (translationUnit as ITranslationInjector != null)
                {
                    ((ITranslationInjector)translationUnit).InjectedTranslationUnitBefore = IdentifierTranslationUnit.Create(Lexems.ExportKeyword);
                }

                writer.WriteLine(translationUnit.Translate());
            }

            // Then, interfaces
            foreach (ITranslationUnit translationUnit in this.interfaces)
            {
                if (translationUnit as NestedElementTranslationUnit != null)
                {
                    ((NestedElementTranslationUnit)translationUnit).NestingLevel = this.NestingLevel + 1;
                }
                writer.WriteLine("{0} {1}",
                                 Lexems.ExportKeyword,
                                 translationUnit.Translate());
            }

            // Closing declaration
            writer.WriteLine("{0}", Lexems.CloseCurlyBracket);

            return(writer.ToString());
        }
        /// <summary>
        /// Translate the unit into TypeScript.
        /// </summary>
        /// <returns></returns>
        public string Translate()
        {
            FormatWriter writer = new FormatWriter()
            {
                Formatter = this.Formatter
            };

            string commentBody = $"<reference path=\"{this.path}\" />";
            ITranslationUnit commentTranslationUnit = SingleLineCommentTranslationUnit.Create(commentBody,
                SingleLineCommentTranslationUnit.CommentStyle.XmlStyle);

            writer.Write("{0}", commentTranslationUnit.Translate());

            return writer.ToString();
        }
Example #23
0
        /// <summary>
        /// Translate the unit into TypeScript.
        /// </summary>
        /// <returns></returns>
        public override string Translate()
        {
            FormatWriter writer = new FormatWriter()
            {
                Formatter = this.Formatter
            };

            // Invokation: <expression>([<params>])
            writer.WriteLine("{0}{1}",
                             this.expression.Translate(),
                             SyntaxUtility.ToSquareBracketEnclosedList(this.arguments.Select(unit => unit.Translate()))
                             );

            return(writer.ToString());
        }
        /// <summary>
        /// Translate the unit into TypeScript.
        /// </summary>
        /// <returns></returns>
        public string Translate()
        {
            FormatWriter writer = new FormatWriter()
            {
                Formatter = new WhiteSpaceInvariantFormatter()
            };

            foreach (var translationUnit in this.content)
            {
                writer.WriteLine("{0}",
                                 translationUnit.Translate());
            }

            return(writer.ToString());
        }
        /// <summary>
        /// Translate the unit into TypeScript.
        /// </summary>
        /// <returns></returns>
        public string Translate()
        {
            FormatWriter writer = new FormatWriter()
            {
                Formatter = this.Formatter
            };

            string           commentBody            = $"<reference path=\"{this.path}\" />";
            ITranslationUnit commentTranslationUnit = SingleLineCommentTranslationUnit.Create(commentBody,
                                                                                              SingleLineCommentTranslationUnit.CommentStyle.XmlStyle);

            writer.Write("{0}", commentTranslationUnit.Translate());

            return(writer.ToString());
        }
        /// <summary>
        /// Translate the unit into TypeScript.
        /// </summary>
        /// <returns></returns>
        public override string Translate()
        {
            FormatWriter writer = new FormatWriter()
            {
                Formatter = this.Formatter
            };

            writer.Write("{0}{1}{2}{3}",
                         Lexems.OpenAngularBracket,
                         this.Type.Translate(),
                         Lexems.CloseAngularBracket,
                         this.Castee.Translate());

            return(writer.ToString());
        }
        /// <summary>
        /// Translate the unit into TypeScript.
        /// </summary>
        /// <returns></returns>
        public string Translate()
        {
            FormatWriter writer = new FormatWriter()
            {
                Formatter = this.Formatter
            };

            foreach (var statement in this.statements)
            {
                writer.WriteLine("{0}{1}",
                                 statement.Translate(),
                                 this.ShouldRenderSemicolon(statement) ? Lexems.Semicolon : string.Empty);
            }

            return(writer.ToString());
        }
Example #28
0
        /// <summary>
        /// Translate the unit into TypeScript.
        /// </summary>
        /// <returns></returns>
        public virtual string Translate()
        {
            FormatWriter writer = new FormatWriter()
            {
                Formatter = this.Formatter
            };

            // Opening declaration
            writer.WriteLine("{0} {1} {2}{3}",
                             TokenUtility.ToString(this.Visibility),
                             this.ReturnType.Translate(),
                             this.Name.Translate(),
                             SyntaxUtility.ToBracketEnclosedList(this.arguments.Select(unit => unit.Translate())));

            return(writer.ToString());
        }
Example #29
0
        /// <summary>
        /// Translate the unit into TypeScript.
        /// </summary>
        /// <returns></returns>
        public virtual string Translate()
        {
            FormatWriter writer = new FormatWriter()
            {
                Formatter = this.Formatter
            };

            // Opening declaration
            writer.Write("{0} {1} {2} {3}",
                         text => ClassDeclarationCodePerfect.RefineDeclaration(text),
                         TokenUtility.ToString(this.Visibility),
                         this.Name.Translate(),
                         Lexems.Colon,
                         this.type.Translate());

            return(writer.ToString());
        }
Example #30
0
        /// <summary>
        /// Translate the unit into TypeScript.
        /// </summary>
        /// <returns></returns>
        public override string Translate()
        {
            FormatWriter writer = new FormatWriter()
            {
                Formatter = this.Formatter
            };

            // TODO: Use `{0}{1}{2}{1}{3}` when FormatWriter gets fixed to support repetitive placeholders
            writer.Write("{0}{1}{2}{3}{4}",
                         this.LeftOperand.Translate(),
                         Lexems.Whitespace,
                         TokenUtility.ToString(this.operatorToken),
                         Lexems.Whitespace,
                         this.RightOperand.Translate());

            return(writer.ToString());
        }
        /// <summary>
        /// Translate the unit into TypeScript.
        /// </summary>
        /// <returns></returns>
        public virtual string Translate()
        {
            FormatWriter writer = new FormatWriter()
            {
                Formatter = this.Formatter
            };

            // Opening declaration
            writer.Write("{0} {1} {2} {3}",
                text => ClassDeclarationCodePerfect.RefineDeclaration(text),
                TokenUtility.ToString(this.Visibility),
                this.Name.Translate(),
                Lexems.Colon,
                this.type.Translate());

            return writer.ToString();
        }
        /// <summary>
        /// Translate the unit into TypeScript.
        /// </summary>
        /// <returns></returns>
        public override string Translate()
        {
            FormatWriter writer = new FormatWriter()
            {
                Formatter = this.Formatter
            };

            // Opening declaration: [<visibility>] <method-name>(<params>) : <type> {
            // TODO: Handle case of no visibility specified
            string methodVisibility = this.RenderedVisibilityModifier;

            if (this.ShouldRenderReturnType)
            {
                writer.WriteLine("{0}{1}{2} {3} {4} {5}",
                                 methodVisibility,
                                 this.RenderedName,
                                 SyntaxUtility.ToBracketEnclosedList(this.Arguments.Select(unit => unit.Translate())),
                                 Lexems.Colon,
                                 this.ReturnType.Translate(),
                                 Lexems.OpenCurlyBracket);
            }
            else
            {
                writer.WriteLine("{0}{1}{2} {3}",
                                 methodVisibility,
                                 this.RenderedName,
                                 SyntaxUtility.ToBracketEnclosedList(this.Arguments.Select(unit => unit.Translate())),
                                 Lexems.OpenCurlyBracket);
            }

            // Statements
            // The body, we render them as a list of semicolon/newline separated elements
            foreach (ITranslationUnit statement in this.statements)
            {
                writer.WriteLine("{0}{1}",
                                 statement.Translate(),
                                 ShouldRenderSemicolon(statement) ? Lexems.Semicolon : string.Empty);
            }

            // Closing declaration
            writer.WriteLine("{0}", Lexems.CloseCurlyBracket);

            return(writer.ToString());
        }
Example #33
0
        /// <summary>
        /// Translate the unit into TypeScript.
        /// </summary>
        /// <returns></returns>
        public override string Translate()
        {
            FormatWriter writer = new FormatWriter()
            {
                Formatter = this.Formatter
            };

            for (var i = 0; i < this.testExpressions.Length; i++)
            {
                // Opening
                writer.WriteLine("{0} {1}{2}{3}",
                                 i == 0 ? Lexems.IfKeyword : Lexems.ElseIfKeyword,
                                 Lexems.OpenRoundBracket,
                                 this.testExpressions[i].Translate(),
                                 Lexems.CloseRoundBracket);
                writer.WriteLine("{0}",
                                 Lexems.OpenCurlyBracket);

                writer.WriteLine("{0}",
                                 this.bodies[i].Translate());

                // Closing
                writer.WriteLine("{0}",
                                 Lexems.CloseCurlyBracket);
            }

            if (this.hasFinalElse)
            {
                // Opening
                writer.WriteLine("{0}",
                                 Lexems.ElseKeyword);
                writer.WriteLine("{0}",
                                 Lexems.OpenCurlyBracket);

                writer.WriteLine("{0}",
                                 this.lastBody.Translate());

                // Closing
                writer.WriteLine("{0}",
                                 Lexems.CloseCurlyBracket);
            }

            return(writer.ToString());
        }
        /// <summary>
        /// Translate the unit into TypeScript.
        /// </summary>
        /// <returns></returns>
        public override string Translate()
        {
            FormatWriter writer = new FormatWriter()
            {
                Formatter = this.Formatter
            };

            // Opening declaration: [<visibility>] <method-name>(<params>) : <type> {
            // TODO: Handle case of no visibility specified
            string methodVisibility = this.RenderedVisibilityModifier;

            if (this.ShouldRenderReturnType)
            {
                writer.WriteLine("{0}{1}{2} {3} {4} {5}",
                methodVisibility,
                this.RenderedName,
                SyntaxUtility.ToBracketEnclosedList(this.Arguments.Select(unit => unit.Translate())),
                Lexems.Colon,
                this.ReturnType.Translate(),
                Lexems.OpenCurlyBracket);
            }
            else
            {
                writer.WriteLine("{0}{1}{2} {3}",
                methodVisibility,
                this.RenderedName,
                SyntaxUtility.ToBracketEnclosedList(this.Arguments.Select(unit => unit.Translate())),
                Lexems.OpenCurlyBracket);
            }

            // Statements
            // The body, we render them as a list of semicolon/newline separated elements
            foreach (ITranslationUnit statement in this.statements)
            {
                writer.WriteLine("{0}{1}",
                    statement.Translate(),
                    ShouldRenderSemicolon(statement) ? Lexems.Semicolon : string.Empty);
            }

            // Closing declaration
            writer.WriteLine("{0}", Lexems.CloseCurlyBracket);

            return writer.ToString();
        }
        /// <summary>
        /// Translate the unit into TypeScript.
        /// </summary>
        /// <returns></returns>
        public virtual string Translate()
        {
            FormatWriter writer = new FormatWriter()
            {
                Formatter = this.Formatter
            };

            // Opening declaration
            string fieldVisibility = this.RenderedVisibilityModifier;

            writer.Write("{0}{1} {2} {3}",
                text => ClassDeclarationCodePerfect.RefineDeclaration(text),
                this.Visibility.ConvertToTypeScriptEquivalent().EmitOptionalVisibility(),
                this.RenderedName,
                Lexems.Colon,
                this.type.Translate());

            return writer.ToString();
        }
        /// <summary>
        /// Translate the unit into TypeScript.
        /// </summary>
        /// <returns></returns>
        public override string Translate()
        {
            FormatWriter writer = new FormatWriter()
            {
                Formatter = this.Formatter
            };

            writer.Write("{0}{1}",
                this.keyword != null ? keyword + " " : string.Empty,
                this.expression.Translate());

            return writer.ToString();
        }
        /// <summary>
        /// Translate the unit into TypeScript.
        /// </summary>
        /// <returns></returns>
        public virtual string Translate()
        {
            FormatWriter writer = new FormatWriter()
            {
                Formatter = this.Formatter
            };

            // TODO: Improve this logic to make it more readable and efficient
            if (this.type != null)
            {
                if (this.Expression == null)
                {
                    // [var ]<name> : <type>
                    writer.Write("{0}{1} {2} {3}",
                        text => ClassDeclarationCodePerfect.RefineDeclaration(text),
                        this.shouldRenderDeclarationKeyword ? Lexems.VariableDeclaratorKeyword + " " : string.Empty,
                        this.names[0].Translate(),
                        Lexems.Colon,
                        this.type.Translate());
                }
                else
                {
                    // [var ]<name> : <type> = <expression>
                    writer.Write("{0}{1} {2} {3} {4} {5}",
                        text => ClassDeclarationCodePerfect.RefineDeclaration(text),
                        this.shouldRenderDeclarationKeyword ? Lexems.VariableDeclaratorKeyword + " " : string.Empty,
                        this.names[0].Translate(),
                        Lexems.Colon,
                        this.type.Translate(),
                        Lexems.EqualsSign,
                        this.Expression.Translate());
                }
            }
            else
            {
                if (this.Expression == null)
                {
                    // var <name>
                    writer.Write("{0} {1}",
                        text => ClassDeclarationCodePerfect.RefineDeclaration(text),
                        Lexems.VariableDeclaratorKeyword,
                        this.names[0].Translate());
                }
                else
                {
                    // var <name> = <expression>
                    writer.Write("{0} {1} {2} {3}",
                        text => ClassDeclarationCodePerfect.RefineDeclaration(text),
                        Lexems.VariableDeclaratorKeyword,
                        this.names[0].Translate(),
                        Lexems.EqualsSign,
                        this.Expression.Translate());
                }
            }

            return writer.ToString();
        }
        /// <summary>
        /// Translate the unit into TypeScript.
        /// </summary>
        /// <returns></returns>
        public override string Translate()
        {
            FormatWriter writer = new FormatWriter()
            {
                Formatter = this.Formatter
            };

            writer.Write("{0}",
                this.variableDeclaration.Translate());

            return writer.ToString();
        }
        /// <summary>
        /// Translate the unit into TypeScript.
        /// </summary>
        /// <returns></returns>
        public string Translate()
        {
            FormatWriter writer = new FormatWriter()
            {
                Formatter = this.Formatter
            };

            // Opening declaration
            string interfaceVisibility = this.RenderedVisibilityModifier;
            string extensionList = this.BuildInterfaceExtensionList();

            if (this.injectedBefore == null)
            {
                writer.WriteLine("{0}{1} {2} {3} {4}",
                text => ClassDeclarationCodePerfect.RefineDeclaration(text),
                interfaceVisibility,
                Lexems.InterfaceKeyword,
                this.Name.Translate(),
                extensionList,
                Lexems.OpenCurlyBracket);
            }
            else
            {
                writer.WriteLine("{0} {1}{2} {3} {4} {5}",
                text => ClassDeclarationCodePerfect.RefineDeclaration(text),
                this.injectedBefore.Translate(),
                interfaceVisibility,
                Lexems.InterfaceKeyword,
                this.Name.Translate(),
                extensionList,
                Lexems.OpenCurlyBracket);
            }

            // Signatures
            if (this.ShouldRenderSignatures)
            {
                foreach (ITranslationUnit translationUnit in this.signatures)
                {
                    writer.WriteLine("{0}{1}", translationUnit.Translate(), Lexems.Semicolon);
                }
            }

            // Closing
            writer.WriteLine("{0}",
                text => ClassDeclarationCodePerfect.RefineDeclaration(text),
                Lexems.CloseCurlyBracket);

            return writer.ToString();
        }
        /// <summary>
        /// Translate the unit into TypeScript.
        /// </summary>
        /// <returns></returns>
        public string Translate()
        {
            FormatWriter writer = new FormatWriter()
            {
                Formatter = new WhiteSpaceInvariantFormatter()
            };

            foreach (var translationUnit in this.content)
            {
                writer.WriteLine("{0}",
                    translationUnit.Translate());
            }

            return writer.ToString();
        }
        /// <summary>
        /// Translate the unit into TypeScript.
        /// </summary>
        /// <returns></returns>
        public override string Translate()
        {
            FormatWriter writer = new FormatWriter()
            {
                Formatter = this.Formatter
            };

            if (this.accessMethod == MemberAccessMethod.None)
            {
                writer.Write("{0}", this.Member.Translate());
            }
            else
            {
                writer.Write("{0}{1}{2}",
                MemberAccessMethod2String(this.accessMethod),
                Lexems.Dot,
                this.Member.Translate());
            }

            return writer.ToString();
        }
        /// <summary>
        /// Translate the unit into TypeScript.
        /// </summary>
        /// <returns></returns>
        public override string Translate()
        {
            FormatWriter writer = new FormatWriter()
            {
                Formatter = this.Formatter
            };

            writer.Write(this.unaryPosition == UnaryPosition.Postfix ? "{0}{1}" : "{1}{0}",
                this.Operand.Translate(),
                TokenUtility.ToString(this.operatorToken));

            return writer.ToString();
        }
        /// <summary>
        /// Translate the unit into TypeScript.
        /// </summary>
        /// <returns></returns>
        public string Translate()
        {
            FormatWriter writer = new FormatWriter()
            {
                Formatter = this.Formatter
            };

            // Opening declaration
            string classVisibility = TokenUtility.ToString(this.Visibility);
            string baseList = this.BuildClassInheritanceAndInterfaceImplementationList();

            if (this.injectedBefore == null)
            {
                writer.WriteLine("{0} class {1} {2} {3}",
                text => ClassDeclarationCodePerfect.RefineDeclaration(text),
                classVisibility,
                this.Name.Translate(),
                baseList,
                Lexems.OpenCurlyBracket);
            }
            else
            {
                writer.WriteLine("{0} {1} class {2} {3} {4}",
                text => ClassDeclarationCodePerfect.RefineDeclaration(text),
                this.injectedBefore.Translate(),
                classVisibility,
                this.Name.Translate(),
                baseList,
                Lexems.OpenCurlyBracket);
            }

            // Translating members first
            foreach (ITranslationUnit translationUnit in this.memberDeclarations)
            {
                if (translationUnit as NestedElementTranslationUnit != null)
                {
                    ((NestedElementTranslationUnit)translationUnit).NestingLevel = this.NestingLevel + 1;
                }
                writer.WriteLine("{0}{1}", translationUnit.Translate(), Lexems.Semicolon);
            }

            // Then constructors
            foreach (ITranslationUnit translationUnit in this.constructorDeclarations)
            {
                if (translationUnit as NestedElementTranslationUnit != null)
                {
                    ((NestedElementTranslationUnit)translationUnit).NestingLevel = this.NestingLevel + 1;
                }
                writer.WriteLine(translationUnit.Translate());
            }

            // Then properties
            foreach (ITranslationUnit translationUnit in this.propertyDeclarations)
            {
                if (translationUnit as NestedElementTranslationUnit != null)
                {
                    ((NestedElementTranslationUnit)translationUnit).NestingLevel = this.NestingLevel + 1;
                }
                writer.WriteLine(translationUnit.Translate());
            }

            // Finally methods
            foreach (ITranslationUnit translationUnit in this.methodDeclarations)
            {
                if (translationUnit as NestedElementTranslationUnit != null)
                {
                    ((NestedElementTranslationUnit)translationUnit).NestingLevel = this.NestingLevel + 1;
                }
                writer.WriteLine(translationUnit.Translate());
            }

            // Closing
            writer.WriteLine("{0}",
                text => ClassDeclarationCodePerfect.RefineDeclaration(text),
                Lexems.CloseCurlyBracket);

            return writer.ToString();
        }
Example #44
0
        /// <summary>
        /// Translate the unit into TypeScript.
        /// </summary>
        /// <returns></returns>
        public string Translate()
        {
            FormatWriter writer = new FormatWriter()
            {
                Formatter = this.Formatter
            };

            // Opening declaration
            string enumVisibility = this.RenderedVisibilityModifier;

            if (this.injectedBefore == null)
            {
                writer.WriteLine("{0}{1} {2} {3}",
                text => ClassDeclarationCodePerfect.RefineDeclaration(text),
                enumVisibility,
                Lexems.EnumKeyword,
                this.Name.Translate(),
                Lexems.OpenCurlyBracket);
            }
            else
            {
                writer.WriteLine("{0} {1}{2} {3} {4}",
                text => ClassDeclarationCodePerfect.RefineDeclaration(text),
                this.injectedBefore.Translate(),
                enumVisibility,
                Lexems.EnumKeyword,
                this.Name.Translate(),
                Lexems.OpenCurlyBracket);
            }

            if (this.ShouldRenderMembers)
            {
                var lastMember = this.members.Count() > 0 ? this.members.Last() : null;
                foreach (ITranslationUnit translationUnit in this.members)
                {
                    if ((object)translationUnit == (object)lastMember)
                    {
                        writer.WriteLine("{0}", translationUnit.Translate());
                    }
                    else
                    {
                        writer.WriteLine("{0}{1}", translationUnit.Translate(), Lexems.Comma);
                    }
                }
            }

            // Closing
            writer.WriteLine("{0}",
                text => ClassDeclarationCodePerfect.RefineDeclaration(text),
                Lexems.CloseCurlyBracket);

            return writer.ToString();
        }
        /// <summary>
        /// Translate the unit into TypeScript.
        /// </summary>
        /// <returns></returns>
        public override string Translate()
        {
            FormatWriter writer = new FormatWriter()
            {
                Formatter = this.Formatter
            };

            // Invokation: <expression>([<params>])
            writer.WriteLine("{0}{1}",
                this.expression.Translate(),
                SyntaxUtility.ToBracketEnclosedList(this.arguments.Select(unit => unit.Translate()))
                );

            return writer.ToString();
        }
            /// <summary>
            /// Following typical scheme.
            /// </summary>
            /// <returns></returns>
            public string Translate()
            {
                FormatWriter writer = new FormatWriter()
                {
                    Formatter = this.Formatter
                };

                // Opening
                writer.WriteLine("{0} {1}",
                    HeaderLexem,
                    Lexems.OpenCurlyBracket);

                foreach (var translationUnit in this.innerUnits)
                {
                    writer.WriteLine("{0}",
                        translationUnit.Translate());
                }

                // Closing
                writer.WriteLine("{0}",
                    Lexems.CloseCurlyBracket);

                return writer.ToString();
            }
        /// <summary>
        /// Translate the unit into TypeScript.
        /// </summary>
        /// <returns></returns>
        public string Translate()
        {
            FormatWriter writer = new FormatWriter()
            {
                Formatter = this.Formatter
            };

            if (this.hasGet)
            {
                // Opening declaration: [<visibility>] get <name>() : <type> {
                // TODO: Handle case of no visibility specified
                writer.WriteLine("{0}{1} {2}{3} {4} {5} {6}",
                    this.Visibility.ConvertToTypeScriptEquivalent().EmitOptionalVisibility(),
                    Lexems.GetKeyword,
                    this.Name.Translate(),
                    Lexems.OpenRoundBracket + Lexems.CloseRoundBracket,
                    Lexems.Colon,
                    this.type.Translate(),
                    Lexems.OpenCurlyBracket);

                writer.WriteLine("{0}",
                    this.getStatements.Translate());

                // Closing declaration
                writer.WriteLine("{0}", Lexems.CloseCurlyBracket);
            }

            if (this.hasSet)
            {
                var valueParameter = ArgumentDefinitionTranslationUnit.Create(
                    this.type, IdentifierTranslationUnit.Create("value"));

                // Opening declaration: [<visibility>] set <name>(value : <type>) {
                writer.WriteLine("{0}{1} {2}{3}{4}{5} {6}",
                    this.Visibility.ConvertToTypeScriptEquivalent().EmitOptionalVisibility(),
                    Lexems.SetKeyword,
                    this.Name.Translate(),
                    Lexems.OpenRoundBracket,
                    valueParameter.Translate(),
                    Lexems.CloseRoundBracket,
                    Lexems.OpenCurlyBracket);

                writer.WriteLine("{0}",
                    this.setStatements.Translate());

                // Closing declaration
                writer.WriteLine("{0}", Lexems.CloseCurlyBracket);
            }

            return writer.ToString();
        }
        /// <summary>
        /// Translate the unit into TypeScript.
        /// </summary>
        /// <returns></returns>
        public override string Translate()
        {
            FormatWriter writer = new FormatWriter()
            {
                Formatter = this.Formatter
            };

            for (var i = 0; i < this.testExpressions.Length; i++)
            {
                // Opening
                writer.WriteLine("{0} {1}{2}{3}",
                    i == 0 ? Lexems.IfKeyword : Lexems.ElseIfKeyword,
                    Lexems.OpenRoundBracket,
                    this.testExpressions[i].Translate(),
                    Lexems.CloseRoundBracket);
                writer.WriteLine("{0}",
                    Lexems.OpenCurlyBracket);

                writer.WriteLine("{0}",
                    this.bodies[i].Translate());

                // Closing
                writer.WriteLine("{0}",
                    Lexems.CloseCurlyBracket);
            }

            if (this.hasFinalElse)
            {
                // Opening
                writer.WriteLine("{0}",
                    Lexems.ElseKeyword);
                writer.WriteLine("{0}",
                    Lexems.OpenCurlyBracket);

                writer.WriteLine("{0}",
                    this.lastBody.Translate());

                // Closing
                writer.WriteLine("{0}",
                    Lexems.CloseCurlyBracket);
            }

            return writer.ToString();
        }
        /// <summary>
        /// Translate the unit into TypeScript.
        /// </summary>
        /// <returns></returns>
        public string Translate()
        {
            FormatWriter writer = new FormatWriter()
            {
                Formatter = this.Formatter
            };

            // Opening declaration
            string classVisibility = this.RenderedVisibilityModifier;
            string baseList = this.BuildClassInheritanceAndInterfaceImplementationList();

            if (this.injectedBefore == null)
            {
                writer.WriteLine("{0}{1} {2} {3} {4}",
                text => ClassDeclarationCodePerfect.RefineDeclaration(text),
                classVisibility,
                Lexems.ClassKeyword,
                this.Name.Translate(),
                baseList,
                Lexems.OpenCurlyBracket);
            }
            else
            {
                writer.WriteLine("{0} {1}{2} {3} {4} {5}",
                text => ClassDeclarationCodePerfect.RefineDeclaration(text),
                this.injectedBefore.Translate(),
                classVisibility,
                Lexems.ClassKeyword,
                this.Name.Translate(),
                baseList,
                Lexems.OpenCurlyBracket);
            }

            // Translating members first
            foreach (ITranslationUnit translationUnit in this.memberDeclarations)
            {
                writer.WriteLine("{0}{1}", translationUnit.Translate(), Lexems.Semicolon);
            }

            // Adding a newline
            if (this.memberDeclarations.Count() > 0 && (
                this.constructorDeclarations.Count() > 0 ||
                this.propertyDeclarations.Count() > 0 ||
                this.methodDeclarations.Count() > 0))
            {
                writer.WriteLine(string.Empty);
            }

            // Then constructors
            foreach (ITranslationUnit translationUnit in this.constructorDeclarations)
            {
                writer.WriteLine("{0}{1}", translationUnit.Translate(), this.RenderedConstructorDeclarationAfterSeparator);
            }

            // Adding a newline
            if (this.constructorDeclarations.Count() > 0 && (
                this.propertyDeclarations.Count() > 0 ||
                this.methodDeclarations.Count() > 0))
            {
                writer.WriteLine(string.Empty);
            }

            // Then properties
            foreach (ITranslationUnit translationUnit in this.propertyDeclarations)
            {
                writer.WriteLine("{0}{1}", translationUnit.Translate(), this.RenderedPropertyDeclarationAfterSeparator);
            }

            // Adding a newline
            if (this.propertyDeclarations.Count() > 0 && this.methodDeclarations.Count() > 0)
            {
                writer.WriteLine(string.Empty);
            }

            // Finally methods
            foreach (ITranslationUnit translationUnit in this.methodDeclarations)
            {
                writer.WriteLine("{0}{1}", translationUnit.Translate(), this.RenderedMethodDeclarationAfterSeparator);
            }

            // Closing
            writer.WriteLine("{0}",
                text => ClassDeclarationCodePerfect.RefineDeclaration(text),
                Lexems.CloseCurlyBracket);

            return writer.ToString();
        }
        /// <summary>
        /// Translate the unit into TypeScript.
        /// </summary>
        /// <returns></returns>
        public override string Translate()
        {
            FormatWriter writer = new FormatWriter()
            {
                Formatter = this.Formatter
            };

            // TODO: Use `{0}{1}{2}{1}{3}` when FormatWriter gets fixed to support repetitive placeholders
            writer.Write("{0}{1}{2}{3}{4}",
                this.LeftOperand.Translate(),
                Lexems.Whitespace,
                TokenUtility.ToString(this.operatorToken),
                Lexems.Whitespace,
                this.RightOperand.Translate());

            return writer.ToString();
        }
        /// <summary>
        /// Translate the unit into TypeScript.
        /// </summary>
        /// <returns></returns>
        public override string Translate()
        {
            FormatWriter writer = new FormatWriter()
            {
                Formatter = this.Formatter
            };

            writer.Write("{0}{1}{2}",
                Lexems.OpenRoundBracket,
                this.WrappedExpression.Translate(),
                Lexems.CloseRoundBracket);

            return writer.ToString();
        }
        /// <summary>
        /// Translate the unit into TypeScript.
        /// </summary>
        /// <returns></returns>
        public string Translate()
        {
            FormatWriter writer = new FormatWriter()
            {
                Formatter = this.Formatter
            };

            if (this.hasGet)
            {
                // Opening declaration: [<visibility>] get <name>() : <type> {
                // TODO: Handle case of no visibility specified
                writer.WriteLine("{0}{1}{2} {3} {4}{5}",
                    this.RenderedVisibilityModifier,
                    this.RenderedGetterMethodName,
                    Lexems.OpenRoundBracket + Lexems.CloseRoundBracket,
                    Lexems.Colon,
                    this.type.Translate(),
                    this.hasSet ? Lexems.Semicolon : string.Empty); // TODO: Find a better way for this
            }

            if (this.hasSet)
            {
                var valueParameter = ArgumentDefinitionTranslationUnit.Create(
                    this.type, IdentifierTranslationUnit.Create("value"));

                // Opening declaration: [<visibility>] set <name>(value : <type>) : void {
                // Emitting `void` in order to prevent errors in case of implicitAllowAny
                writer.WriteLine("{0}{1}{2}{3}{4} {5} {6}",
                    this.RenderedVisibilityModifier,
                    this.RenderedSetterMethodName,
                    Lexems.OpenRoundBracket,
                    valueParameter.Translate(),
                    Lexems.CloseRoundBracket,
                    Lexems.Colon,
                    Lexems.VoidReturnType);
            }

            return writer.ToString();
        }
        /// <summary>
        /// Translate the unit into TypeScript.
        /// </summary>
        /// <returns></returns>
        public override string Translate()
        {
            FormatWriter writer = new FormatWriter()
            {
                Formatter = this.Formatter
            };

            writer.Write("{0}",
                keyword);

            return writer.ToString();
        }
        /// <summary>
        /// Translate the unit into TypeScript.
        /// </summary>
        /// <returns></returns>
        public override string Translate()
        {
            FormatWriter writer = new FormatWriter()
            {
                Formatter = this.Formatter
            };

            writer.Write("{0}{1}{2}{3}",
                Lexems.OpenAngularBracket,
                this.Type.Translate(),
                Lexems.CloseAngularBracket,
                this.Castee.Translate());

            return writer.ToString();
        }
        /// <summary>
        /// Translate the unit into TypeScript.
        /// </summary>
        /// <returns></returns>
        public override string Translate()
        {
            FormatWriter writer = new FormatWriter()
            {
                Formatter = this.Formatter
            };

            // Opening declaration: <visibility> constructor(<params>) {
            writer.WriteLine("{0}{1}{2} {3}",
                this.Visibility.ConvertToTypeScriptEquivalent().EmitOptionalVisibility(),
                Lexems.ConstructorKeyword,
                SyntaxUtility.ToBracketEnclosedList(this.Arguments.Select(unit => unit.Translate())),
                Lexems.OpenCurlyBracket);

            // Statements
            // The body, we render them as a list of semicolon/newline separated elements
            foreach (ITranslationUnit statement in this.statements)
            {
                writer.WriteLine("{0}{1}",
                    statement.Translate(),
                    ShouldRenderSemicolon(statement) ? Lexems.Semicolon : string.Empty);
            }

            // Closing declaration
            writer.WriteLine("{0}", Lexems.CloseCurlyBracket);

            return writer.ToString();
        }
Example #56
0
        /// <summary>
        /// Translate the unit into TypeScript.
        /// </summary>
        /// <returns></returns>
        public string Translate()
        {
            FormatWriter writer = new FormatWriter()
            {
                Formatter = this.Formatter
            };

            // Opening declaration
            writer.WriteLine("{0} {1} {2} {3}",
                text => ClassDeclarationCodePerfect.RefineDeclaration(text),
                Lexems.ExportKeyword,
                Lexems.ModuleKeyword,
                this.name.Translate(),
                Lexems.OpenCurlyBracket);

            // We render classes first
            foreach (ITranslationUnit translationUnit in this.classes)
            {
                if (translationUnit as NestedElementTranslationUnit != null)
                {
                    ((NestedElementTranslationUnit)translationUnit).NestingLevel = this.NestingLevel + 1;
                }

                // Classes need injection for observing indentation
                if (translationUnit as ITranslationInjector != null)
                {
                    ((ITranslationInjector)translationUnit).InjectedTranslationUnitBefore = IdentifierTranslationUnit.Create(Lexems.ExportKeyword);
                }

                writer.WriteLine(translationUnit.Translate());
            }

            // Then, interfaces
            foreach (ITranslationUnit translationUnit in this.interfaces)
            {
                if (translationUnit as NestedElementTranslationUnit != null)
                {
                    ((NestedElementTranslationUnit)translationUnit).NestingLevel = this.NestingLevel + 1;
                }
                writer.WriteLine("{0} {1}",
                    Lexems.ExportKeyword,
                    translationUnit.Translate());
            }

            // Closing declaration
            writer.WriteLine("{0}", Lexems.CloseCurlyBracket);

            return writer.ToString();
        }
        /// <summary>
        /// Translate the unit into TypeScript.
        /// </summary>
        /// <returns></returns>
        public string Translate()
        {
            FormatWriter writer = new FormatWriter()
            {
                Formatter = this.Formatter
            };

            foreach (var statement in this.statements)
            {
                writer.WriteLine("{0}{1}",
                    statement.Translate(),
                    this.ShouldRenderSemicolon(statement) ? Lexems.Semicolon : string.Empty);
            }

            return writer.ToString();
        }
        /// <summary>
        /// Translate the unit into TypeScript.
        /// </summary>
        /// <returns></returns>
        public string Translate()
        {
            FormatWriter writer = new FormatWriter()
            {
                Formatter = this.Formatter
            };

            writer.Write("{0} {1}",
                this.commentToken,
                this.comment);

            return writer.ToString();
        }