File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
4444Babelify . prototype . _transform = function ( buf , enc , callback ) {
45- this . _data += buf ;
45+ this . _data . push ( buf ) ;
4646 callback ( ) ;
4747} ;
4848
4949Babelify . 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 {
You can’t perform that action at this time.
0 commit comments