예제 #1
0
        public void FlattenMap_ReturnsOnlyLineInformation()
        {
            // Arrange
            SourcePosition generated1   = UnitTestUtils.GenerateSourcePosition(lineNumber: 1, colNumber: 2);
            SourcePosition original1    = UnitTestUtils.GenerateSourcePosition(lineNumber: 2, colNumber: 2);
            MappingEntry   mappingEntry = UnitTestUtils.GetSimpleEntry(generated1, original1, "sourceOne.js");

            SourceMap map = new SourceMap
            {
                File    = "generated.js",
                Sources = new List <string> {
                    "sourceOne.js"
                },
                ParsedMappings = new List <MappingEntry> {
                    mappingEntry
                },
                SourcesContent = new List <string> {
                    "var a = b"
                }
            };

            // Act
            SourceMap linesOnlyMap = SourceMapTransformer.Flatten(map);

            // Assert
            Assert.IsNotNull(linesOnlyMap);
            Assert.AreEqual(1, linesOnlyMap.Sources.Count);
            Assert.AreEqual(1, linesOnlyMap.SourcesContent.Count);
            Assert.AreEqual(1, linesOnlyMap.ParsedMappings.Count);
            Assert.AreEqual(1, linesOnlyMap.ParsedMappings[0].GeneratedSourcePosition.ZeroBasedLineNumber);
            Assert.AreEqual(0, linesOnlyMap.ParsedMappings[0].GeneratedSourcePosition.ZeroBasedColumnNumber);
            Assert.AreEqual(2, linesOnlyMap.ParsedMappings[0].OriginalSourcePosition.ZeroBasedLineNumber);
            Assert.AreEqual(0, linesOnlyMap.ParsedMappings[0].OriginalSourcePosition.ZeroBasedColumnNumber);
        }
예제 #2
0
        public void ApplyMap_ExactMatchDeep_ReturnsCorrectMappingEntry()
        {
            // Arrange
            var generated1 = UnitTestUtils.GenerateSourcePosition(lineNumber: 3, colNumber: 5);
            var original1  = UnitTestUtils.GenerateSourcePosition(lineNumber: 2, colNumber: 10);
            var mapLevel2  = UnitTestUtils.GetSimpleEntry(generated1, original1, "sourceThree.js");

            var grandChildMap = new SourceMap
            {
                File    = "sourceTwo.js",
                Sources = new List <string> {
                    "sourceThree.js"
                },
                ParsedMappings = new List <MappingEntry> {
                    mapLevel2
                }
            };

            var generated2 = UnitTestUtils.GenerateSourcePosition(lineNumber: 4, colNumber: 3);
            var original2  = UnitTestUtils.GenerateSourcePosition(lineNumber: 3, colNumber: 5);
            var mapLevel1  = UnitTestUtils.GetSimpleEntry(generated2, original2, "sourceTwo.js");

            var childMap = new SourceMap
            {
                File    = "sourceOne.js",
                Sources = new List <string> {
                    "sourceTwo.js"
                },
                ParsedMappings = new List <MappingEntry> {
                    mapLevel1
                }
            };

            var generated3 = UnitTestUtils.GenerateSourcePosition(lineNumber: 5, colNumber: 5);
            var original3  = UnitTestUtils.GenerateSourcePosition(lineNumber: 4, colNumber: 3);
            var mapLevel0  = UnitTestUtils.GetSimpleEntry(generated3, original3, "sourceOne.js");

            var parentMap = new SourceMap
            {
                File    = "generated.js",
                Sources = new List <string> {
                    "sourceOne.js"
                },
                ParsedMappings = new List <MappingEntry> {
                    mapLevel0
                }
            };

            // Act
            var firstCombinedMap = parentMap.ApplySourceMap(childMap);

            // Assert
            Assert.IsNotNull(firstCombinedMap);
            var secondCombinedMap = firstCombinedMap.ApplySourceMap(grandChildMap);

            Assert.IsNotNull(secondCombinedMap);
            var rootMapping = secondCombinedMap.GetMappingEntryForGeneratedSourcePosition(generated3);

            Assert.AreEqual(0, rootMapping.OriginalSourcePosition.CompareTo(mapLevel2.OriginalSourcePosition));
        }
예제 #3
0
        public void ApplyMap_PartialMatchingSources_ReturnsCorrectMap()
        {
            // Expect mappings with same source filename as the applied source-map to be replaced
            // mappings with a different source filename should stay the same

            // Arrange
            var generated1   = UnitTestUtils.GenerateSourcePosition(lineNumber: 2, colNumber: 10);
            var original1    = UnitTestUtils.GenerateSourcePosition(lineNumber: 1, colNumber: 5);
            var childMapping = UnitTestUtils.GetSimpleEntry(generated1, original1, "sourceTwo.js");

            var childMap = new SourceMap
            {
                File    = "sourceOne.js",
                Sources = new List <string> {
                    "sourceTwo.js"
                },
                ParsedMappings = new List <MappingEntry> {
                    childMapping
                }
            };

            var generated2 = UnitTestUtils.GenerateSourcePosition(lineNumber: 3, colNumber: 2);
            var original2  = UnitTestUtils.GenerateSourcePosition(lineNumber: 2, colNumber: 10);
            var mapping    = UnitTestUtils.GetSimpleEntry(generated2, original2, "sourceOne.js");

            var generated3 = UnitTestUtils.GenerateSourcePosition(lineNumber: 4, colNumber: 3);
            var original3  = UnitTestUtils.GenerateSourcePosition(lineNumber: 3, colNumber: 2);
            var mapping2   = UnitTestUtils.GetSimpleEntry(generated3, original3, "noMapForThis.js");

            var parentMap = new SourceMap
            {
                File    = "generated.js",
                Sources = new List <string> {
                    "sourceOne.js", "noMapForThis.js"
                },
                ParsedMappings = new List <MappingEntry> {
                    mapping, mapping2
                }
            };

            // Act
            var combinedMap = parentMap.ApplySourceMap(childMap);

            // Assert
            Assert.IsNotNull(combinedMap);
            Assert.AreEqual(2, combinedMap.ParsedMappings.Count);
            Assert.AreEqual(2, combinedMap.Sources.Count);
            var firstCombinedMapping = combinedMap.GetMappingEntryForGeneratedSourcePosition(generated3);

            Assert.IsTrue(firstCombinedMapping.IsValueEqual(mapping2));
            var secondCombinedMapping = combinedMap.GetMappingEntryForGeneratedSourcePosition(generated2);

            Assert.AreEqual(0,
                            secondCombinedMapping.OriginalSourcePosition.CompareTo(childMapping.OriginalSourcePosition));
        }
예제 #4
0
        public void ApplyMap_MatchingSources_ReturnsCorrectMap()
        {
            // Expect mapping with same source filename as the applied source-map to be replaced

            // Arrange
            var generated1   = UnitTestUtils.GenerateSourcePosition(lineNumber: 2, colNumber: 4);
            var original1    = UnitTestUtils.GenerateSourcePosition(lineNumber: 1, colNumber: 3);
            var childMapping = UnitTestUtils.GetSimpleEntry(generated1, original1, "sourceTwo.js");

            var childMap = new SourceMap
            {
                File    = "sourceOne.js",
                Sources = new List <string> {
                    "sourceTwo.js"
                },
                ParsedMappings = new List <MappingEntry> {
                    childMapping
                }
            };

            var generated2    = UnitTestUtils.GenerateSourcePosition(lineNumber: 3, colNumber: 5);
            var original2     = UnitTestUtils.GenerateSourcePosition(lineNumber: 2, colNumber: 4);
            var parentMapping = UnitTestUtils.GetSimpleEntry(generated2, original2, "sourceOne.js");

            var parentMap = new SourceMap
            {
                File    = "generated.js",
                Sources = new List <string> {
                    "sourceOne.js"
                },
                ParsedMappings = new List <MappingEntry> {
                    parentMapping
                }
            };

            // Act
            var combinedMap = parentMap.ApplySourceMap(childMap);

            // Assert
            Assert.IsNotNull(combinedMap);
            Assert.AreEqual(1, combinedMap.ParsedMappings.Count);
            Assert.AreEqual(1, combinedMap.Sources.Count);
            var rootMapping = combinedMap.GetMappingEntryForGeneratedSourcePosition(generated2);

            Assert.AreEqual(0, rootMapping.OriginalSourcePosition.CompareTo(childMapping.OriginalSourcePosition));
        }
예제 #5
0
        public void ApplyMap_NoMatchingMappings_ReturnsSameMap()
        {
            // Arrange
            var generated1   = UnitTestUtils.GenerateSourcePosition(lineNumber: 2, colNumber: 2);
            var original1    = UnitTestUtils.GenerateSourcePosition(lineNumber: 1, colNumber: 10);
            var childMapping = UnitTestUtils.GetSimpleEntry(generated1, original1, "sourceTwo.js");

            var childMap = new SourceMap
            {
                File    = "sourceOne.js",
                Sources = new List <string> {
                    "sourceTwo.js"
                },
                ParsedMappings = new List <MappingEntry> {
                    childMapping
                }
            };

            var generated2    = UnitTestUtils.GenerateSourcePosition(lineNumber: 3, colNumber: 4);
            var original2     = UnitTestUtils.GenerateSourcePosition(lineNumber: 2, colNumber: 5);
            var parentMapping = UnitTestUtils.GetSimpleEntry(generated2, original2, "sourceOne.js");

            var parentMap = new SourceMap
            {
                File    = "generated.js",
                Sources = new List <string> {
                    "sourceOne.js"
                },
                ParsedMappings = new List <MappingEntry> {
                    parentMapping
                }
            };

            // Act
            var combinedMap = parentMap.ApplySourceMap(childMap);

            // Assert
            Assert.IsNotNull(combinedMap);
            var firstMapping = combinedMap.ParsedMappings[0];

            Assert.IsTrue(firstMapping.IsValueEqual(parentMapping));
        }
예제 #6
0
        public void ApplyMap_NullSubmap_ThrowsException()
        {
            // Arrange
            var generated2 = UnitTestUtils.GenerateSourcePosition(lineNumber: 3, colNumber: 5);
            var original2  = UnitTestUtils.GenerateSourcePosition(lineNumber: 2, colNumber: 5);
            var mapping    = UnitTestUtils.GetSimpleEntry(generated2, original2, "sourceOne.js");

            var map = new SourceMap
            {
                File    = "generated.js",
                Sources = new List <string> {
                    "sourceOne.js"
                },
                ParsedMappings = new List <MappingEntry> {
                    mapping
                }
            };

            // Act
            var combinedMap = map.ApplySourceMap(null);

            // Assert (decorated expected exception)
        }
예제 #7
0
        public void GetRootMappingEntryForGeneratedSourcePosition_NoChildren_ReturnsSameEntry()
        {
            // Arrange
            var generated1   = UnitTestUtils.GenerateSourcePosition(lineNumber: 2, colNumber: 5);
            var original1    = UnitTestUtils.GenerateSourcePosition(lineNumber: 1, colNumber: 5);
            var mappingEntry = UnitTestUtils.GetSimpleEntry(generated1, original1, "generated.js");

            var sourceMap = new SourceMap
            {
                Sources = new List <string> {
                    "generated.js"
                },
                ParsedMappings = new List <MappingEntry> {
                    mappingEntry
                }
            };

            // Act
            var rootEntry = sourceMap.GetMappingEntryForGeneratedSourcePosition(generated1);

            // Assert
            Assert.AreEqual(rootEntry, mappingEntry);
        }