/// <summary> /// Maps a location in the generated code into a location in the source code. /// </summary> internal bool TryMapPoint(int lineNo, int columnNo, out SourceMapInfo res) { if (lineNo < this._lines.Length) { var line = this._lines[lineNo]; for (var i = line.Segments.Length - 1; i >= 0; i--) { if (line.Segments[i].GeneratedColumn <= columnNo) { // we map to this column res = new SourceMapInfo( line.Segments[i].OriginalLine, line.Segments[i].OriginalColumn, line.Segments[i].SourceIndex < this.Sources.Count ? this.Sources[line.Segments[i].SourceIndex] : null, line.Segments[i].OriginalName < this.Names.Count ? this.Names[line.Segments[i].OriginalName] : null ); return(true); } } if (line.Segments.Length > 0) { // we map to this column res = new SourceMapInfo( line.Segments[0].OriginalLine, line.Segments[0].OriginalColumn, line.Segments[0].SourceIndex < this.Sources.Count ? this.Sources[line.Segments[0].SourceIndex] : null, line.Segments[0].OriginalName < this.Names.Count ? this.Names[line.Segments[0].OriginalName] : null ); return(true); } } res = default(SourceMapInfo); return(false); }
/// <summary> /// Maps a location in the source code into the generated code. /// </summary> internal bool TryMapPointBack(int lineNo, int columnNo, out SourceMapInfo res) { int?firstBestLine = null, secondBestLine = null; for (var i = 0; i < this._lines.Length; i++) { var line = this._lines[i]; int?originalColumn = null; foreach (var segment in line.Segments) { if (segment.OriginalLine == lineNo) { if (segment.OriginalColumn <= columnNo) { originalColumn = segment.OriginalColumn; } else if (originalColumn != null) { res = new SourceMapInfo( i, columnNo - originalColumn.Value, this.File, null ); return(true); } else { // code like: // constructor(public greeting: string) { } // gets compiled into: // function Greeter(greeting) { // this.greeting = greeting; // } // If we're going to pick a line out of here we'd rather pick the // 2nd line where we're going to hit a breakpoint. if (firstBestLine == null) { firstBestLine = i; } else if (secondBestLine == null && firstBestLine.Value != i) { secondBestLine = i; } } } else if (segment.OriginalLine > lineNo && firstBestLine != null) { // not a perfect matching on column (e.g. requested 0, mapping starts at 4) res = new SourceMapInfo(secondBestLine ?? firstBestLine.Value, 0, this.File, null); return(true); } } } res = default(SourceMapInfo); return(false); }
/// <summary> /// Get the original file name to map to. /// </summary> /// <param name="javaScriptFileName">JavaScript compiled file.</param> /// <param name="line">Line number</param> /// <param name="column">Column number</param> internal string GetOriginalFileName(string javaScriptFileName, int?line, int?column) { string originalFileName = null; if (line != null && column != null) { SourceMapInfo tempMapping = this.MapToOriginal(javaScriptFileName, (int)line, (int)column); if (tempMapping != null) { originalFileName = tempMapping.FileName; } } return(originalFileName ?? this.MapToOriginal(javaScriptFileName)); }
/// <summary> /// Maps a location in the generated code into a location in the source code. /// </summary> internal bool TryMapLine(int lineNo, out SourceMapInfo res) { if (lineNo < this._lines.Length) { var line = this._lines[lineNo]; if (line.Segments.Length > 0) { res = new SourceMapInfo( line.Segments[0].OriginalLine, 0, this.Sources[line.Segments[0].SourceIndex], line.Segments[0].OriginalName < this.Names.Count ? this.Names[line.Segments[0].OriginalName] : null ); return(true); } } res = default(SourceMapInfo); return(false); }