Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Source maps not aligned #17

Open
dan-j opened this issue Jul 21, 2017 · 0 comments
Open

Source maps not aligned #17

dan-j opened this issue Jul 21, 2017 · 0 comments

Comments

@dan-j
Copy link

dan-j commented Jul 21, 2017

Source maps when compiled through ts-babel-node aren't correct. It's an issue with babel (see babel/babel#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 };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant