Beispiel #1
0
 internal BlockScope(Transpiler visitor, bool requiresBraces)
 {
     _requiresBraces = requiresBraces;
     _visitor        = visitor;
     if (_requiresBraces)
     {
         _visitor.Emit("{");
     }
     _visitor.AddIndent();
 }
Beispiel #2
0
        public static void Main(params string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("missing file argument");
                return;
            }

            var visitor = new Transpiler(File.ReadAllText(args[0]));

            var output = visitor.ToTypeScript();
            var outputFileName = args.Length > 1 ? args[1] : Path.ChangeExtension(args[0], "ts");

            File.WriteAllText(outputFileName, output);
        }
Beispiel #3
0
        protected static void Compare(string code, string expected)
        {
            var actual = new Transpiler(code).ToTypeScript();

            var actualAsList = actual.Replace("\r", "")
                               .Split(new[] { "\n" }, StringSplitOptions.None)
                               .Select(l => l.TrimEnd())
                               .ToArray();

            var expectedAsList = expected
                                 .Replace("\r", "")
                                 .Split(new[] { "\n" }, StringSplitOptions.None)
                                 .SkipWhile(l => l.Trim().Length == 0)
                                 .ToArray();

            expectedAsList = expectedAsList.Take(expectedAsList.Length - 1).ToArray();

            var indentSize = expectedAsList
                             .First()
                             .TakeWhile(l => l == ' ')
                             .Count();

            var indent = new string(' ', indentSize);

            expectedAsList = expectedAsList
                             .Select(l => l.Replace(indent, "").TrimEnd())
                             .ToArray();

            var dump = DisplayLists(expectedAsList, actualAsList);

            try
            {
                CollectionAssert.AreEqual(expectedAsList, actualAsList, dump);
            }
            catch (AssertionException)
            {
                Debug.WriteLine(dump);
                throw;
            }
        }
Beispiel #4
0
        protected static void Compare(string code, string expected)
        {
            var actual = new Transpiler(code).ToTypeScript();

            var actualAsList = actual.Replace("\r", "")
                .Split(new[] { "\n" }, StringSplitOptions.None)
                .Select(l => l.TrimEnd())
                .ToArray();

            var expectedAsList = expected
                .Replace("\r", "")
                .Split(new[] { "\n" }, StringSplitOptions.None)
                .SkipWhile(l => l.Trim().Length == 0)
                .ToArray();

            expectedAsList = expectedAsList.Take(expectedAsList.Length - 1).ToArray();

            var indentSize = expectedAsList
                .First()
                .TakeWhile(l => l == ' ')
                .Count();

            var indent = new string(' ', indentSize);

            expectedAsList = expectedAsList
                .Select(l => l.Replace(indent, "").TrimEnd())
                .ToArray();

            var dump = DisplayLists(expectedAsList, actualAsList);
            try
            {
                CollectionAssert.AreEqual(expectedAsList, actualAsList, dump);
            }
            catch (AssertionException)
            {
                Debug.WriteLine(dump);
                throw;
            }
        }
Beispiel #5
0
 internal BlockScope(Transpiler visitor, bool requiresBraces)
 {
     _requiresBraces = requiresBraces;
     _visitor = visitor;
     if (_requiresBraces)
         _visitor.Emit("{");
     _visitor.AddIndent();
 }
Beispiel #6
0
 internal BlockScope(Transpiler visitor)
     : this(visitor, true)
 {
 }
Beispiel #7
0
 internal BlockScope(Transpiler visitor) : this(visitor, true)
 {
 }