Skip to content
Permalink
Browse files

Fix multibyte character corruption edge case.

  • Loading branch information...
loganfsmyth committed Sep 4, 2018
1 parent cbd6934 commit 239adce3191faeff652a180bdd563d3a8b97a60d
Showing with 7 additions and 3 deletions.
  1. +7 −3 index.js
@@ -32,7 +32,7 @@ function Babelify(filename, opts) {
}

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

Babelify.prototype._transform = function (buf, enc, callback) {
this._data += buf;
this._data.push(buf);
callback();
};

Babelify.prototype._flush = function (callback) {
babel.transform(this._data, this._opts, (err, result) => {
// Merge the buffer pieces after all are available, instead of one at a time,
// to avoid corrupting multibyte characters.
const data = Buffer.concat(this._data).toString();

babel.transform(data, this._opts, (err, result) => {
if (err) {
this.emit("error", err);
} else {

0 comments on commit 239adce

Please sign in to comment.
You can’t perform that action at this time.