Skip to content

Commit f8b87e1

Browse files
committed
Add readme
1 parent 0dd75c4 commit f8b87e1

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
```

SourceMaps.StackTraces/StackTraceParser.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff 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);

0 commit comments

Comments
 (0)