Skip to content

Commit 239adce

Browse files
committed
Fix multibyte character corruption edge case.
1 parent cbd6934 commit 239adce

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

index.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function Babelify(filename, opts) {
3232
}
3333

3434
stream.Transform.call(this);
35-
this._data = "";
35+
this._data = [];
3636
this._filename = filename;
3737
this._opts = Object.assign({filename: filename}, opts, {
3838
caller: Object.assign({
@@ -42,12 +42,16 @@ function Babelify(filename, opts) {
4242
}
4343

4444
Babelify.prototype._transform = function (buf, enc, callback) {
45-
this._data += buf;
45+
this._data.push(buf);
4646
callback();
4747
};
4848

4949
Babelify.prototype._flush = function (callback) {
50-
babel.transform(this._data, this._opts, (err, result) => {
50+
// Merge the buffer pieces after all are available, instead of one at a time,
51+
// to avoid corrupting multibyte characters.
52+
const data = Buffer.concat(this._data).toString();
53+
54+
babel.transform(data, this._opts, (err, result) => {
5155
if (err) {
5256
this.emit("error", err);
5357
} else {

0 commit comments

Comments
 (0)