JsSourceMapper Class

Maps the positions of generated scripts (bundles, the output of a compiler) to their original sources with source maps: the location of a JsException and the stack traces. It does not change the execution of the scripts: the errors and the stack property that the scripts see keep the generated positions.

public sealed class JsSourceMapper

Remarks

The source map of a script is found by the URL of the script (the URL given to JsRealm.Execute or to JsRealm.ParseModule): added with JsSourceMapper.Add, or returned by the resolver of the constructor, which is called once per URL. A position whose script has no source map, or that no mapping of the source map contains, is not changed. The methods can be called from any thread.

Constructors

NameDescription
JsSourceMapper()Initializes a new instance of the JsSourceMapper class whose source maps are added with JsSourceMapper.Add.
JsSourceMapper(Func<string, JsSourceMap?>)Initializes a new instance of the JsSourceMapper class that gets the source maps from a resolver.

JsSourceMapper overloads

JsSourceMapper()

JsSourceMapper.cs

Initializes a new instance of the JsSourceMapper class whose source maps are added with JsSourceMapper.Add.

public JsSourceMapper()

JsSourceMapper(Func<string, JsSourceMap?>)

JsSourceMapper.cs

Initializes a new instance of the JsSourceMapper class that gets the source maps from a resolver.

public JsSourceMapper(Func<string, JsSourceMap?> resolver)
Parameters
resolver Func<string, JsSourceMap?>
Returns the source map of the script of a URL, or null when it has none (e.g. it reads the file of the //# sourceMappingURL= comment of the script). It is called once per URL; an exception it throws goes to the caller of the method that maps the position, and the resolver is called again for the next position of the URL.

Methods

NameDescription
Add(string, JsSourceMap)Sets the source map of the script of a URL.
MapLocation(JsSourceLocation)Gets the original position of a position of a generated script, or the position itself when it cannot be mapped.
MapLocation(JsSourceLocation?)Gets the original position of a position of a generated script (e.g. JsException.Location), or the position itself when it cannot be mapped.
MapStackTrace(string)Replaces the positions of the frames of a stack trace (the stack property of an error, or the result of JsEngine.CaptureStackTrace) by their original positions. The lines that are not frames, and the frames that cannot be mapped, are not changed.

Add(string, JsSourceMap)

JsSourceMapper.cs

Sets the source map of the script of a URL.

public void Add(string url, JsSourceMap sourceMap)

Parameters

url string
The URL of the generated script.
sourceMap JsSourceMap
The source map of the script.

MapLocation overloads

MapLocation(JsSourceLocation)

JsSourceMapper.cs

Gets the original position of a position of a generated script, or the position itself when it cannot be mapped.

public JsSourceLocation MapLocation(JsSourceLocation location)
Parameters
location JsSourceLocation
Returns

JsSourceLocation

MapLocation(JsSourceLocation?)

JsSourceMapper.cs

Gets the original position of a position of a generated script (e.g. JsException.Location), or the position itself when it cannot be mapped.

public JsSourceLocation? MapLocation(JsSourceLocation? location)
Parameters
location JsSourceLocation?
Returns

JsSourceLocation?

MapStackTrace(string)

JsSourceMapper.cs

Replaces the positions of the frames of a stack trace (the stack property of an error, or the result of JsEngine.CaptureStackTrace) by their original positions. The lines that are not frames, and the frames that cannot be mapped, are not changed.

public string MapStackTrace(string stackTrace)

Parameters

stackTrace string
The stack trace: lines such as at check (bundle.js:2:24) or at bundle.js:5:1.

Returns

string