示例#1
0
        public override TypescriptBuilder Build(TypescriptBuilder builder, IElement parent)
        {
            if (string.IsNullOrWhiteSpace(Text))
            {
                return(builder);
            }

            var lines = Text.Split('\r', '\n') //.SelectMany(t => t.Split('\n'))
                        .Where(x => !string.IsNullOrEmpty(x))
                        .Select(s => s.Trim(' ', '\t'))
                        .ToList();

            if (string.IsNullOrWhiteSpace(lines.Last()))
            {
                lines.Remove(lines.Last());
            }

            if (string.IsNullOrWhiteSpace(lines.First()))
            {
                lines.Remove(lines.First());
            }

            if (parent == null)
            {
                var text = string.Join(Environment.NewLine, lines.Select(s => "// " + s));
                return(builder.Append(text));
            }
            else // Treat these as jsdoc comments.
            {
                var text = "//** " + string.Join(" ", lines);
                return(builder.Append(text));
            }
        }
        public override string ToString()
        {
            var builder = new TypescriptBuilder();

            if (Imports.Any())
            {
                foreach (var import in Imports)
                {
                    builder.Append(import, null).NewLine();
                }

                builder.NewLine();
            }

            foreach (var element in Elements)
            {
                if (element == null)
                {
                    continue;
                }

                element.Build(builder, null);

                if (element != Elements.LastOrDefault())
                {
                    builder.NewLine().NewLine();
                }
            }

            return(builder.ToString());
        }
示例#3
0
        public override TypescriptBuilder Build(TypescriptBuilder builder, IElement parent)
        {
            var property = (Property)parent;

            builder.Append("get ").Append(property.Name).Append("()");

            if (property.HasType)
            {
                builder.Append(": ").Append(property.Type);
            }

            return(builder.Append(" {")
                   .Indent()
                   .NewLine()
                   .Join(Statements, this, Environment.NewLine + builder.Indentation)
                   .Unindent()
                   .NewLine()
                   .Append('}'));
        }
示例#4
0
        public override TypescriptBuilder Build(TypescriptBuilder builder, IElement parent)
        {
            if (Decorators.Any())
            {
                builder.NewLine();
            }
            builder.Join(Decorators, b => b.NewLine());
            if (Decorators.Any())
            {
                builder.NewLine();
            }

            if (parent == null)
            {
                builder.Append("var ").Append(Name);

                if (HasType)
                {
                    builder.Append(": ").Append(Type);
                }
                if (HasValue)
                {
                    builder.Append(" = ").Append(Value);
                }

                builder.Append(";");
            }

            if (HasGetter && parent is Class)
            {
                builder.Append(Get, this);
            }

            if (HasGetter && HasSetter)
            {
                builder.NewLine();
            }

            if (HasSetter && parent is Class)
            {
                builder.Append(Set, this);
            }

            if (!HasSetter && !HasGetter && parent != null || parent is Interface)
            {
                var modifiers = Modifiers.Distinct().OrderBy(m => !(m is IAccessor)).Select(m => m.ToString());
                builder.Join(modifiers, " ");

                if (Modifiers.Any())
                {
                    builder.Append(' ');
                }

                builder.Append(Name);

                if (HasType)
                {
                    builder.Append(": ").Append(Type);
                }
                if (HasValue)
                {
                    builder.Append(" = ").Append(Value);
                }

                builder.Append(";");
            }

            return(builder);
        }
示例#5
0
 public override TypescriptBuilder Build(TypescriptBuilder builder, IElement parent) =>
 builder.Append('@')
 .Append(Name)
 .Append('(')
 .Join(Arguments, ", ")
 .Append(')');