\href{https://npmjs.org/package/merge-source-map}{\texttt{ }} \href{https://npmjs.org/package/merge-source-map}{\texttt{ }} \href{https://travis-ci.org/keik/merge-source-map}{\texttt{ }} \href{https://coveralls.io/github/keik/merge-source-map}{\texttt{ }}

Merge old source map and new source map in multi-\/transform flow\hypertarget{md_sfcode_node_modules_merge_source_map_README_autotoc_md17118}{}\doxysection{API}\label{md_sfcode_node_modules_merge_source_map_README_autotoc_md17118}

\begin{DoxyCode}{0}
\DoxyCodeLine{var merge = require('merge-\/source-\/map') }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_merge_source_map_README_autotoc_md17119}{}\doxysubsection{$<$tt$>$merge(old\+Map, new\+Map)$<$/tt$>$}\label{md_sfcode_node_modules_merge_source_map_README_autotoc_md17119}
Merge old source map and new source map and return merged. If old or new source map value is falsy, return another one as it is.


\begin{DoxyDescription}
\item[{\ttfamily old\+Map} \+: {\ttfamily object$\vert$undefined}  ]old source map object 


\item[{\ttfamily newmap} \+: {\ttfamily object$\vert$undefined}  ]new source map object  
\end{DoxyDescription}\hypertarget{md_sfcode_node_modules_merge_source_map_README_autotoc_md17120}{}\doxysection{Example}\label{md_sfcode_node_modules_merge_source_map_README_autotoc_md17120}

\begin{DoxyCode}{0}
\DoxyCodeLine{var esprima    = require('esprima'),}
\DoxyCodeLine{    estraverse = require('estraverse'),}
\DoxyCodeLine{    escodegen  = require('escodegen'),}
\DoxyCodeLine{    convert    = require('convert-\/source-\/map'),}
\DoxyCodeLine{    merge      = require('merge-\/source-\/map')}
\DoxyCodeLine{}
\DoxyCodeLine{const CODE = 'a = 1',}
\DoxyCodeLine{      FILEPATH = 'a.js'}
\DoxyCodeLine{}
\DoxyCodeLine{// create AST of original code}
\DoxyCodeLine{var ast = esprima.parse(CODE, \{sourceType: 'module', loc: true\})}
\DoxyCodeLine{}
\DoxyCodeLine{// transform AST of original code}
\DoxyCodeLine{estraverse.replace(ast, \{}
\DoxyCodeLine{  enter: function(node, parent) \{ /* change AST */ \},}
\DoxyCodeLine{  leave: function(node, parent) \{ /* change AST */ \}}
\DoxyCodeLine{\})}
\DoxyCodeLine{}
\DoxyCodeLine{// generate code and source map from transformed AST}
\DoxyCodeLine{var gen = escodegen.generate(ast, \{}
\DoxyCodeLine{  sourceMap: FILEPATH,}
\DoxyCodeLine{  sourceMapWithCode: true,}
\DoxyCodeLine{  sourceContent: CODE}
\DoxyCodeLine{\})}
\DoxyCodeLine{}
\DoxyCodeLine{// merge old source map and new source map}
\DoxyCodeLine{var oldMap = convert.fromSource(CODE) \&\& convert.fromSource(CODE).toObject(),}
\DoxyCodeLine{    newMap = JSON.parse(gen.map.toString()),}
\DoxyCodeLine{    mergedMap = merge(oldMap, newMap),}
\DoxyCodeLine{    mapComment = convert.fromObject(mergedMap).toComment()}
\DoxyCodeLine{}
\DoxyCodeLine{// attach merge source map to transformed code}
\DoxyCodeLine{var transformed = gen.code + '\(\backslash\)n' + mapComment}
\DoxyCodeLine{}
\DoxyCodeLine{console.log(transformed); }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_merge_source_map_README_autotoc_md17121}{}\doxysection{Test}\label{md_sfcode_node_modules_merge_source_map_README_autotoc_md17121}

\begin{DoxyCode}{0}
\DoxyCodeLine{\% npm install}
\DoxyCodeLine{\% npm test }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_merge_source_map_README_autotoc_md17122}{}\doxysection{License}\label{md_sfcode_node_modules_merge_source_map_README_autotoc_md17122}
MIT (c) keik 