public void GetMappingEntryForGeneratedSourcePosition_NoExactMatchHasSimilarOnSameLine_ReturnSimilarEntry() { // Arrange SourceMap sourceMap = new SourceMap(); MappingEntry matchingMappingEntry = new MappingEntry { GeneratedSourcePosition = new SourcePosition { ZeroBasedLineNumber = 10, ZeroBasedColumnNumber = 13 } }; sourceMap.ParsedMappings = new List <MappingEntry> { new MappingEntry { GeneratedSourcePosition = new SourcePosition { ZeroBasedLineNumber = 0, ZeroBasedColumnNumber = 0 } }, matchingMappingEntry }; SourcePosition sourcePosition = new SourcePosition { ZeroBasedLineNumber = 10, ZeroBasedColumnNumber = 14 }; // Act MappingEntry result = sourceMap.GetMappingEntryForGeneratedSourcePosition(sourcePosition); // Asset Assert.AreEqual(matchingMappingEntry, result); }
/// <summary> /// Inspects the module code. /// </summary> /// <param name="interpeter">The interpreter.</param> private static void InspectCode(ref Interpreter interpreter) { var code = interpreter.Module.Code; var format = "{0," + Digits(code.Length - 1) + "} {1}"; SourceMap last = null; for (var i = 0; i < code.Length; i++) { if (i == interpreter.IP) { Console.Write('>'); } else { Console.Write(' '); } Console.Write(format, i, code[i].ToString()); var src = interpreter.GetSourceMap(i); if (src?.Row != null && src?.Row != last?.Row) { Console.Write(" {0}", src.SourceText[src.Row.Value]); last = src; } Console.WriteLine(); } }
public void GetDeminifiedMethodNameFromSourceMap_HasSingleBindingNoMatchingMapping_ReturnNullMethodName() { // Arrange FunctionMapEntry functionMapEntry = new FunctionMapEntry { Bindings = new List <BindingInformation> { new BindingInformation { SourcePosition = new SourcePosition { ZeroBasedLineNumber = 20, ZeroBasedColumnNumber = 15 } } } }; SourceMap sourceMap = MockRepository.GenerateStub <SourceMap>(); sourceMap.Stub(x => x.GetMappingEntryForGeneratedSourcePosition(Arg <SourcePosition> .Is.Anything)).Return(null); // Act string result = FunctionMapGenerator.GetDeminifiedMethodNameFromSourceMap(functionMapEntry, sourceMap); // Assert Assert.IsNull(result); sourceMap.VerifyAllExpectations(); }
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)); }
public void ParseSourceCode_TwoNestedSingleLineFunctions_TwoFunctionMapEntries() { // Arrange FunctionMapGenerator functionMapGenerator = new FunctionMapGenerator(); string sourceCode = "function foo(){function bar(){baz();}}"; SourceMap sourceMap = CreateSourceMapMock(); // Act IReadOnlyList <FunctionMapEntry> functionMap = functionMapGenerator.ParseSourceCode(UnitTestUtils.StreamReaderFromString(sourceCode), sourceMap); // Assert Assert.Equal(2, functionMap.Count); Assert.Equal("bar", functionMap[0].Bindings[0].Name); Assert.Equal(0, functionMap[0].Bindings[0].SourcePosition.ZeroBasedLineNumber); Assert.Equal(24, functionMap[0].Bindings[0].SourcePosition.ZeroBasedColumnNumber); Assert.Equal(0, functionMap[0].StartSourcePosition.ZeroBasedLineNumber); Assert.Equal(0, functionMap[0].EndSourcePosition.ZeroBasedLineNumber); Assert.Equal(29, functionMap[0].StartSourcePosition.ZeroBasedColumnNumber); Assert.Equal(37, functionMap[0].EndSourcePosition.ZeroBasedColumnNumber); Assert.Equal("foo", functionMap[1].Bindings[0].Name); Assert.Equal(0, functionMap[1].Bindings[0].SourcePosition.ZeroBasedLineNumber); Assert.Equal(9, functionMap[1].Bindings[0].SourcePosition.ZeroBasedColumnNumber); Assert.Equal(0, functionMap[1].StartSourcePosition.ZeroBasedLineNumber); Assert.Equal(0, functionMap[1].EndSourcePosition.ZeroBasedLineNumber); Assert.Equal(14, functionMap[1].StartSourcePosition.ZeroBasedColumnNumber); Assert.Equal(38, functionMap[1].EndSourcePosition.ZeroBasedColumnNumber); }
public void GetMappingEntryForGeneratedSourcePosition_MatchingEntryInMappingList_ReturnMatchingEntry() { // Arrange SourceMap sourceMap = new SourceMap(); MappingEntry matchingMappingEntry = new MappingEntry { GeneratedSourcePosition = new SourcePosition { ZeroBasedLineNumber = 8, ZeroBasedColumnNumber = 13 } }; sourceMap.ParsedMappings = new List <MappingEntry> { new MappingEntry { GeneratedSourcePosition = new SourcePosition { ZeroBasedLineNumber = 0, ZeroBasedColumnNumber = 0 } }, matchingMappingEntry }; SourcePosition sourcePosition = new SourcePosition { ZeroBasedLineNumber = 8, ZeroBasedColumnNumber = 13 }; // Act MappingEntry result = sourceMap.GetMappingEntryForGeneratedSourcePosition(sourcePosition); // Asset Assert.Equal(matchingMappingEntry, result); }
/// <summary> /// The post fixed attribute matcher. /// </summary> public static IEnumerable <AttributeComparison> Match(IDiffContext context, SourceMap controlSources, SourceMap testSources) { if (controlSources is null) { throw new ArgumentNullException(nameof(controlSources)); } if (testSources is null) { throw new ArgumentNullException(nameof(testSources)); } foreach (var control in controlSources.GetUnmatched()) { var ctrlName = control.Attribute.Name; if (!NameHasPostfixSeparator(ctrlName)) { continue; } ctrlName = RemovePostfixFromName(ctrlName); if (testSources.Contains(ctrlName) && testSources.IsUnmatched(ctrlName)) { yield return(new AttributeComparison(control, testSources[ctrlName])); } } yield break; }
public void AddMapping(string origpath, string localpath) { if (!SourceMap.ContainsKey(origpath)) { SourceMap.Add(origpath, localpath); } }
public void GetDeminifiedMethodNameFromSourceMap_HasSingleBindingMatchingMapping_ReturnsMethodName() { // Arrange FunctionMapEntry functionMapEntry = new FunctionMapEntry { Bindings = new List <BindingInformation> { new BindingInformation { SourcePosition = new SourcePosition { ZeroBasedLineNumber = 5, ZeroBasedColumnNumber = 8 } } } }; SourceMap sourceMap = MockRepository.GenerateStub <SourceMap>(); sourceMap.Stub( x => x.GetMappingEntryForGeneratedSourcePosition( Arg <SourcePosition> .Matches(y => y.ZeroBasedLineNumber == 5 && y.ZeroBasedColumnNumber == 8))) .Return(new MappingEntry { OriginalName = "foo", }); // Act string result = FunctionMapGenerator.GetDeminifiedMethodNameFromSourceMap(functionMapEntry, sourceMap); // Assert Assert.AreEqual("foo", result); sourceMap.VerifyAllExpectations(); }
public static void AssertMapping( int generatedLine, int generatedColumn, string originalSource, int?originalLine, int?originalColumn, string name, SourceMap map) { var mapping = map.OriginalPositionFor(generatedLine, generatedColumn); Assert.NotNull(mapping); Assert.Equal(name, mapping?.OriginalName); Assert.Equal(originalLine ?? 0, mapping?.OriginalLineNumber); Assert.Equal(originalColumn ?? 0, mapping?.OriginalColumnNumber); var expectedSource = (originalSource, map.SourceRoot) switch { var(source, root) when source?.IndexOf(root) == 0 => source, var(source, root) when source != null && root != null => Path.Join(root, source), var(source, root) when source != null => source, _ => null, }; Assert.Equal(expectedSource, mapping?.OriginalFileName); }
public static void AssertEqualMaps(SourceMap expected, SourceMap actual) { Assert.Equal(expected.Version, actual.Version); Assert.Equal(expected.File, actual.File); Assert.Equal(expected.Names.Count, actual.Names.Count); for (var i = 0; i < expected.Names.Count; i++) { Assert.Equal(expected.Names[i], actual.Names[i]); } Assert.Equal(expected.Sources.Count, actual.Sources.Count); for (var i = 0; i < expected.Sources.Count; i++) { Assert.Equal(expected.Sources[i], actual.Sources[i]); } Assert.Equal(expected.SourceRoot, actual.SourceRoot); Assert.Equal(expected.MappingsString, actual.MappingsString); if (expected.SourcesContent != null) { Assert.Equal(expected.SourcesContent.Count, actual.SourcesContent.Count); for (var i = 0; i < expected.SourcesContent.Count; i++) { Assert.Equal(expected.SourcesContent[i], actual.SourcesContent[i]); } } }
private void FormatEntry(Span sp, SourceMap sourceMap, string additional) { Console.Write($"{Color.NicePurple.ToS()}{FormatLocation(sp, sourceMap)}{Color.Reset.ToS()}: "); Console.WriteLine($"{Color.Bold.ToS()}{Color.Red.ToS()}{additional}{Color.Reset.ToS()}"); var(_, a, b, c, d) = GetHumanPos(sp, sourceMap); Console.Write(FormatLines(sourceMap.LookupSource(sp.Sid).Split("\n"), a, b, c, d)); }
public override void DisplayError(SourceMap sourceMap) { foreach (Error err in _errs) { err.DisplayError(sourceMap); } }
public void ParseSourceCode_InstanceMethodWithObjectInitializerAndFunctionHasName_FunctionMapEntryGeneratedForObjectPrototype() { // Arrange FunctionMapGenerator functionMapGenerator = new FunctionMapGenerator(); string sourceCode = "var foo = function(){} foo.prototype = { bar: function myCoolFunctionName() { baz(); } }"; SourceMap sourceMap = CreateSourceMapMock(); // Act IReadOnlyList <FunctionMapEntry> functionMap = functionMapGenerator.ParseSourceCode(UnitTestUtils.StreamReaderFromString(sourceCode), sourceMap); // Assert Assert.Equal(2, functionMap.Count); Assert.Equal("foo", functionMap[0].Bindings[0].Name); Assert.Equal(0, functionMap[0].Bindings[0].SourcePosition.ZeroBasedLineNumber); Assert.Equal(23, functionMap[0].Bindings[0].SourcePosition.ZeroBasedColumnNumber); Assert.Equal("bar", functionMap[0].Bindings[1].Name); Assert.Equal(0, functionMap[0].Bindings[1].SourcePosition.ZeroBasedLineNumber); Assert.Equal(41, functionMap[0].Bindings[1].SourcePosition.ZeroBasedColumnNumber); Assert.Equal(0, functionMap[0].StartSourcePosition.ZeroBasedLineNumber); Assert.Equal(0, functionMap[0].EndSourcePosition.ZeroBasedLineNumber); Assert.Equal(76, functionMap[0].StartSourcePosition.ZeroBasedColumnNumber); Assert.Equal(86, functionMap[0].EndSourcePosition.ZeroBasedColumnNumber); Assert.Equal("foo", functionMap[1].Bindings[0].Name); Assert.Equal(0, functionMap[1].Bindings[0].SourcePosition.ZeroBasedLineNumber); Assert.Equal(4, functionMap[1].Bindings[0].SourcePosition.ZeroBasedColumnNumber); Assert.Equal(0, functionMap[1].StartSourcePosition.ZeroBasedLineNumber); Assert.Equal(0, functionMap[1].EndSourcePosition.ZeroBasedLineNumber); Assert.Equal(20, functionMap[1].StartSourcePosition.ZeroBasedColumnNumber); Assert.Equal(22, functionMap[1].EndSourcePosition.ZeroBasedColumnNumber); }
public void ParseSourceCode_StaticMethodAndFunctionHasName_FunctionMapEntryGeneratedForPropertyName() { // Arrange FunctionMapGenerator functionMapGenerator = new FunctionMapGenerator(); string sourceCode = "var foo = function(){};foo.bar = function myCoolFunctionName() { baz(); }"; SourceMap sourceMap = CreateSourceMapMock(); // Act IReadOnlyList <FunctionMapEntry> functionMap = functionMapGenerator.ParseSourceCode(UnitTestUtils.StreamReaderFromString(sourceCode), sourceMap); // Assert Assert.Equal(2, functionMap.Count); Assert.Equal("foo", functionMap[0].Bindings[0].Name); Assert.Equal("bar", functionMap[0].Bindings[1].Name); Assert.Equal(0, functionMap[0].Bindings[0].SourcePosition.ZeroBasedLineNumber); Assert.Equal(23, functionMap[0].Bindings[0].SourcePosition.ZeroBasedColumnNumber); Assert.Equal(0, functionMap[0].StartSourcePosition.ZeroBasedLineNumber); Assert.Equal(0, functionMap[0].EndSourcePosition.ZeroBasedLineNumber); Assert.Equal(63, functionMap[0].StartSourcePosition.ZeroBasedColumnNumber); Assert.Equal(73, functionMap[0].EndSourcePosition.ZeroBasedColumnNumber); Assert.Equal("foo", functionMap[1].Bindings[0].Name); Assert.Equal(0, functionMap[1].Bindings[0].SourcePosition.ZeroBasedLineNumber); Assert.Equal(4, functionMap[1].Bindings[0].SourcePosition.ZeroBasedColumnNumber); Assert.Equal(0, functionMap[1].StartSourcePosition.ZeroBasedLineNumber); Assert.Equal(0, functionMap[1].EndSourcePosition.ZeroBasedLineNumber); Assert.Equal(20, functionMap[1].StartSourcePosition.ZeroBasedColumnNumber); Assert.Equal(22, functionMap[1].EndSourcePosition.ZeroBasedColumnNumber); }
public void ParseSourceCode_InstanceMethod_FunctionMapEntryGenerated() { // Arrange FunctionMapGenerator functionMapGenerator = new FunctionMapGenerator(); string sourceCode = "var foo = function(){} foo.prototype.bar = function () { baz(); }"; SourceMap sourceMap = CreateSourceMapMock(); // Act IReadOnlyList <FunctionMapEntry> functionMap = functionMapGenerator.ParseSourceCode(UnitTestUtils.StreamReaderFromString(sourceCode), sourceMap); // Assert Assert.Equal(2, functionMap.Count); Assert.Equal("foo.prototype", functionMap[0].Bindings[0].Name); Assert.Equal("bar", functionMap[0].Bindings[1].Name); Assert.Equal(0, functionMap[0].Bindings[0].SourcePosition.ZeroBasedLineNumber); Assert.Equal(23, functionMap[0].Bindings[0].SourcePosition.ZeroBasedColumnNumber); Assert.Equal(0, functionMap[0].StartSourcePosition.ZeroBasedLineNumber); Assert.Equal(0, functionMap[0].EndSourcePosition.ZeroBasedLineNumber); Assert.Equal(55, functionMap[0].StartSourcePosition.ZeroBasedColumnNumber); Assert.Equal(65, functionMap[0].EndSourcePosition.ZeroBasedColumnNumber); Assert.Equal("foo", functionMap[1].Bindings[0].Name); Assert.Equal(0, functionMap[1].Bindings[0].SourcePosition.ZeroBasedLineNumber); Assert.Equal(4, functionMap[1].Bindings[0].SourcePosition.ZeroBasedColumnNumber); Assert.Equal(0, functionMap[1].StartSourcePosition.ZeroBasedLineNumber); Assert.Equal(0, functionMap[1].EndSourcePosition.ZeroBasedLineNumber); Assert.Equal(20, functionMap[1].StartSourcePosition.ZeroBasedColumnNumber); Assert.Equal(22, functionMap[1].EndSourcePosition.ZeroBasedColumnNumber); }
public bool Use(User target) { Logger.DebugFormat("warp: {0} from {1} ({2},{3}) to {4} ({5}, {6}", target.Name, SourceMap.Name, X, Y, DestinationMapName, DestinationX, DestinationY); switch (WarpType) { case WarpType.Map: Map map; if (SourceMap.World.MapCatalog.TryGetValue(DestinationMapName, out map)) { Thread.Sleep(250); target.Teleport(map.Id, DestinationX, DestinationY); return(true); } Logger.ErrorFormat("User {0} tried to warp to nonexistent map {1} from {2}: {3},{4}", target.Name, DestinationMapName, SourceMap.Name, X, Y); break; case WarpType.WorldMap: WorldMap wmap; if (SourceMap.World.WorldMaps.TryGetValue(DestinationMapName, out wmap)) { SourceMap.Remove(target); target.SendWorldMap(wmap); SourceMap.World.Maps[Hybrasyl.Constants.LAG_MAP].Insert(target, 5, 5, false); return(true); } Logger.ErrorFormat("User {0} tried to warp to nonexistent worldmap {1} from {2}: {3},{4}", target.Name, DestinationMapName, SourceMap.Name, X, Y); break; } return(false); }
public void StackFrameDeminierDeminifyStackFrame_SourceMapGeneratedMappingEntryNull_NoMatchingMapingInSourceMapError() { // Arrange string filePath = "foo"; FunctionMapEntry wrapingFunctionMapEntry = CreateFunctionMapEntry(deminifiedMethodName: "DeminifiedFoo"); StackFrame stackFrame = new StackFrame { FilePath = filePath }; IFunctionMapStore functionMapStore = MockRepository.GenerateStub <IFunctionMapStore>(); functionMapStore.Stub(c => c.GetFunctionMapForSourceCode(filePath)) .Return(new List <FunctionMapEntry>()); ISourceMapStore sourceMapStore = MockRepository.GenerateStub <ISourceMapStore>(); SourceMap sourceMap = CreateSourceMap(parsedMappings: new List <MappingEntry>()); sourceMapStore.Stub(c => c.GetSourceMapForUrl(Arg <string> .Is.Anything)).Return(sourceMap); IFunctionMapConsumer functionMapConsumer = MockRepository.GenerateStub <IFunctionMapConsumer>(); functionMapConsumer.Stub(c => c.GetWrappingFunctionForSourceLocation(Arg <SourcePosition> .Is.Anything, Arg <List <FunctionMapEntry> > .Is.Anything)) .Return(wrapingFunctionMapEntry); IStackFrameDeminifier stackFrameDeminifier = GetStackFrameDeminifierWithMockDependencies(sourceMapStore: sourceMapStore, functionMapStore: functionMapStore, functionMapConsumer: functionMapConsumer); // Act StackFrameDeminificationResult stackFrameDeminification = stackFrameDeminifier.DeminifyStackFrame(stackFrame, callerSymbolName: null); // Assert Assert.Equal(DeminificationError.NoMatchingMapingInSourceMap, stackFrameDeminification.DeminificationError); Assert.Equal(wrapingFunctionMapEntry.DeminifiedMethodName, stackFrameDeminification.DeminifiedStackFrame.MethodName); Assert.Equal(SourcePosition.NotFound, stackFrameDeminification.DeminifiedStackFrame.SourcePosition); Assert.Null(stackFrameDeminification.DeminifiedStackFrame.FilePath); }
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.NotNull(linesOnlyMap); Assert.Equal(1, linesOnlyMap.Sources.Count); Assert.Equal(1, linesOnlyMap.SourcesContent.Count); Assert.Equal(1, linesOnlyMap.ParsedMappings.Count); Assert.Equal(1, linesOnlyMap.ParsedMappings[0].GeneratedSourcePosition.ZeroBasedLineNumber); Assert.Equal(0, linesOnlyMap.ParsedMappings[0].GeneratedSourcePosition.ZeroBasedColumnNumber); Assert.Equal(2, linesOnlyMap.ParsedMappings[0].OriginalSourcePosition.ZeroBasedLineNumber); Assert.Equal(0, linesOnlyMap.ParsedMappings[0].OriginalSourcePosition.ZeroBasedColumnNumber); }
public void TestMappingLine() { var map = new SourceMap(new StringReader(_sample)); var testCases = new[] { new { Line = 0, Name = "Greeter", Filename = "test.ts" }, new { Line = 1, Name = "Greeter", Filename = "test.ts" }, new { Line = 1, Name = "Greeter.constructor", Filename = "test.ts" }, new { Line = 1, Name = "Greeter.constructor", Filename = "test.ts" }, new { Line = 2, Name = "Greeter", Filename = "test.ts" }, new { Line = 3, Name = "Greeter.greet", Filename = "test.ts" }, new { Line = 4, Name = "Greeter.greet", Filename = "test.ts" }, new { Line = 5, Name = "Greeter", Filename = "test.ts" }, new { Line = 5, Name = "Greeter", Filename = "test.ts" }, new { Line = 5, Name = "Greeter", Filename = "test.ts" }, new { Line = -1, Name = "", Filename = "" }, }; for (int i = 0; i < testCases.Length; i++) { SourceMapInfo mapping; if (map.TryMapLine(i, out mapping)) { Assert.AreEqual(testCases[i].Filename, mapping.FileName); Assert.AreEqual(testCases[i].Name, mapping.Name); Assert.AreEqual(testCases[i].Line, mapping.Line); } else { Assert.AreEqual(-1, testCases[i].Line); } } }
public void TestMappingLineAndColumn() { var map = new SourceMap(new StringReader(_sample)); var testCases = new[] { new { InLine = 0, InColumn = 0, ExpectedLine = 0, ExpectedColumn = 0, Name = "Greeter", Filename = "test.ts" }, new { InLine = 1, InColumn = 0, ExpectedLine = 1, ExpectedColumn = 4, Name = "Greeter", Filename = "test.ts" }, new { InLine = 1, InColumn = 4, ExpectedLine = 1, ExpectedColumn = 4, Name = "Greeter", Filename = "test.ts" }, new { InLine = 2, InColumn = 0, ExpectedLine = 1, ExpectedColumn = 16, Name = "Greeter.constructor", Filename = "test.ts" }, new { InLine = 2, InColumn = 4, ExpectedLine = 1, ExpectedColumn = 16, Name = "Greeter.constructor", Filename = "test.ts" }, new { InLine = 2, InColumn = 8, ExpectedLine = 1, ExpectedColumn = 16, Name = "Greeter.constructor", Filename = "test.ts" }, new { InLine = 3, InColumn = 0, ExpectedLine = 1, ExpectedColumn = 39, Name = "Greeter.constructor", Filename = "test.ts" }, new { InLine = 4, InColumn = 0, ExpectedLine = 2, ExpectedColumn = 4, Name = "Greeter", Filename = "test.ts" }, new { InLine = 5, InColumn = 0, ExpectedLine = 3, ExpectedColumn = 8, Name = "Greeter.greet", Filename = "test.ts" }, new { InLine = 5, InColumn = 4, ExpectedLine = 3, ExpectedColumn = 8, Name = "Greeter.greet", Filename = "test.ts" }, new { InLine = 5, InColumn = 32, ExpectedLine = 3, ExpectedColumn = 29, Name = "Greeter.greet", Filename = "test.ts" }, new { InLine = 6, InColumn = 0, ExpectedLine = 4, ExpectedColumn = 4, Name = "Greeter.greet", Filename = "test.ts" }, new { InLine = 7, InColumn = 0, ExpectedLine = 5, ExpectedColumn = 0, Name = "Greeter", Filename = "test.ts" }, new { InLine = 8, InColumn = 0, ExpectedLine = 5, ExpectedColumn = 0, Name = "Greeter", Filename = "test.ts" }, new { InLine = 9, InColumn = 0, ExpectedLine = 5, ExpectedColumn = 1, Name = "Greeter", Filename = "test.ts" }, new { InLine = 10, InColumn = 0, ExpectedLine = 5, ExpectedColumn = 0, Name = "", Filename = "" }, }; for (int i = 0; i < testCases.Length; i++) { Console.WriteLine("{0} {1}", testCases[i].InLine, testCases[i].InColumn); SourceMapInfo mapping; if (map.TryMapPoint(testCases[i].InLine, testCases[i].InColumn, out mapping)) { Assert.AreEqual(testCases[i].Filename, mapping.FileName); Assert.AreEqual(testCases[i].Name, mapping.Name); Assert.AreEqual(testCases[i].ExpectedLine, mapping.Line); Assert.AreEqual(testCases[i].ExpectedColumn, mapping.Column); } } }
public void MappingLine() { var map = new SourceMap(new StringReader(_sample)); var testCases = new[] { new { Line = 0, Name = "Greeter", Filename = "test.ts" }, new { Line = 1, Name = "Greeter", Filename = "test.ts" }, new { Line = 1, Name = "Greeter.constructor", Filename = "test.ts" }, new { Line = 1, Name = "Greeter.constructor", Filename = "test.ts" }, new { Line = 2, Name = "Greeter", Filename = "test.ts" }, new { Line = 3, Name = "Greeter.greet", Filename = "test.ts" }, new { Line = 4, Name = "Greeter.greet", Filename = "test.ts" }, new { Line = 5, Name = "Greeter", Filename = "test.ts" }, new { Line = 5, Name = "Greeter", Filename = "test.ts" }, new { Line = 5, Name = "Greeter", Filename = "test.ts" }, new { Line = -1, Name = "", Filename = "" }, }; for (int i = 0; i < testCases.Length; i++) { SourceMapInfo mapping; if (map.TryMapLine(i, out mapping)) { Assert.AreEqual(testCases[i].Filename, mapping.FileName); Assert.AreEqual(testCases[i].Name, mapping.Name); Assert.AreEqual(testCases[i].Line, mapping.Line); } else { Assert.AreEqual(-1, testCases[i].Line); } } }
public static string ReTrace(SourceMap sourceMap, string stacktrace, string?sourceRoot = null) { var collection = new SourceMapCollection(); collection.Register(sourceMap); return(ReTrace(collection, stacktrace, sourceRoot)); }
public void GetMappingEntryForGeneratedSourcePosition_MatchingEntryInMappingList_ReturnMatchingEntry() { // Arrange var sourceMap = new SourceMap(); var matchingMappingEntry = new MappingEntry { GeneratedSourcePosition = new SourcePosition(8, 13) }; sourceMap.ParsedMappings = new List <MappingEntry> { new MappingEntry { GeneratedSourcePosition = new SourcePosition(0, 0) }, matchingMappingEntry }; var sourcePosition = new SourcePosition(8, 13); // Act var result = sourceMap.GetMappingEntryForGeneratedSourcePosition(sourcePosition); // Asset Assert.AreEqual(matchingMappingEntry, result); }
public void GetMappingEntryForGeneratedSourcePosition_NoExactMatchHasSimilarOnSameLine_ReturnSimilarEntry() { // Arrange var sourceMap = new SourceMap(); var matchingMappingEntry = new MappingEntry { GeneratedSourcePosition = new SourcePosition(10, 13) }; sourceMap.ParsedMappings = new List <MappingEntry> { new MappingEntry { GeneratedSourcePosition = new SourcePosition(0, 0) }, matchingMappingEntry }; var sourcePosition = new SourcePosition(10, 14); // Act var result = sourceMap.GetMappingEntryForGeneratedSourcePosition(sourcePosition); // Asset Assert.AreEqual(matchingMappingEntry, result); }
public void FlattenMap_MultipleOriginalLineToSameGeneratedLine_ReturnsFirstOriginalLine() { // 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"); SourcePosition generated2 = UnitTestUtils.generateSourcePosition(lineNumber: 1, colNumber: 3); SourcePosition original2 = UnitTestUtils.generateSourcePosition(lineNumber: 3, colNumber: 5); MappingEntry mappingEntry2 = UnitTestUtils.getSimpleEntry(generated2, original2, "sourceOne.js"); SourceMap map = new SourceMap { File = "generated.js", Sources = new List <string> { "sourceOne.js" }, ParsedMappings = new List <MappingEntry> { mappingEntry, mappingEntry2 } }; // Act SourceMap linesOnlyMap = SourceMapTransformer.Flatten(map); // Assert Assert.IsNotNull(linesOnlyMap); Assert.AreEqual(1, linesOnlyMap.Sources.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); }
private SourceMap GetSimpleSourceMap() { SourceMap input = new SourceMap() { File = "CommonIntl", Names = new List <string>() { "CommonStrings", "afrikaans" }, Sources = new List <string>() { "input/CommonIntl.js" }, Version = 3, }; input.ParsedMappings = new List <MappingEntry>() { new MappingEntry { GeneratedSourcePosition = new SourcePosition() { ZeroBasedLineNumber = 0, ZeroBasedColumnNumber = 0 }, OriginalFileName = input.Sources[0], OriginalName = input.Names[0], OriginalSourcePosition = new SourcePosition() { ZeroBasedLineNumber = 1, ZeroBasedColumnNumber = 0 }, }, new MappingEntry { GeneratedSourcePosition = new SourcePosition() { ZeroBasedLineNumber = 0, ZeroBasedColumnNumber = 13 }, OriginalFileName = input.Sources[0], OriginalSourcePosition = new SourcePosition() { ZeroBasedLineNumber = 1, ZeroBasedColumnNumber = 0 }, }, new MappingEntry { GeneratedSourcePosition = new SourcePosition() { ZeroBasedLineNumber = 0, ZeroBasedColumnNumber = 14 }, OriginalFileName = input.Sources[0], OriginalSourcePosition = new SourcePosition() { ZeroBasedLineNumber = 1, ZeroBasedColumnNumber = 14 }, }, }; return(input); }
/// <summary> /// Initializes a new instance of the class. /// </summary> /// <param name="parent">The parent emitter.</param> /// <param name="outer">The outer code section.</param> /// <param name="sourceMap">The current source map.</param> private Emitter(Emitter parent, CodeSection outer, SourceMap sourceMap) { this.data = parent.data; this.code = parent.code; this.local = new CodeSection(); this.sourceMap = sourceMap; outer.Add(this.local); }
public void TestInvalidJson() { try { var map = new SourceMap(new StringReader("{'test.js\\'}")); Assert.Fail("Argument exception not raised"); } catch (ArgumentException) { } }
/// <summary> /// Initializes a new instance of the class. /// </summary> /// <param name="source">The source code, split into lines.</param> public Emitter(string[] source) { this.data = new DataSection(); this.code = new CodeSection(); this.local = new CodeSection(); this.sourceMap = new SourceMap(source); this.code.Add(this.local); }
/// <summary> /// Initializes a new instance of the class. /// </summary> /// <param name="opcode">The opcode.</param> /// <param name="param">The param.</param> /// <param name="value">The value.</param> /// <param name="target">The target element, if any.</param> /// <param name="sourceMap">The source map.</param> public CodeEmitter(Opcode opcode, int param, int value, CodeElement target, SourceMap sourceMap) { this.opcode = opcode; this.param = param; this.value = value; this.target = target; this.sourceMap = sourceMap; }
public WarpedMapTileSource(UnwarpedMapTileSource unwarpedTileSource, CachePackage cachePackage, SourceMap sourceMap) { this.unwarpedMapTileSource = unwarpedTileSource; this.cachePackage = cachePackage; this.coordinateSystem = new MercatorCoordinateSystem(); if (sourceMap.registration.GetAssociationList().Count < sourceMap.registration.warpStyle.getCorrespondencesRequired()) { throw new InsufficientCorrespondencesException(); } this.imageTransformer = sourceMap.registration.warpStyle.getImageTransformer(sourceMap.registration, RenderQualityStyle.theStyle.warpInterpolationMode); }
private JavaScriptSourceMapInfo TryGetMapInfo(string filename) { JavaScriptSourceMapInfo mapInfo; if (!_originalFileToSourceMap.TryGetValue(filename, out mapInfo)) { if (File.Exists(filename)) { string[] contents = File.ReadAllLines(filename); const string marker = "# sourceMappingURL="; int markerStart; string markerLine = contents.Reverse().FirstOrDefault(x => x.IndexOf(marker, StringComparison.Ordinal) != -1); if (markerLine != null && (markerStart = markerLine.IndexOf(marker, StringComparison.Ordinal)) != -1) { string sourceMapFilename = markerLine.Substring(markerStart + marker.Length).Trim(); try { if (!File.Exists(sourceMapFilename)) { sourceMapFilename = Path.Combine(Path.GetDirectoryName(filename) ?? string.Empty, Path.GetFileName(sourceMapFilename)); } } catch (ArgumentException) { } catch (PathTooLongException) { } try { if (File.Exists(sourceMapFilename)) { using (StreamReader reader = new StreamReader(sourceMapFilename)) { var sourceMap = new SourceMap(reader); _originalFileToSourceMap[filename] = mapInfo = new JavaScriptSourceMapInfo(sourceMap, contents); // clear all of our cached _generatedFileToSourceMap files... foreach (var cachedInvalid in _generatedFileToSourceMap.Where(x => x.Value == null).Select(x => x.Key).ToArray()) { _generatedFileToSourceMap.Remove(cachedInvalid); } } } } catch (ArgumentException) { } catch (PathTooLongException) { } catch (NotSupportedException) { } catch (InvalidOperationException) { } } } } return mapInfo; }
public void Sources() { var map = new SourceMap(new StringReader("{version:3, sources:['test.ts']}")); Assert.AreEqual(map.Sources[0], "test.ts"); map = new SourceMap(new StringReader("{version:3, sources:['test.ts'], sourceRoot:'root_path\\\\'}")); Assert.AreEqual(map.Sources[0], "root_path\\test.ts"); }
internal JavaScriptSourceMapInfo(SourceMap map, string[] lines) { Map = map; Lines = lines; }
public UnwarpedMapTileSource(CachePackage cachePackage, IFuture localDocumentFuture, SourceMap sourceMap) { this.cachePackage = cachePackage; this.localDocumentFuture = localDocumentFuture; this.sourceMap = sourceMap; }
internal static FunctionInformation MaybeMap(FunctionInformation funcInfo, Dictionary<string, SourceMap> sourceMaps) { if (funcInfo.Filename != null && funcInfo.Filename.IndexOfAny(InvalidPathChars) == -1 && File.Exists(funcInfo.Filename) && File.Exists(funcInfo.Filename + ".map") && funcInfo.LineNumber != null) { SourceMap map = null; if (sourceMaps == null || !sourceMaps.TryGetValue(funcInfo.Filename, out map)) { try { using (StreamReader reader = new StreamReader(funcInfo.Filename + ".map")) { map = new SourceMap(reader); } } catch (InvalidOperationException) { } catch (FileNotFoundException) { } catch (DirectoryNotFoundException) { } catch (IOException) { } if (sourceMaps != null && map != null) { sourceMaps[funcInfo.Filename] = map; } } SourceMapInfo mapping; // We explicitly don't convert our 1 based line numbers into 0 based // line numbers here. V8 is giving us the starting line of the function, // and TypeScript doesn't give the right name for the declaring name. // But TypeScript also happens to always emit a newline after the { // for a function definition, and we're always mapping line numbers from // function definitions, so mapping line + 1 happens to work out for // the time being. if (map != null && map.TryMapLine(funcInfo.LineNumber.Value, out mapping)) { string filename = mapping.FileName; if (filename != null && !Path.IsPathRooted(filename)) { filename = Path.Combine(Path.GetDirectoryName(funcInfo.Filename), filename); } return new FunctionInformation( funcInfo.Namespace, mapping.Name ?? funcInfo.Function, mapping.Line + 1, filename ?? funcInfo.Filename, funcInfo.IsRecompilation ); } } return funcInfo; }
public ReverseSourceMap(SourceMap mapping, string javaScriptFile) { Mapping = mapping; JavaScriptFile = javaScriptFile; }
public void MappingLineAndColumn() { var map = new SourceMap(new StringReader(_sample)); var testCases = new[] { new { InLine = 0, InColumn = 0, ExpectedLine = 0, ExpectedColumn = 0, Name = "Greeter", Filename = "test.ts" }, new { InLine = 1, InColumn = 0, ExpectedLine = 1, ExpectedColumn = 4, Name = "Greeter", Filename = "test.ts" }, new { InLine = 1, InColumn = 4, ExpectedLine = 1, ExpectedColumn = 4, Name = "Greeter", Filename = "test.ts" }, new { InLine = 2, InColumn = 0, ExpectedLine = 1, ExpectedColumn = 16, Name = "Greeter.constructor", Filename = "test.ts" }, new { InLine = 2, InColumn = 4, ExpectedLine = 1, ExpectedColumn = 16, Name = "Greeter.constructor", Filename = "test.ts" }, new { InLine = 2, InColumn = 8, ExpectedLine = 1, ExpectedColumn = 16, Name = "Greeter.constructor", Filename = "test.ts" }, new { InLine = 3, InColumn = 0, ExpectedLine = 1, ExpectedColumn = 39, Name = "Greeter.constructor", Filename = "test.ts" }, new { InLine = 4, InColumn = 0, ExpectedLine = 2, ExpectedColumn = 4, Name = "Greeter", Filename = "test.ts" }, new { InLine = 5, InColumn = 0, ExpectedLine = 3, ExpectedColumn = 8, Name = "Greeter.greet", Filename = "test.ts" }, new { InLine = 5, InColumn = 4, ExpectedLine = 3, ExpectedColumn = 8, Name = "Greeter.greet", Filename = "test.ts" }, new { InLine = 5, InColumn = 32, ExpectedLine = 3, ExpectedColumn = 29, Name = "Greeter.greet", Filename = "test.ts" }, new { InLine = 6, InColumn = 0, ExpectedLine = 4, ExpectedColumn = 4, Name = "Greeter.greet", Filename = "test.ts" }, new { InLine = 7, InColumn = 0, ExpectedLine = 5, ExpectedColumn = 0, Name = "Greeter", Filename = "test.ts" }, new { InLine = 8, InColumn = 0, ExpectedLine = 5, ExpectedColumn = 0, Name = "Greeter", Filename = "test.ts" }, new { InLine = 9, InColumn = 0, ExpectedLine = 5, ExpectedColumn = 1, Name = "Greeter", Filename = "test.ts" }, new { InLine = 10, InColumn = 0, ExpectedLine = 5, ExpectedColumn = 0, Name = "", Filename = "" }, }; for (int i = 0; i < testCases.Length; i++) { Console.WriteLine("{0} {1}", testCases[i].InLine, testCases[i].InColumn); SourceMapInfo mapping; if (map.TryMapPoint(testCases[i].InLine, testCases[i].InColumn, out mapping)) { Assert.AreEqual(testCases[i].Filename, mapping.FileName); Assert.AreEqual(testCases[i].Name, mapping.Name); Assert.AreEqual(testCases[i].ExpectedLine, mapping.Line); Assert.AreEqual(testCases[i].ExpectedColumn, mapping.Column); } } }
public void Names() { var map = new SourceMap(new StringReader("{version:3, names:['foo']}")); Assert.AreEqual(map.Names[0], "foo"); }
public void File() { var map = new SourceMap(new StringReader("{version:3, file:'test.js'}")); Assert.AreEqual(map.File, "test.js"); }
public void InvalidJson() { try { var map = new SourceMap(new StringReader("{'test.js\\'}")); Assert.Fail("Argument exception not raised"); } catch (ArgumentException) { } }