Encode/decode the {\ttfamily mappings} property of a \href{https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit}{\texttt{ sourcemap}}.\hypertarget{md_sfcode_node_modules_sourcemap_codec_README_autotoc_md28597}{}\doxysection{Why?}\label{md_sfcode_node_modules_sourcemap_codec_README_autotoc_md28597}
Sourcemaps are difficult to generate and manipulate, because the {\ttfamily mappings} property – the part that actually links the generated code back to the original source – is encoded using an obscure method called \href{https://en.wikipedia.org/wiki/Variable-length_quantity}{\texttt{ Variable-\/length quantity}}. On top of that, each segment in the mapping contains offsets rather than absolute indices, which means that you can\textquotesingle{}t look at a segment in isolation – you have to understand the whole sourcemap.

This package makes the process slightly easier.\hypertarget{md_sfcode_node_modules_sourcemap_codec_README_autotoc_md28598}{}\doxysection{Installation}\label{md_sfcode_node_modules_sourcemap_codec_README_autotoc_md28598}

\begin{DoxyCode}{0}
\DoxyCodeLine{npm install sourcemap-\/codec }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_sourcemap_codec_README_autotoc_md28599}{}\doxysection{Usage}\label{md_sfcode_node_modules_sourcemap_codec_README_autotoc_md28599}

\begin{DoxyCode}{0}
\DoxyCodeLine{import \{ encode, decode \} from 'sourcemap-\/codec';}
\DoxyCodeLine{}
\DoxyCodeLine{var decoded = decode( ';EAEEA,EAAE,EAAC,CAAE;ECQY,UACC' );}
\DoxyCodeLine{}
\DoxyCodeLine{assert.deepEqual( decoded, [}
\DoxyCodeLine{    // the first line (of the generated code) has no mappings,}
\DoxyCodeLine{    // as shown by the starting semi-\/colon (which separates lines)}
\DoxyCodeLine{    [],}
\DoxyCodeLine{}
\DoxyCodeLine{    // the second line contains four (comma-\/separated) segments}
\DoxyCodeLine{    [}
\DoxyCodeLine{        // segments are encoded as you'd expect:}
\DoxyCodeLine{        // [ generatedCodeColumn, sourceIndex, sourceCodeLine, sourceCodeColumn, nameIndex ]}
\DoxyCodeLine{}
\DoxyCodeLine{        // i.e. the first segment begins at column 2, and maps back to the second column}
\DoxyCodeLine{        // of the second line (both zero-\/based) of the 0th source, and uses the 0th}
\DoxyCodeLine{        // name in the `map.names` array}
\DoxyCodeLine{        [ 2, 0, 2, 2, 0 ],}
\DoxyCodeLine{}
\DoxyCodeLine{        // the remaining segments are 4-\/length rather than 5-\/length,}
\DoxyCodeLine{        // because they don't map a name}
\DoxyCodeLine{        [ 4, 0, 2, 4 ],}
\DoxyCodeLine{        [ 6, 0, 2, 5 ],}
\DoxyCodeLine{        [ 7, 0, 2, 7 ]}
\DoxyCodeLine{    ],}
\DoxyCodeLine{}
\DoxyCodeLine{    // the final line contains two segments}
\DoxyCodeLine{    [}
\DoxyCodeLine{        [ 2, 1, 10, 19 ],}
\DoxyCodeLine{        [ 12, 1, 11, 20 ]}
\DoxyCodeLine{    ]}
\DoxyCodeLine{]);}
\DoxyCodeLine{}
\DoxyCodeLine{var encoded = encode( decoded );}
\DoxyCodeLine{assert.equal( encoded, ';EAEEA,EAAE,EAAC,CAAE;ECQY,UACC' ); }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_sourcemap_codec_README_autotoc_md28600}{}\doxysection{License}\label{md_sfcode_node_modules_sourcemap_codec_README_autotoc_md28600}
MIT 