Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

sourcemap-codec

Rich-Harris26.8mMITdeprecated1.4.8TypeScript support: included

Please use @jridgewell/sourcemap-codec instead

Encode/decode sourcemap mappings

sourcemap, vlq

readme

sourcemap-codec

Encode/decode the mappings property of a sourcemap.

Why?

Sourcemaps are difficult to generate and manipulate, because the mappings property – the part that actually links the generated code back to the original source – is encoded using an obscure method called Variable-length quantity. On top of that, each segment in the mapping contains offsets rather than absolute indices, which means that you can't look at a segment in isolation – you have to understand the whole sourcemap.

This package makes the process slightly easier.

Installation

npm install sourcemap-codec

Usage

import { encode, decode } from 'sourcemap-codec';

var decoded = decode( ';EAEEA,EAAE,EAAC,CAAE;ECQY,UACC' );

assert.deepEqual( decoded, [
    // the first line (of the generated code) has no mappings,
    // as shown by the starting semi-colon (which separates lines)
    [],

    // the second line contains four (comma-separated) segments
    [
        // segments are encoded as you'd expect:
        // [ generatedCodeColumn, sourceIndex, sourceCodeLine, sourceCodeColumn, nameIndex ]

        // i.e. the first segment begins at column 2, and maps back to the second column
        // of the second line (both zero-based) of the 0th source, and uses the 0th
        // name in the `map.names` array
        [ 2, 0, 2, 2, 0 ],

        // the remaining segments are 4-length rather than 5-length,
        // because they don't map a name
        [ 4, 0, 2, 4 ],
        [ 6, 0, 2, 5 ],
        [ 7, 0, 2, 7 ]
    ],

    // the final line contains two segments
    [
        [ 2, 1, 10, 19 ],
        [ 12, 1, 11, 20 ]
    ]
]);

var encoded = encode( decoded );
assert.equal( encoded, ';EAEEA,EAAE,EAAC,CAAE;ECQY,UACC' );

License

MIT

changelog

sourcemap-codec changelog

1.4.8

  • Performance boost (#80)

1.4.7

  • Include .map files in package (#73)

1.4.6

  • Use arrays instead of typed arrays (#79)

1.4.5

  • Handle overflow cases (#78)

1.4.4

  • Use Uint32Array, yikes (#77)

1.4.3

  • Use Uint16Array to prevent overflow (#75)

1.4.2

  • GO EVEN FASTER (#74)

1.4.1

  • GO FASTER (#71)

1.4.0

  • Add TypeScript declarations (#70)

1.3.1

  • Update build process, expose pkg.module

1.3.0

  • Update build process

1.2.1

  • Add dist files to npm package

1.2.0

  • Add ES6 build
  • Update dependencies
  • Add test coverage

1.1.0

  • Fix bug with lines containing single-character segments
  • Add tests

1.0.0

  • First release