From e20842d4dd8cef9b80eea2fad54556032c006aea Mon Sep 17 00:00:00 2001 From: Denis Iogansen Date: Thu, 26 Nov 2015 17:35:57 +0300 Subject: [PATCH] Fix sourcemap's bug for files in nested folders. Closes #54 --- index.js | 4 +++- test.js | 29 +++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index fc41c03..c477428 100644 --- a/index.js +++ b/index.js @@ -24,7 +24,9 @@ module.exports = function (opts) { var fileOpts = objectAssign({}, opts, { filename: file.path, filenameRelative: file.relative, - sourceMap: Boolean(file.sourceMap) + sourceMap: Boolean(file.sourceMap), + sourceFileName: file.relative, + sourceMapTarget: file.relative }); var res = babel.transform(file.contents.toString(), fileOpts); diff --git a/test.js b/test.js index 4aeab1a..0f66498 100644 --- a/test.js +++ b/test.js @@ -56,6 +56,35 @@ it('should generate source maps', function (cb) { init.end(); }); +it('should generate source maps for file in nested folder', function (cb) { + var init = sourceMaps.init(); + var write = sourceMaps.write(); + init + .pipe(babel({ + plugins: ['transform-es2015-arrow-functions'] + })) + .pipe(write); + + write.on('data', function (file) { + assert.deepEqual(file.sourceMap.sources, ['nested/fixture.es6']); + assert.strictEqual(file.sourceMap.file, 'nested/fixture.js'); + var contents = file.contents.toString(); + assert(/function/.test(contents)); + assert(/sourceMappingURL/.test(contents)); + cb(); + }); + + init.write(new gutil.File({ + cwd: __dirname, + base: path.join(__dirname, 'fixture'), + path: path.join(__dirname, 'fixture/nested/fixture.es6'), + contents: new Buffer('[].map(v => v + 1)'), + sourceMap: '' + })); + + init.end(); +}); + it('should list used helpers in file.babel', function (cb) { var stream = babel({ plugins: ['transform-es2015-classes']