Esempio n. 1
0
        public void SourceMapCache_HandlesDuplicateNames()
        {
            var cache = new SourceMapCache(new SourceMap()
            {
                version    = 3,
                file       = "foo.js",
                sources    = new string[] { "source.js" },
                names      = new string[] { "name1", "name1", "name3" },
                mappings   = ";EAACA;;IAEEA;;MAEEE",
                sourceRoot = "http://example.com"
            });

            {
                var expected = new SourceMapping(1, 1, 2, 2, "source.js", "name1");
                var actual   = cache.SourceMappingFor(2, 2);
                Assert.AreEqual(expected, actual);
            }

            {
                var expected = new SourceMapping(3, 3, 4, 4, "source.js", "name1");
                var actual   = cache.SourceMappingFor(4, 4);
                Assert.AreEqual(expected, actual);
            }

            {
                var expected = new SourceMapping(5, 5, 6, 6, "source.js", "name3");
                var actual   = cache.SourceMappingFor(6, 6);
                Assert.AreEqual(expected, actual);
            }
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            {
                var json = "{ \"version\": 3, \"file\": \"foo.js\", \"sources\": [\"såurce.js\"], \"names\": [\"näme1\", \"name1\", \"name3\"], \"mappings\": \";EAACA;;IAEEA;;MAEEE\", \"sourceRoot\": \"http://example.com\" }";

                var cache   = new SourceMapCache(json);
                var mapping = cache.SourceMappingFor(2, 2);
                Console.WriteLine("OK: {0}", mapping);
            }
            {
                var json = "{ \"version\": 2, \"file\": \"foo.js\", \"sources\": [\"såurce.js\"], \"names\": [\"näme1\", \"name1\", \"name3\"], \"mappings\": \";EAACA;;IAEEA;;MAEEE\", \"sourceRoot\": \"http://example.com\" }";
                try
                {
                    var cache = new SourceMapCache(json);
                    Console.WriteLine("ERR: Should throw on source maps < v3");
                    return;
                }
                catch (SourceMapParsingException e)
                {
                    Console.WriteLine("OK: Does not parse old source maps: {0}", e.Message);
                }
            }
            {
                var json = "{ \"version\": 3, \"file\": \"foo.js\", \"sources\": [\"såurce.js\"], \"names\": [\"näme1\", \"name1\", \"name3\"], \"mappings\": \";;;\", \"sourceRoot\": \"http://example.com\" }";
                try
                {
                    var cache = new SourceMapCache(json);
                    Console.WriteLine("ERR: Should throw on empty source maps");
                    return;
                }
                catch (SourceMapParsingException e)
                {
                    Console.WriteLine("OK: Does not parse empty source maps: {0}", e.Message);
                }
            }
            if (args.Length > 0)
            {
                var jsonPath = args[0];
                Console.WriteLine($"Performance testing with source map: {jsonPath}");
                var watch = new Stopwatch();
                for (var i = 0; i < 10; i++)
                {
                    Console.WriteLine($"Run {i}/10, {watch.ElapsedMilliseconds}ms elapsed");
                    watch.Start();
                    //var json = File.ReadAllText(jsonPath);
                    var jsonStream = new FileStream(jsonPath, FileMode.Open, FileAccess.Read);
                    var cache      = new SourceMapCache(jsonStream);
                    var mapping    = cache.SourceMappingFor(2, 2);
                    watch.Stop();
                }
                Console.WriteLine($"Average duration (read, parse, query): {watch.ElapsedMilliseconds / 10}ms");
            }
            Console.ReadLine();
        }
Esempio n. 3
0
 public void SourceMapCache_AllowsOmittingSourceRoot()
 {
     var cache = new SourceMapCache(new SourceMap()
     {
         version  = 3,
         file     = "foo.js",
         sources  = new string[] { "source.js" },
         names    = new string[] { "name1", "name1", "name3" },
         mappings = ";EAACA;;IAEEA;;MAEEE"
     });
     // Should not throw
 }
Esempio n. 4
0
 public void SourceMapCache_ParsesEmptySourceRoot()
 {
     var cache = new SourceMapCache(new SourceMap()
     {
         version    = 3,
         file       = "foo.js",
         sources    = new string[] { "source.js" },
         names      = new string[] { "name1", "name1", "name3" },
         mappings   = ";EAACA;;IAEEA;;MAEEE",
         sourceRoot = ""
     });
 }
Esempio n. 5
0
        public void SourceMapCache_ParsesSimpleSourceMap()
        {
            var cache = new SourceMapCache(new SourceMap()
            {
                version    = 3,
                file       = "foo.js",
                sourceRoot = "http://example.com/",
                sources    = new string[] { "/a" },
                names      = new string[] { },
                mappings   = "AACA"
            });

            var expected = new SourceMapping(2, 0, 1, 0, "/a", "");
            var actual   = cache.SourceMappingFor(1, 0);

            Assert.AreEqual(expected, actual);
        }
Esempio n. 6
0
 public void SourceMapCache_ThrowsWhenThereAreNoMappings()
 {
     try
     {
         var cache = new SourceMapCache(new SourceMap()
         {
             version  = 3,
             file     = "foo.js",
             sources  = new string[] { "source.js" },
             names    = new string[] { "name1", "name1", "name3" },
             mappings = ";;;"
         });
         Assert.Fail("Source maps with no mappings should be rejected");
     }
     catch (SourceMapParsingException e)
     {
         // OK
     }
 }
Esempio n. 7
0
 public void SourceMapCache_RejectsInvalidSourceMapsNormally()
 {
     try
     {
         var cache = new SourceMapCache(new SourceMap()
         {
             version  = 3,
             file     = "",
             sources  = new string[] { },
             names    = new string[] { },
             mappings = ";EAACA;;IAEEA;;MAEEE"
         });
         Assert.Fail("Invalid source maps should be rejected");
     }
     catch (SourceMapParsingException e)
     {
         // OK
     }
 }
Esempio n. 8
0
 public void SourceMapCache_RejectsOlderSourceMapRevisions()
 {
     try
     {
         var cache = new SourceMapCache(new SourceMap()
         {
             version    = 2,
             file       = "",
             sources    = new string[] { "source.js" },
             names      = new string[] { "name1", "name1", "name3" },
             mappings   = ";EAACA;;IAEEA;;MAEEE",
             sourceRoot = "http://example.com"
         });
         Assert.Fail("Source Map revision < 3 should be rejected");
     }
     catch (SourceMapParsingException e)
     {
         // OK
     }
 }