var encoder = new TextEncoder();

module.exports = function (data) {
  // eslint-disable-next-line no-undef
  var transformStream = new TransformStream();
  var writer = transformStream.writable.getWriter();
  var out = this.createOut(
    data && data.$global,
    {
      write: function (string) {
        writer.write(encoder.encode(string));
      },
      end: function () {
        writer.close();
      }
    },
    undefined,
    this.___shouldBuffer
  );
  this.render(data, out);
  out.end();

  return transformStream.readable;
};

@@ -25,16 +25,43 @@
 coder();
+%0Avar noop = function () %7B%7D;
 %0A%0Amodule
@@ -238,64 +238,19 @@
 var 
-out = this.createOut(%0A    data && data.$global,%0A   
+facade =
  %7B%0A
-  
     
@@ -272,26 +272,24 @@
  (string) %7B%0A
-  
       writer
@@ -324,23 +324,19 @@
 ));%0A    
- 
- 
 %7D,%0A
-  
     end:
@@ -352,26 +352,24 @@
  () %7B%0A      
-  
 writer.close
@@ -380,61 +380,219 @@
     
+%7D%0A
   %7D
+;
 %0A  
-  %7D,%0A    undefined,%0A    this.___shouldBuffer%0A  
+var out = this.createOut(%0A    data && data.$global,%0A    facade,%0A    undefined,%0A    this.___shouldBuffer%0A  );%0A  out.once(%22error%22, err =%3E %7B%0A    facade.write = facade.end = noop;%0A    writer.abort(err);%0A  %7D
 );%0A 

improve error handling in web workers