ts-babel-node icon indicating copy to clipboard operation
ts-babel-node copied to clipboard

Source maps not aligned

Open dan-j opened this issue 8 years ago • 0 comments

Source maps when compiled through ts-babel-node aren't correct. It's an issue with babel (see https://github.com/babel/babel/issues/5408), however as a workaround, there's a good module on merging source maps, merge-source-map.

I've been stepping through the module with a debugger and saving the maps, and using https://sokra.github.io/source-map-visualization to visualise them. Using the package mentioned above gives much better results.

Is this something you'd accept a pull request on?

Essentially you just don't pass the inputSourceMap to babelOpts:

function compile(base, code, filename) {
  var sourcemap = convertSourceMap.fromSource(code).toObject();
  code = convertSourceMap.removeMapFileComments(code);

  var babelOutput = babel.transform(code, getBabelOpts(filename, /* sourcemap */ null));

  // babelOutput has a bunch of undocumented stuff on it. Just grab what we need to save memory
  var mergedMap = mergeSourceMap(sourcemap, babelOutput.map);
  outputs[filename] = { code: babelOutput.code, map: mergedMap };

  return base.call(this, babelOutput.code, filename);
}

and set the baseBabelOpts as so:

var baseBabelOpts = { ast: false, sourceMaps: true };

dan-j avatar Jul 21 '17 07:07 dan-j