Skip to content

Commit 0b8b9f1

Browse files
committed
Fix crash when replacing 0 length ranges, fixes #41
1 parent 9c5868d commit 0b8b9f1

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,11 @@ module.exports = function parse (modules, opts) {
6666
s.stream.pipe(concat({ encoding: 'string' }, function (chunk) {
6767
// We have to give magic-string the replacement string,
6868
// so it can calculate the amount of lines and columns.
69-
sourcemapper.overwrite(s.start, s.start + s.offset, chunk);
69+
if (s.offset === 0) {
70+
sourcemapper.appendRight(s.start, chunk);
71+
} else {
72+
sourcemapper.overwrite(s.start, s.start + s.offset, chunk);
73+
}
7074
})).on('finish', next);
7175
} else {
7276
s.stream.on('end', next);

test/vars.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,10 @@ test('multi consecutive require vars', function (t) {
7777
return fs.createReadStream(file).pipe(quote());
7878
}
7979
}
80-
}, { vars: { __dirname: path.join(__dirname, 'vars') } });
80+
}, {
81+
vars: { __dirname: path.join(__dirname, 'vars') },
82+
sourceMap: true // Make sure source maps work when replacing 0 length ranges.
83+
});
8184

8285
readStream('multi-require.js').pipe(sm).pipe(concat(function (body) {
8386
Function(['console','require'],body)({ log: log }, function() { return {} });

0 commit comments

Comments
 (0)