🌜
🌞
sourcemap-codec

sourcemap-codec

v1.4.8

Encode/decode sourcemap mappings

npm install sourcemap-codec

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

General

License
MIT
Typescript Types
Built-in
Tree-shakeable
Yes

Popularity

GitHub Stargazers
58
Community Interest
76
Number of Forks
16

Maintenance

Commits
10/219/2201
Last Commit
Jan 16, 2020
Open Issues
5
Closed Issues
1
Open Pull Requests
2
Closed Pull Requests
57

Versions

Versions Released
10/219/2201
Latest Version Released
Jan 16, 2020
Current Tags
latest1.4.8

Contributors

Rich-Harris
Rich-Harris
Commits: 35
greenkeeperio-bot
greenkeeperio-bot
Commits: 13
MattiasBuelens
MattiasBuelens
Commits: 9
jridgewell
jridgewell
Commits: 4
mourner
mourner
Commits: 3
Havunen
Havunen
Commits: 2
DarthVanger
DarthVanger
Commits: 1
t2t2
t2t2
Commits: 1