File tree Expand file tree Collapse file tree 2 files changed +49
-0
lines changed
Expand file tree Collapse file tree 2 files changed +49
-0
lines changed Original file line number Diff line number Diff line change 1+ # SourceMaps
2+
3+ .NET Standard 2.0 library for parsing and using SourceMaps
4+
5+ ## Packages
6+ ### SourceMaps
7+ SourceMaps library that handles parsing of the sourcemap and has methods for getting the original position,
8+ name and file for a generated position.
9+
10+ ### SourceMaps.StackTraces
11+ SourceMaps.StackTraces is an additional package that can be used to parse JavaScript stack traces
12+ and map them with the source map to the original files.
13+
14+ ## Usage
15+ ### SourceMaps
16+ To parse a sourcemap located at ` ./app.js.map `
17+
18+ ``` csharp
19+ using SourceMaps
20+ // ...
21+
22+ var map = File .ReadAllText ("./app .js .map ");
23+ var sourceMap = SourceMapParser .Parse (map );
24+ ```
25+
26+ To get the original mapping for a generated position, use
27+
28+ ``` csharp
29+ var mapping = sourceMap .OriginalPositionFor (new SourcePosition (/* generatedLineNumber */ 1 , /* generatedColumnNumber */ 1 ));
30+
31+ mapping .OriginalName ; // original token name
32+ mapping .OriginalFileName ; // original file name
33+ mapping .OriginalSourcePosition .LineNumber ; // original line number
34+ mapping .OriginalSourcePosition .ColumnNumber ; // original column number
35+ ```
36+
37+ ### SourceMaps.StackTraces
38+ To get the original stack trace using the source maps
39+
40+ ``` csharp
41+ StackTraceParser .ReTrace (sourceMap , " /* JavaScript StackTrace */" , /* optional source root */ " https://localhost:5001/js/" )
42+ ```
Original file line number Diff line number Diff line change @@ -5,6 +5,13 @@ namespace SourceMaps.StackTraces
55{
66 public static class StackTraceParser
77 {
8+ public static string ReTrace ( SourceMap sourceMap , string stacktrace , string sourceRoot = null )
9+ {
10+ var collection = new SourceMapCollection ( ) ;
11+ collection . Register ( sourceMap ) ;
12+ return ReTrace ( collection , stacktrace , sourceRoot ) ;
13+ }
14+
815 public static string ReTrace ( SourceMapCollection sourceMaps , string stacktrace , string sourceRoot = null )
916 {
1017 var trace = Parse ( stacktrace ) ;
You can’t perform that action at this time.
0 commit comments