@jridgewell/trace-mapping
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
@jridgewell/resolve-uri | 3.1.0 | 9.62 kB | MIT | prod | |
@jridgewell/sourcemap-codec | 1.4.14 | 8.19 kB | MIT | prod |
The @jridgewell/trace-mapping package serves as a powerful tool for developers working with JavaScript source maps. This package aids in tracing the original location in a source file from the line and column of an output file via a source map. For those already acquainted with the source-map
package's SourceMapConsumer
, they will find this package delivers similar functionalities like originalPositionFor
and generatedPositionFor
API without the necessity of WASM.
To utilize @jridgewell/trace-mapping, you first need to install the package via npm using the command npm install @jridgewell/trace-mapping
. Then, you can import the required functions from @jridgewell/trace-mapping in your script.
Here is an example of its usage:
import {
TraceMap,
originalPositionFor,
generatedPositionFor,
sourceContentFor,
} from '@jridgewell/trace-mapping';
const tracer = new TraceMap({
version: 3,
sources: ['input.js'],
sourcesContent: ['content of input.js'],
names: ['foo'],
mappings: 'KAyCIA',
});
// Lines start at line 1, columns at column 0.
const traced = originalPositionFor(tracer, { line: 1, column: 5 });
//...
You can also use it for sectioned sourcemaps by utilizing the AnyMap
helper:
import { AnyMap } from '@jridgewell/trace-mapping';
const sectioned = new AnyMap({
version: 3,
sections: [
// Your sections here...
],
});
const traced = originalPositionFor(sectioned, {
line: 2,
column: 0,
});
//...
The documentation for the @jridgewell/trace-mapping package isn't hosted on a dedicated site but is instead available directly on the package's GitHub page. Here you'll find detailed explanations of the package's functionalities, requirements, and usage examples.