Protect against missing Babel source maps in compile-coffeescript.js.

This commit is contained in:
Ben Newman
2016-06-06 14:10:56 -04:00
parent e60878a8ab
commit 31b080ddb3

View File

@@ -83,12 +83,19 @@ export class CoffeeCompiler extends CachingCompiler {
doubleRoastedCoffee.data != null) {
output.js = doubleRoastedCoffee.data;
// Combine the original CoffeeScript source map with the one
// produced by this.babelCompiler.processOneFileForTarget.
const smg = new SourceMapGenerator(
new SourceMapConsumer(doubleRoastedCoffee.sourceMap));
smg.applySourceMap(new SourceMapConsumer(sourceMap));
sourceMap = smg.toJSON();
if (doubleRoastedCoffee.sourceMap) {
// Combine the original CoffeeScript source map with the one
// produced by this.babelCompiler.processOneFileForTarget.
const smg = new SourceMapGenerator(
new SourceMapConsumer(doubleRoastedCoffee.sourceMap));
smg.applySourceMap(new SourceMapConsumer(sourceMap));
sourceMap = smg.toJSON();
} else {
// If the .coffee file is contained by a node_modules directory,
// then BabelCompiler will not transpile it, and there will be
// no sourceMap, but that's fine because the original
// CoffeeScript sourceMap will still be valid.
}
}
}