spatie/sourcemaps-lookup

Fast, memory-efficient Source Map v3 lookup for PHP

Maintainers

Package info

github.com/spatie/sourcemaps-lookup

pkg:composer/spatie/sourcemaps-lookup

Fund package maintenance!

spatie

Statistics

Installs: 68

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

1.0.0 2026-04-22 14:53 UTC

This package is auto-updated.

Last update: 2026-04-27 15:24:27 UTC


README

Latest Version on Packagist Tests Total Downloads

spatie/sourcemaps-lookup resolves JavaScript stack frame positions against a Source Map v3 file. It returns the original source file, line, column, symbol name, and enclosing scope. The package is tuned for stack frame resolution (for example, symbolicating JavaScript errors using an uploaded source map), and is narrowly focused on the read path. It does not write, merge, or transform maps.

use Spatie\SourcemapsLookup\SourceMapLookup;

$map = SourceMapLookup::fromFile('bundle.js.map');

// Resolve a generated position to its original source location.
$position = $map->lookup(42, 17);
echo $position->sourceFileName;  // "src/app.tsx"
echo $position->sourceLine;      // 1-based
echo $position->sourceColumn;    // 0-based

// Resolve the enclosing source-language scope.
$scope = $map->scopeAt(42, 17);
echo $scope->name;               // "onClick"
echo $scope->parent?->name;      // "DeeplyNestedTrigger"

Resolving 20 stack frames against a 6 MB production source map takes around 3.8 ms and uses about 18 MiB of memory on an Apple M1 Pro. See the benchmarks page for the full picture.

Support us

We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.

Documentation

You'll find the full documentation on our website.

Installation

You can install the package via Composer:

composer require spatie/sourcemaps-lookup

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

Correctness test fixtures in tests/fixtures/axy/ are copied verbatim from axy/sourcemap under its MIT licence, and used as reference data for spec conformance.

License

The MIT License (MIT). Please see License File for more information.