Ejemplo n.º 1
0
        public void SimpleSampleTest()
        {
            // from http://evanw.github.io/source-map-visualization/
            var consumer = new SourceMapConsumer();

            consumer.Parse(SimpleSourceMapObject);

            Mapping mapping;

            mapping = consumer.GetMappingForLine(new FilePosition(1, 3)); // semicolon on line 2
            Assert.Equal(0, mapping.Original.Line);
            Assert.Equal(2, mapping.Original.Column);

            mapping = consumer.GetMappingForLine(new FilePosition(4, 8)); // the true in if(true)
            Assert.Equal(0, mapping.Original.Line);
            Assert.Equal(10, mapping.Original.Column);

            mapping = consumer.GetMappingForLine(new FilePosition(7, 8)); // the false in if(false)
            Assert.Equal(0, mapping.Original.Line);
            Assert.Equal(27, mapping.Original.Column);

            mapping = consumer.GetMappingForLine(new FilePosition(13, 1)); // the last semicolon on line 14
            Assert.Equal(0, mapping.Original.Line);
            Assert.Equal(47, mapping.Original.Column);
        }
        public void ParsesMappingsUsingDefaultDecoder()
        {
            var consumer = new SourceMapConsumer(new SourceMapFile {
                Version = 3, Mappings = "encoded mappings"
            });

            _decoderMock.Verify(x => x.GetMappingGroups("encoded mappings"), Times.Once());
        }
        public void OriginalPositionsFor_ThrowsArgumentOutOfRangeException_IfColumnLessThanZero()
        {
            var consumer = new SourceMapConsumer(new SourceMapFile {
                Version = 3
            });

            Assert.Throws(typeof(ArgumentOutOfRangeException), () => consumer.OriginalPositionsFor(1, -1));
        }
        public void OriginalPositionsFor_ThrowsArgumentOutOfRangeException_IfLineNumberEqualsZero()
        {
            var consumer = new SourceMapConsumer(new SourceMapFile {
                Version = 3
            });

            Assert.Throws(typeof(ArgumentOutOfRangeException), () => consumer.OriginalPositionsFor(0, 0));
        }
        public void OriginalPositionsFor_ReturnsEmptyArray_IfNoMatchingSourceLines()
        {
            var consumer = new SourceMapConsumer(new SourceMapFile {
                Version = 3
            });
            var sourceLines = consumer.OriginalPositionsFor(15, 0);

            Assert.That(sourceLines, Is.Not.Null);
            Assert.That(sourceLines.Length, Is.EqualTo(0));
        }
Ejemplo n.º 6
0
        private ISourceMapConsumer CreateSourceMap(string file)
        {
            var mapFile = GetMapFile(file);

            if (mapFile == null)
            {
                return(null);
            }

            return(SourceMapConsumer.GetConsumer(mapFile));
        }
        public void OriginalPositionsFor_ReturnsEmptyArray_IfMatchingMappingGroupHasEmptySegments()
        {
            _mappings[1].Segments = Enumerable.Empty <MappingSegment>();

            var consumer = new SourceMapConsumer(new SourceMapFile {
                Version = 3
            });
            var sourceLines = consumer.OriginalPositionsFor(2, 0);

            Assert.That(sourceLines, Is.Not.Null);
            Assert.That(sourceLines.Length, Is.EqualTo(0));
        }
Ejemplo n.º 8
0
        public void OriginalPositionsFor_ReturnsPositionsMappingToGeneratedSourceLine()
        {
            // Line 1 maps to lines 2 and 11
            var consumer = new SourceMapConsumer(new SourceMapFile {
                Version = 3, Sources = new[] { "File", "Other" }
            });
            var sourceLines = consumer.OriginalPositionsFor(1);

            Assert.That(sourceLines, Is.Not.Null);
            Assert.That(sourceLines.Length, Is.EqualTo(2));

            // The segments store indices - add 1 to get line numbers
            Assert.That(sourceLines.Any(x => x.LineNumber == 2));
            Assert.That(sourceLines.Any(x => x.LineNumber == 11));
            Assert.That(sourceLines.All(x => x.File == "Other"));
        }
Ejemplo n.º 9
0
        public void DecodeEncodeTest()
        {
            var consumer = new SourceMapConsumer();

            consumer.Parse(SimpleSourceMapObject);

            var generator = new SourceMapGenerator();

            foreach (var m in consumer.Mappings)
            {
                generator.AddMapping(m);
            }
            var map = generator.Generate();

            Assert.Contains("AAAA;AAAC,GAAC;AAAC,GAAC;AAAC,GAAC;AAAC,MAAG,IAAI,EAAC;OAAG;AAAC,SAAK;QAAG,KAAK,EAAC;SAAG;AAAC,WAAK;SAAG;AAAC;;CAAC", map.mappings);
        }
Ejemplo n.º 10
0
        public static object Map(SourceLocation[] locations, string pathToSourceMap)
        {
            var file = JsonConvert.DeserializeObject <SourceMapFile>(File.ReadAllText(pathToSourceMap));

            var consumer = new SourceMapConsumer(file);

            foreach (var location in locations)
            {
                var mappedPositions = consumer.OriginalPositionsFor(location.Position.LineNumber);
                if (mappedPositions.Length >= 1)
                {
                    location.Position = mappedPositions.First();
                }
            }

            return(null);
        }
        public void TestMappingTokensBackBiased(int sourceLine, int sourceCol, string file, int orgLine, int orgCol, string methodName)
        {
            // Force reset so we don't use the mocked decoder here
            MappingDecoder.Default = null;

            var consumer = new SourceMapConsumer(new SourceMapFile()
            {
                Version    = 3,
                File       = "min.js",
                Names      = new [] { "bar", "baz", "n" },
                SourceRoot = "/the/root",
                Sources    = new [] { "one.js", "two.js" },
                Mappings   = "CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOC,IAAID;CCDb,IAAI,IAAM,SAAUE,GAClB,OAAOA"
            });

            var firstMap = consumer.OriginalPositionsFor(sourceLine, sourceCol);

            Assert.That(firstMap, Is.Not.Null);
            Assert.That(firstMap.Length, Is.EqualTo(1), "Should have 1 source line");
            Assert.That(firstMap.All(x => x.LineNumber == orgLine), $"Original line number should be {orgLine}");
            Assert.That(firstMap.All(x => x.Column == orgCol), $"Original column should be {orgCol}");
            Assert.That(firstMap.All(x => x.File == file), $"Source file should be {file}");
            Assert.That(firstMap.All(x => x.MethodName == methodName), $"Original method name should be {methodName}");
        }