.NET Standard 2.0 library for parsing and using SourceMaps
SourceMaps library that handles parsing of the sourcemap and has methods for getting the original position, name and file for a generated position.
SourceMaps.StackTraces is an additional package that can be used to parse JavaScript stack traces and map them with the source map to the original files.
To parse a sourcemap
using SourceMaps;
var sourceMap = SourceMapParser.Parse(sourceMapAsString);
To get the original mapping for a given generated position, use
var mapping = sourceMap.OriginalPositionFor(generatedLineNumber: 1, generatedColumnNumber: 1);
mapping.OriginalName; // original token name
mapping.OriginalFileName; // original file name
mapping.OriginalSourcePosition.LineNumber; // original line number
mapping.OriginalSourcePosition.ColumnNumber; // original column number
To get the original stack trace using the source maps
StackTraceParser.ReTrace(
sourceMap,
stackTrace: @"ReferenceError: ""getExceptionProps"" is undefined
at eval code (eval code:1:1)
at foo (http:https://path/to/file.js:58:17)
at bar (http:https://path/to/file.js:109:1)",
sourceRoot: "https://localhost:5001/js/");