Skip to content

Commit

Permalink
Fix sourcemap's bug for files in nested folders. Closes #54
Browse files Browse the repository at this point in the history
  • Loading branch information
pofigizm committed Nov 26, 2015
1 parent 40815c1 commit e20842d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
29 changes: 29 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down

0 comments on commit e20842d

Please sign in to comment.