@bytecodealliance/jco 0.4.1 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/api.mjs CHANGED
@@ -2782,60 +2782,48 @@ module.exports.q = codes;
2782
2782
  // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
2783
2783
  // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
2784
2784
  // USE OR OTHER DEALINGS IN THE SOFTWARE.
2785
+
2785
2786
  // a duplex stream is just a stream that is both readable and writable.
2786
2787
  // Since JS doesn't have multiple prototypal inheritance, this class
2787
2788
  // prototypally inherits from Readable, and then parasitically from
2788
2789
  // Writable.
2789
2790
 
2790
- /*<replacement>*/
2791
2791
 
2792
+
2793
+ /*<replacement>*/
2792
2794
  var objectKeys = Object.keys || function (obj) {
2793
2795
  var keys = [];
2794
-
2795
- for (var key in obj) {
2796
- keys.push(key);
2797
- }
2798
-
2796
+ for (var key in obj) keys.push(key);
2799
2797
  return keys;
2800
2798
  };
2801
2799
  /*</replacement>*/
2802
2800
 
2803
-
2804
2801
  module.exports = Duplex;
2805
-
2806
2802
  var Readable = __nccwpck_require__(1433);
2807
-
2808
2803
  var Writable = __nccwpck_require__(6993);
2809
-
2810
2804
  __nccwpck_require__(4124)(Duplex, Readable);
2811
-
2812
2805
  {
2813
2806
  // Allow the keys array to be GC'ed.
2814
2807
  var keys = objectKeys(Writable.prototype);
2815
-
2816
2808
  for (var v = 0; v < keys.length; v++) {
2817
2809
  var method = keys[v];
2818
2810
  if (!Duplex.prototype[method]) Duplex.prototype[method] = Writable.prototype[method];
2819
2811
  }
2820
2812
  }
2821
-
2822
2813
  function Duplex(options) {
2823
2814
  if (!(this instanceof Duplex)) return new Duplex(options);
2824
2815
  Readable.call(this, options);
2825
2816
  Writable.call(this, options);
2826
2817
  this.allowHalfOpen = true;
2827
-
2828
2818
  if (options) {
2829
2819
  if (options.readable === false) this.readable = false;
2830
2820
  if (options.writable === false) this.writable = false;
2831
-
2832
2821
  if (options.allowHalfOpen === false) {
2833
2822
  this.allowHalfOpen = false;
2834
2823
  this.once('end', onend);
2835
2824
  }
2836
2825
  }
2837
2826
  }
2838
-
2839
2827
  Object.defineProperty(Duplex.prototype, 'writableHighWaterMark', {
2840
2828
  // making it explicit this property is not enumerable
2841
2829
  // because otherwise some prototype manipulation in
@@ -2862,20 +2850,20 @@ Object.defineProperty(Duplex.prototype, 'writableLength', {
2862
2850
  get: function get() {
2863
2851
  return this._writableState.length;
2864
2852
  }
2865
- }); // the no-half-open enforcer
2853
+ });
2866
2854
 
2855
+ // the no-half-open enforcer
2867
2856
  function onend() {
2868
2857
  // If the writable side ended, then we're ok.
2869
- if (this._writableState.ended) return; // no more data can be written.
2870
- // But allow more writes to happen in this tick.
2858
+ if (this._writableState.ended) return;
2871
2859
 
2860
+ // no more data can be written.
2861
+ // But allow more writes to happen in this tick.
2872
2862
  process.nextTick(onEndNT, this);
2873
2863
  }
2874
-
2875
2864
  function onEndNT(self) {
2876
2865
  self.end();
2877
2866
  }
2878
-
2879
2867
  Object.defineProperty(Duplex.prototype, 'destroyed', {
2880
2868
  // making it explicit this property is not enumerable
2881
2869
  // because otherwise some prototype manipulation in
@@ -2885,7 +2873,6 @@ Object.defineProperty(Duplex.prototype, 'destroyed', {
2885
2873
  if (this._readableState === undefined || this._writableState === undefined) {
2886
2874
  return false;
2887
2875
  }
2888
-
2889
2876
  return this._readableState.destroyed && this._writableState.destroyed;
2890
2877
  },
2891
2878
  set: function set(value) {
@@ -2893,10 +2880,10 @@ Object.defineProperty(Duplex.prototype, 'destroyed', {
2893
2880
  // has not been initialized yet
2894
2881
  if (this._readableState === undefined || this._writableState === undefined) {
2895
2882
  return;
2896
- } // backward compatibility, the user is explicitly
2897
- // managing destroyed
2898
-
2883
+ }
2899
2884
 
2885
+ // backward compatibility, the user is explicitly
2886
+ // managing destroyed
2900
2887
  this._readableState.destroyed = value;
2901
2888
  this._writableState.destroyed = value;
2902
2889
  }
@@ -2927,22 +2914,20 @@ Object.defineProperty(Duplex.prototype, 'destroyed', {
2927
2914
  // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
2928
2915
  // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
2929
2916
  // USE OR OTHER DEALINGS IN THE SOFTWARE.
2917
+
2930
2918
  // a passthrough stream.
2931
2919
  // basically just the most minimal sort of Transform stream.
2932
2920
  // Every written chunk gets output as-is.
2933
2921
 
2934
2922
 
2935
- module.exports = PassThrough;
2936
2923
 
2924
+ module.exports = PassThrough;
2937
2925
  var Transform = __nccwpck_require__(4415);
2938
-
2939
2926
  __nccwpck_require__(4124)(PassThrough, Transform);
2940
-
2941
2927
  function PassThrough(options) {
2942
2928
  if (!(this instanceof PassThrough)) return new PassThrough(options);
2943
2929
  Transform.call(this, options);
2944
2930
  }
2945
-
2946
2931
  PassThrough.prototype._transform = function (chunk, encoding, cb) {
2947
2932
  cb(null, chunk);
2948
2933
  };
@@ -2974,47 +2959,38 @@ PassThrough.prototype._transform = function (chunk, encoding, cb) {
2974
2959
  // USE OR OTHER DEALINGS IN THE SOFTWARE.
2975
2960
 
2976
2961
 
2962
+
2977
2963
  module.exports = Readable;
2978
- /*<replacement>*/
2979
2964
 
2965
+ /*<replacement>*/
2980
2966
  var Duplex;
2981
2967
  /*</replacement>*/
2982
2968
 
2983
2969
  Readable.ReadableState = ReadableState;
2984
- /*<replacement>*/
2985
2970
 
2971
+ /*<replacement>*/
2986
2972
  var EE = (__nccwpck_require__(2361).EventEmitter);
2987
-
2988
2973
  var EElistenerCount = function EElistenerCount(emitter, type) {
2989
2974
  return emitter.listeners(type).length;
2990
2975
  };
2991
2976
  /*</replacement>*/
2992
2977
 
2993
2978
  /*<replacement>*/
2994
-
2995
-
2996
2979
  var Stream = __nccwpck_require__(2387);
2997
2980
  /*</replacement>*/
2998
2981
 
2999
-
3000
2982
  var Buffer = (__nccwpck_require__(4300).Buffer);
3001
-
3002
- var OurUint8Array = global.Uint8Array || function () {};
3003
-
2983
+ var OurUint8Array = (typeof global !== 'undefined' ? global : typeof window !== 'undefined' ? window : typeof self !== 'undefined' ? self : {}).Uint8Array || function () {};
3004
2984
  function _uint8ArrayToBuffer(chunk) {
3005
2985
  return Buffer.from(chunk);
3006
2986
  }
3007
-
3008
2987
  function _isUint8Array(obj) {
3009
2988
  return Buffer.isBuffer(obj) || obj instanceof OurUint8Array;
3010
2989
  }
3011
- /*<replacement>*/
3012
-
3013
2990
 
2991
+ /*<replacement>*/
3014
2992
  var debugUtil = __nccwpck_require__(3837);
3015
-
3016
2993
  var debug;
3017
-
3018
2994
  if (debugUtil && debugUtil.debuglog) {
3019
2995
  debug = debugUtil.debuglog('stream');
3020
2996
  } else {
@@ -3022,60 +2998,57 @@ if (debugUtil && debugUtil.debuglog) {
3022
2998
  }
3023
2999
  /*</replacement>*/
3024
3000
 
3025
-
3026
3001
  var BufferList = __nccwpck_require__(2746);
3027
-
3028
3002
  var destroyImpl = __nccwpck_require__(7049);
3029
-
3030
3003
  var _require = __nccwpck_require__(9948),
3031
- getHighWaterMark = _require.getHighWaterMark;
3032
-
3004
+ getHighWaterMark = _require.getHighWaterMark;
3033
3005
  var _require$codes = (__nccwpck_require__(7214)/* .codes */ .q),
3034
- ERR_INVALID_ARG_TYPE = _require$codes.ERR_INVALID_ARG_TYPE,
3035
- ERR_STREAM_PUSH_AFTER_EOF = _require$codes.ERR_STREAM_PUSH_AFTER_EOF,
3036
- ERR_METHOD_NOT_IMPLEMENTED = _require$codes.ERR_METHOD_NOT_IMPLEMENTED,
3037
- ERR_STREAM_UNSHIFT_AFTER_END_EVENT = _require$codes.ERR_STREAM_UNSHIFT_AFTER_END_EVENT; // Lazy loaded to improve the startup performance.
3038
-
3006
+ ERR_INVALID_ARG_TYPE = _require$codes.ERR_INVALID_ARG_TYPE,
3007
+ ERR_STREAM_PUSH_AFTER_EOF = _require$codes.ERR_STREAM_PUSH_AFTER_EOF,
3008
+ ERR_METHOD_NOT_IMPLEMENTED = _require$codes.ERR_METHOD_NOT_IMPLEMENTED,
3009
+ ERR_STREAM_UNSHIFT_AFTER_END_EVENT = _require$codes.ERR_STREAM_UNSHIFT_AFTER_END_EVENT;
3039
3010
 
3011
+ // Lazy loaded to improve the startup performance.
3040
3012
  var StringDecoder;
3041
3013
  var createReadableStreamAsyncIterator;
3042
3014
  var from;
3043
-
3044
3015
  __nccwpck_require__(4124)(Readable, Stream);
3045
-
3046
3016
  var errorOrDestroy = destroyImpl.errorOrDestroy;
3047
3017
  var kProxyEvents = ['error', 'close', 'destroy', 'pause', 'resume'];
3048
-
3049
3018
  function prependListener(emitter, event, fn) {
3050
3019
  // Sadly this is not cacheable as some libraries bundle their own
3051
3020
  // event emitter implementation with them.
3052
- if (typeof emitter.prependListener === 'function') return emitter.prependListener(event, fn); // This is a hack to make sure that our error handler is attached before any
3021
+ if (typeof emitter.prependListener === 'function') return emitter.prependListener(event, fn);
3022
+
3023
+ // This is a hack to make sure that our error handler is attached before any
3053
3024
  // userland ones. NEVER DO THIS. This is here only because this code needs
3054
3025
  // to continue to work with older versions of Node.js that do not include
3055
3026
  // the prependListener() method. The goal is to eventually remove this hack.
3056
-
3057
3027
  if (!emitter._events || !emitter._events[event]) emitter.on(event, fn);else if (Array.isArray(emitter._events[event])) emitter._events[event].unshift(fn);else emitter._events[event] = [fn, emitter._events[event]];
3058
3028
  }
3059
-
3060
3029
  function ReadableState(options, stream, isDuplex) {
3061
3030
  Duplex = Duplex || __nccwpck_require__(1359);
3062
- options = options || {}; // Duplex streams are both readable and writable, but share
3031
+ options = options || {};
3032
+
3033
+ // Duplex streams are both readable and writable, but share
3063
3034
  // the same options object.
3064
3035
  // However, some cases require setting options to different
3065
3036
  // values for the readable and the writable sides of the duplex stream.
3066
3037
  // These options can be provided separately as readableXXX and writableXXX.
3038
+ if (typeof isDuplex !== 'boolean') isDuplex = stream instanceof Duplex;
3067
3039
 
3068
- if (typeof isDuplex !== 'boolean') isDuplex = stream instanceof Duplex; // object stream flag. Used to make read(n) ignore n and to
3040
+ // object stream flag. Used to make read(n) ignore n and to
3069
3041
  // make all the buffer merging and length checks go away
3070
-
3071
3042
  this.objectMode = !!options.objectMode;
3072
- if (isDuplex) this.objectMode = this.objectMode || !!options.readableObjectMode; // the point at which it stops calling _read() to fill the buffer
3043
+ if (isDuplex) this.objectMode = this.objectMode || !!options.readableObjectMode;
3044
+
3045
+ // the point at which it stops calling _read() to fill the buffer
3073
3046
  // Note: 0 is a valid value, means "don't call _read preemptively ever"
3047
+ this.highWaterMark = getHighWaterMark(this, options, 'readableHighWaterMark', isDuplex);
3074
3048
 
3075
- this.highWaterMark = getHighWaterMark(this, options, 'readableHighWaterMark', isDuplex); // A linked list is used to store data chunks instead of an array because the
3049
+ // A linked list is used to store data chunks instead of an array because the
3076
3050
  // linked list can remove elements from the beginning faster than
3077
3051
  // array.shift()
3078
-
3079
3052
  this.buffer = new BufferList();
3080
3053
  this.length = 0;
3081
3054
  this.pipes = null;
@@ -3083,61 +3056,66 @@ function ReadableState(options, stream, isDuplex) {
3083
3056
  this.flowing = null;
3084
3057
  this.ended = false;
3085
3058
  this.endEmitted = false;
3086
- this.reading = false; // a flag to be able to tell if the event 'readable'/'data' is emitted
3059
+ this.reading = false;
3060
+
3061
+ // a flag to be able to tell if the event 'readable'/'data' is emitted
3087
3062
  // immediately, or on a later tick. We set this to true at first, because
3088
3063
  // any actions that shouldn't happen until "later" should generally also
3089
3064
  // not happen before the first read call.
3065
+ this.sync = true;
3090
3066
 
3091
- this.sync = true; // whenever we return null, then we set a flag to say
3067
+ // whenever we return null, then we set a flag to say
3092
3068
  // that we're awaiting a 'readable' event emission.
3093
-
3094
3069
  this.needReadable = false;
3095
3070
  this.emittedReadable = false;
3096
3071
  this.readableListening = false;
3097
3072
  this.resumeScheduled = false;
3098
- this.paused = true; // Should close be emitted on destroy. Defaults to true.
3073
+ this.paused = true;
3074
+
3075
+ // Should close be emitted on destroy. Defaults to true.
3076
+ this.emitClose = options.emitClose !== false;
3099
3077
 
3100
- this.emitClose = options.emitClose !== false; // Should .destroy() be called after 'end' (and potentially 'finish')
3078
+ // Should .destroy() be called after 'end' (and potentially 'finish')
3079
+ this.autoDestroy = !!options.autoDestroy;
3101
3080
 
3102
- this.autoDestroy = !!options.autoDestroy; // has it been destroyed
3081
+ // has it been destroyed
3082
+ this.destroyed = false;
3103
3083
 
3104
- this.destroyed = false; // Crypto is kind of old and crusty. Historically, its default string
3084
+ // Crypto is kind of old and crusty. Historically, its default string
3105
3085
  // encoding is 'binary' so we have to make this configurable.
3106
3086
  // Everything else in the universe uses 'utf8', though.
3087
+ this.defaultEncoding = options.defaultEncoding || 'utf8';
3107
3088
 
3108
- this.defaultEncoding = options.defaultEncoding || 'utf8'; // the number of writers that are awaiting a drain event in .pipe()s
3109
-
3110
- this.awaitDrain = 0; // if true, a maybeReadMore has been scheduled
3089
+ // the number of writers that are awaiting a drain event in .pipe()s
3090
+ this.awaitDrain = 0;
3111
3091
 
3092
+ // if true, a maybeReadMore has been scheduled
3112
3093
  this.readingMore = false;
3113
3094
  this.decoder = null;
3114
3095
  this.encoding = null;
3115
-
3116
3096
  if (options.encoding) {
3117
3097
  if (!StringDecoder) StringDecoder = (__nccwpck_require__(4841)/* .StringDecoder */ .s);
3118
3098
  this.decoder = new StringDecoder(options.encoding);
3119
3099
  this.encoding = options.encoding;
3120
3100
  }
3121
3101
  }
3122
-
3123
3102
  function Readable(options) {
3124
3103
  Duplex = Duplex || __nccwpck_require__(1359);
3125
- if (!(this instanceof Readable)) return new Readable(options); // Checking for a Stream.Duplex instance is faster here instead of inside
3126
- // the ReadableState constructor, at least with V8 6.5
3104
+ if (!(this instanceof Readable)) return new Readable(options);
3127
3105
 
3106
+ // Checking for a Stream.Duplex instance is faster here instead of inside
3107
+ // the ReadableState constructor, at least with V8 6.5
3128
3108
  var isDuplex = this instanceof Duplex;
3129
- this._readableState = new ReadableState(options, this, isDuplex); // legacy
3109
+ this._readableState = new ReadableState(options, this, isDuplex);
3130
3110
 
3111
+ // legacy
3131
3112
  this.readable = true;
3132
-
3133
3113
  if (options) {
3134
3114
  if (typeof options.read === 'function') this._read = options.read;
3135
3115
  if (typeof options.destroy === 'function') this._destroy = options.destroy;
3136
3116
  }
3137
-
3138
3117
  Stream.call(this);
3139
3118
  }
3140
-
3141
3119
  Object.defineProperty(Readable.prototype, 'destroyed', {
3142
3120
  // making it explicit this property is not enumerable
3143
3121
  // because otherwise some prototype manipulation in
@@ -3147,7 +3125,6 @@ Object.defineProperty(Readable.prototype, 'destroyed', {
3147
3125
  if (this._readableState === undefined) {
3148
3126
  return false;
3149
3127
  }
3150
-
3151
3128
  return this._readableState.destroyed;
3152
3129
  },
3153
3130
  set: function set(value) {
@@ -3155,69 +3132,60 @@ Object.defineProperty(Readable.prototype, 'destroyed', {
3155
3132
  // has not been initialized yet
3156
3133
  if (!this._readableState) {
3157
3134
  return;
3158
- } // backward compatibility, the user is explicitly
3159
- // managing destroyed
3160
-
3135
+ }
3161
3136
 
3137
+ // backward compatibility, the user is explicitly
3138
+ // managing destroyed
3162
3139
  this._readableState.destroyed = value;
3163
3140
  }
3164
3141
  });
3165
3142
  Readable.prototype.destroy = destroyImpl.destroy;
3166
3143
  Readable.prototype._undestroy = destroyImpl.undestroy;
3167
-
3168
3144
  Readable.prototype._destroy = function (err, cb) {
3169
3145
  cb(err);
3170
- }; // Manually shove something into the read() buffer.
3146
+ };
3147
+
3148
+ // Manually shove something into the read() buffer.
3171
3149
  // This returns true if the highWaterMark has not been hit yet,
3172
3150
  // similar to how Writable.write() returns true if you should
3173
3151
  // write() some more.
3174
-
3175
-
3176
3152
  Readable.prototype.push = function (chunk, encoding) {
3177
3153
  var state = this._readableState;
3178
3154
  var skipChunkCheck;
3179
-
3180
3155
  if (!state.objectMode) {
3181
3156
  if (typeof chunk === 'string') {
3182
3157
  encoding = encoding || state.defaultEncoding;
3183
-
3184
3158
  if (encoding !== state.encoding) {
3185
3159
  chunk = Buffer.from(chunk, encoding);
3186
3160
  encoding = '';
3187
3161
  }
3188
-
3189
3162
  skipChunkCheck = true;
3190
3163
  }
3191
3164
  } else {
3192
3165
  skipChunkCheck = true;
3193
3166
  }
3194
-
3195
3167
  return readableAddChunk(this, chunk, encoding, false, skipChunkCheck);
3196
- }; // Unshift should *always* be something directly out of read()
3197
-
3168
+ };
3198
3169
 
3170
+ // Unshift should *always* be something directly out of read()
3199
3171
  Readable.prototype.unshift = function (chunk) {
3200
3172
  return readableAddChunk(this, chunk, null, true, false);
3201
3173
  };
3202
-
3203
3174
  function readableAddChunk(stream, chunk, encoding, addToFront, skipChunkCheck) {
3204
3175
  debug('readableAddChunk', chunk);
3205
3176
  var state = stream._readableState;
3206
-
3207
3177
  if (chunk === null) {
3208
3178
  state.reading = false;
3209
3179
  onEofChunk(stream, state);
3210
3180
  } else {
3211
3181
  var er;
3212
3182
  if (!skipChunkCheck) er = chunkInvalid(state, chunk);
3213
-
3214
3183
  if (er) {
3215
3184
  errorOrDestroy(stream, er);
3216
3185
  } else if (state.objectMode || chunk && chunk.length > 0) {
3217
3186
  if (typeof chunk !== 'string' && !state.objectMode && Object.getPrototypeOf(chunk) !== Buffer.prototype) {
3218
3187
  chunk = _uint8ArrayToBuffer(chunk);
3219
3188
  }
3220
-
3221
3189
  if (addToFront) {
3222
3190
  if (state.endEmitted) errorOrDestroy(stream, new ERR_STREAM_UNSHIFT_AFTER_END_EVENT());else addChunk(stream, state, chunk, true);
3223
3191
  } else if (state.ended) {
@@ -3226,7 +3194,6 @@ function readableAddChunk(stream, chunk, encoding, addToFront, skipChunkCheck) {
3226
3194
  return false;
3227
3195
  } else {
3228
3196
  state.reading = false;
3229
-
3230
3197
  if (state.decoder && !encoding) {
3231
3198
  chunk = state.decoder.write(chunk);
3232
3199
  if (state.objectMode || chunk.length !== 0) addChunk(stream, state, chunk, false);else maybeReadMore(stream, state);
@@ -3238,14 +3205,13 @@ function readableAddChunk(stream, chunk, encoding, addToFront, skipChunkCheck) {
3238
3205
  state.reading = false;
3239
3206
  maybeReadMore(stream, state);
3240
3207
  }
3241
- } // We can push more data if we are below the highWaterMark.
3208
+ }
3209
+
3210
+ // We can push more data if we are below the highWaterMark.
3242
3211
  // Also, if we have no data yet, we can stand some more bytes.
3243
3212
  // This is to work around cases where hwm=0, such as the repl.
3244
-
3245
-
3246
3213
  return !state.ended && (state.length < state.highWaterMark || state.length === 0);
3247
3214
  }
3248
-
3249
3215
  function addChunk(stream, state, chunk, addToFront) {
3250
3216
  if (state.flowing && state.length === 0 && !state.sync) {
3251
3217
  state.awaitDrain = 0;
@@ -3256,50 +3222,42 @@ function addChunk(stream, state, chunk, addToFront) {
3256
3222
  if (addToFront) state.buffer.unshift(chunk);else state.buffer.push(chunk);
3257
3223
  if (state.needReadable) emitReadable(stream);
3258
3224
  }
3259
-
3260
3225
  maybeReadMore(stream, state);
3261
3226
  }
3262
-
3263
3227
  function chunkInvalid(state, chunk) {
3264
3228
  var er;
3265
-
3266
3229
  if (!_isUint8Array(chunk) && typeof chunk !== 'string' && chunk !== undefined && !state.objectMode) {
3267
3230
  er = new ERR_INVALID_ARG_TYPE('chunk', ['string', 'Buffer', 'Uint8Array'], chunk);
3268
3231
  }
3269
-
3270
3232
  return er;
3271
3233
  }
3272
-
3273
3234
  Readable.prototype.isPaused = function () {
3274
3235
  return this._readableState.flowing === false;
3275
- }; // backwards compatibility.
3276
-
3236
+ };
3277
3237
 
3238
+ // backwards compatibility.
3278
3239
  Readable.prototype.setEncoding = function (enc) {
3279
3240
  if (!StringDecoder) StringDecoder = (__nccwpck_require__(4841)/* .StringDecoder */ .s);
3280
3241
  var decoder = new StringDecoder(enc);
3281
- this._readableState.decoder = decoder; // If setEncoding(null), decoder.encoding equals utf8
3282
-
3283
- this._readableState.encoding = this._readableState.decoder.encoding; // Iterate over current buffer to convert already stored Buffers:
3242
+ this._readableState.decoder = decoder;
3243
+ // If setEncoding(null), decoder.encoding equals utf8
3244
+ this._readableState.encoding = this._readableState.decoder.encoding;
3284
3245
 
3246
+ // Iterate over current buffer to convert already stored Buffers:
3285
3247
  var p = this._readableState.buffer.head;
3286
3248
  var content = '';
3287
-
3288
3249
  while (p !== null) {
3289
3250
  content += decoder.write(p.data);
3290
3251
  p = p.next;
3291
3252
  }
3292
-
3293
3253
  this._readableState.buffer.clear();
3294
-
3295
3254
  if (content !== '') this._readableState.buffer.push(content);
3296
3255
  this._readableState.length = content.length;
3297
3256
  return this;
3298
- }; // Don't raise the hwm > 1GB
3299
-
3257
+ };
3300
3258
 
3259
+ // Don't raise the hwm > 1GB
3301
3260
  var MAX_HWM = 0x40000000;
3302
-
3303
3261
  function computeNewHighWaterMark(n) {
3304
3262
  if (n >= MAX_HWM) {
3305
3263
  // TODO(ronag): Throw ERR_VALUE_OUT_OF_RANGE.
@@ -3315,55 +3273,54 @@ function computeNewHighWaterMark(n) {
3315
3273
  n |= n >>> 16;
3316
3274
  n++;
3317
3275
  }
3318
-
3319
3276
  return n;
3320
- } // This function is designed to be inlinable, so please take care when making
3321
- // changes to the function body.
3322
-
3277
+ }
3323
3278
 
3279
+ // This function is designed to be inlinable, so please take care when making
3280
+ // changes to the function body.
3324
3281
  function howMuchToRead(n, state) {
3325
3282
  if (n <= 0 || state.length === 0 && state.ended) return 0;
3326
3283
  if (state.objectMode) return 1;
3327
-
3328
3284
  if (n !== n) {
3329
3285
  // Only flow one buffer at a time
3330
3286
  if (state.flowing && state.length) return state.buffer.head.data.length;else return state.length;
3331
- } // If we're asking for more than the current hwm, then raise the hwm.
3332
-
3333
-
3287
+ }
3288
+ // If we're asking for more than the current hwm, then raise the hwm.
3334
3289
  if (n > state.highWaterMark) state.highWaterMark = computeNewHighWaterMark(n);
3335
- if (n <= state.length) return n; // Don't have enough
3336
-
3290
+ if (n <= state.length) return n;
3291
+ // Don't have enough
3337
3292
  if (!state.ended) {
3338
3293
  state.needReadable = true;
3339
3294
  return 0;
3340
3295
  }
3341
-
3342
3296
  return state.length;
3343
- } // you can override either this method, or the async _read(n) below.
3344
-
3297
+ }
3345
3298
 
3299
+ // you can override either this method, or the async _read(n) below.
3346
3300
  Readable.prototype.read = function (n) {
3347
3301
  debug('read', n);
3348
3302
  n = parseInt(n, 10);
3349
3303
  var state = this._readableState;
3350
3304
  var nOrig = n;
3351
- if (n !== 0) state.emittedReadable = false; // if we're doing read(0) to trigger a readable event, but we
3305
+ if (n !== 0) state.emittedReadable = false;
3306
+
3307
+ // if we're doing read(0) to trigger a readable event, but we
3352
3308
  // already have a bunch of data in the buffer, then just trigger
3353
3309
  // the 'readable' event and move on.
3354
-
3355
3310
  if (n === 0 && state.needReadable && ((state.highWaterMark !== 0 ? state.length >= state.highWaterMark : state.length > 0) || state.ended)) {
3356
3311
  debug('read: emitReadable', state.length, state.ended);
3357
3312
  if (state.length === 0 && state.ended) endReadable(this);else emitReadable(this);
3358
3313
  return null;
3359
3314
  }
3315
+ n = howMuchToRead(n, state);
3360
3316
 
3361
- n = howMuchToRead(n, state); // if we've ended, and we're now clear, then finish it up.
3362
-
3317
+ // if we've ended, and we're now clear, then finish it up.
3363
3318
  if (n === 0 && state.ended) {
3364
3319
  if (state.length === 0) endReadable(this);
3365
3320
  return null;
3366
- } // All the actual chunk generation logic needs to be
3321
+ }
3322
+
3323
+ // All the actual chunk generation logic needs to be
3367
3324
  // *below* the call to _read. The reason is that in certain
3368
3325
  // synthetic stream cases, such as passthrough streams, _read
3369
3326
  // may be a completely synchronous operation which may change
@@ -3384,40 +3341,37 @@ Readable.prototype.read = function (n) {
3384
3341
  // 'readable' etc.
3385
3342
  //
3386
3343
  // 3. Actually pull the requested chunks out of the buffer and return.
3387
- // if we need a readable event, then we need to do some reading.
3388
-
3389
3344
 
3345
+ // if we need a readable event, then we need to do some reading.
3390
3346
  var doRead = state.needReadable;
3391
- debug('need readable', doRead); // if we currently have less than the highWaterMark, then also read some
3347
+ debug('need readable', doRead);
3392
3348
 
3349
+ // if we currently have less than the highWaterMark, then also read some
3393
3350
  if (state.length === 0 || state.length - n < state.highWaterMark) {
3394
3351
  doRead = true;
3395
3352
  debug('length less than watermark', doRead);
3396
- } // however, if we've ended, then there's no point, and if we're already
3397
- // reading, then it's unnecessary.
3398
-
3353
+ }
3399
3354
 
3355
+ // however, if we've ended, then there's no point, and if we're already
3356
+ // reading, then it's unnecessary.
3400
3357
  if (state.ended || state.reading) {
3401
3358
  doRead = false;
3402
3359
  debug('reading or ended', doRead);
3403
3360
  } else if (doRead) {
3404
3361
  debug('do read');
3405
3362
  state.reading = true;
3406
- state.sync = true; // if the length is currently zero, then we *need* a readable event.
3407
-
3408
- if (state.length === 0) state.needReadable = true; // call internal read method
3409
-
3363
+ state.sync = true;
3364
+ // if the length is currently zero, then we *need* a readable event.
3365
+ if (state.length === 0) state.needReadable = true;
3366
+ // call internal read method
3410
3367
  this._read(state.highWaterMark);
3411
-
3412
- state.sync = false; // If _read pushed data synchronously, then `reading` will be false,
3368
+ state.sync = false;
3369
+ // If _read pushed data synchronously, then `reading` will be false,
3413
3370
  // and we need to re-evaluate how much data we can return to the user.
3414
-
3415
3371
  if (!state.reading) n = howMuchToRead(nOrig, state);
3416
3372
  }
3417
-
3418
3373
  var ret;
3419
3374
  if (n > 0) ret = fromList(n, state);else ret = null;
3420
-
3421
3375
  if (ret === null) {
3422
3376
  state.needReadable = state.length <= state.highWaterMark;
3423
3377
  n = 0;
@@ -3425,34 +3379,28 @@ Readable.prototype.read = function (n) {
3425
3379
  state.length -= n;
3426
3380
  state.awaitDrain = 0;
3427
3381
  }
3428
-
3429
3382
  if (state.length === 0) {
3430
3383
  // If we have nothing in the buffer, then we want to know
3431
3384
  // as soon as we *do* get something into the buffer.
3432
- if (!state.ended) state.needReadable = true; // If we tried to read() past the EOF, then emit end on the next tick.
3385
+ if (!state.ended) state.needReadable = true;
3433
3386
 
3387
+ // If we tried to read() past the EOF, then emit end on the next tick.
3434
3388
  if (nOrig !== n && state.ended) endReadable(this);
3435
3389
  }
3436
-
3437
3390
  if (ret !== null) this.emit('data', ret);
3438
3391
  return ret;
3439
3392
  };
3440
-
3441
3393
  function onEofChunk(stream, state) {
3442
3394
  debug('onEofChunk');
3443
3395
  if (state.ended) return;
3444
-
3445
3396
  if (state.decoder) {
3446
3397
  var chunk = state.decoder.end();
3447
-
3448
3398
  if (chunk && chunk.length) {
3449
3399
  state.buffer.push(chunk);
3450
3400
  state.length += state.objectMode ? 1 : chunk.length;
3451
3401
  }
3452
3402
  }
3453
-
3454
3403
  state.ended = true;
3455
-
3456
3404
  if (state.sync) {
3457
3405
  // if we are sync, wait until next tick to emit the data.
3458
3406
  // Otherwise we risk emitting data in the flow()
@@ -3461,61 +3409,56 @@ function onEofChunk(stream, state) {
3461
3409
  } else {
3462
3410
  // emit 'readable' now to make sure it gets picked up.
3463
3411
  state.needReadable = false;
3464
-
3465
3412
  if (!state.emittedReadable) {
3466
3413
  state.emittedReadable = true;
3467
3414
  emitReadable_(stream);
3468
3415
  }
3469
3416
  }
3470
- } // Don't emit readable right away in sync mode, because this can trigger
3417
+ }
3418
+
3419
+ // Don't emit readable right away in sync mode, because this can trigger
3471
3420
  // another read() call => stack overflow. This way, it might trigger
3472
3421
  // a nextTick recursion warning, but that's not so bad.
3473
-
3474
-
3475
3422
  function emitReadable(stream) {
3476
3423
  var state = stream._readableState;
3477
3424
  debug('emitReadable', state.needReadable, state.emittedReadable);
3478
3425
  state.needReadable = false;
3479
-
3480
3426
  if (!state.emittedReadable) {
3481
3427
  debug('emitReadable', state.flowing);
3482
3428
  state.emittedReadable = true;
3483
3429
  process.nextTick(emitReadable_, stream);
3484
3430
  }
3485
3431
  }
3486
-
3487
3432
  function emitReadable_(stream) {
3488
3433
  var state = stream._readableState;
3489
3434
  debug('emitReadable_', state.destroyed, state.length, state.ended);
3490
-
3491
3435
  if (!state.destroyed && (state.length || state.ended)) {
3492
3436
  stream.emit('readable');
3493
3437
  state.emittedReadable = false;
3494
- } // The stream needs another readable event if
3438
+ }
3439
+
3440
+ // The stream needs another readable event if
3495
3441
  // 1. It is not flowing, as the flow mechanism will take
3496
3442
  // care of it.
3497
3443
  // 2. It is not ended.
3498
3444
  // 3. It is below the highWaterMark, so we can schedule
3499
3445
  // another readable later.
3500
-
3501
-
3502
3446
  state.needReadable = !state.flowing && !state.ended && state.length <= state.highWaterMark;
3503
3447
  flow(stream);
3504
- } // at this point, the user has presumably seen the 'readable' event,
3448
+ }
3449
+
3450
+ // at this point, the user has presumably seen the 'readable' event,
3505
3451
  // and called read() to consume some data. that may have triggered
3506
3452
  // in turn another _read(n) call, in which case reading = true if
3507
3453
  // it's in progress.
3508
3454
  // However, if we're not ended, or reading, and the length < hwm,
3509
3455
  // then go ahead and try to read some more preemptively.
3510
-
3511
-
3512
3456
  function maybeReadMore(stream, state) {
3513
3457
  if (!state.readingMore) {
3514
3458
  state.readingMore = true;
3515
3459
  process.nextTick(maybeReadMore_, stream, state);
3516
3460
  }
3517
3461
  }
3518
-
3519
3462
  function maybeReadMore_(stream, state) {
3520
3463
  // Attempt to read more data if we should.
3521
3464
  //
@@ -3544,49 +3487,42 @@ function maybeReadMore_(stream, state) {
3544
3487
  var len = state.length;
3545
3488
  debug('maybeReadMore read 0');
3546
3489
  stream.read(0);
3547
- if (len === state.length) // didn't get any data, stop spinning.
3490
+ if (len === state.length)
3491
+ // didn't get any data, stop spinning.
3548
3492
  break;
3549
3493
  }
3550
-
3551
3494
  state.readingMore = false;
3552
- } // abstract method. to be overridden in specific implementation classes.
3495
+ }
3496
+
3497
+ // abstract method. to be overridden in specific implementation classes.
3553
3498
  // call cb(er, data) where data is <= n in length.
3554
3499
  // for virtual (non-string, non-buffer) streams, "length" is somewhat
3555
3500
  // arbitrary, and perhaps not very meaningful.
3556
-
3557
-
3558
3501
  Readable.prototype._read = function (n) {
3559
3502
  errorOrDestroy(this, new ERR_METHOD_NOT_IMPLEMENTED('_read()'));
3560
3503
  };
3561
-
3562
3504
  Readable.prototype.pipe = function (dest, pipeOpts) {
3563
3505
  var src = this;
3564
3506
  var state = this._readableState;
3565
-
3566
3507
  switch (state.pipesCount) {
3567
3508
  case 0:
3568
3509
  state.pipes = dest;
3569
3510
  break;
3570
-
3571
3511
  case 1:
3572
3512
  state.pipes = [state.pipes, dest];
3573
3513
  break;
3574
-
3575
3514
  default:
3576
3515
  state.pipes.push(dest);
3577
3516
  break;
3578
3517
  }
3579
-
3580
3518
  state.pipesCount += 1;
3581
3519
  debug('pipe count=%d opts=%j', state.pipesCount, pipeOpts);
3582
3520
  var doEnd = (!pipeOpts || pipeOpts.end !== false) && dest !== process.stdout && dest !== process.stderr;
3583
3521
  var endFn = doEnd ? onend : unpipe;
3584
3522
  if (state.endEmitted) process.nextTick(endFn);else src.once('end', endFn);
3585
3523
  dest.on('unpipe', onunpipe);
3586
-
3587
3524
  function onunpipe(readable, unpipeInfo) {
3588
3525
  debug('onunpipe');
3589
-
3590
3526
  if (readable === src) {
3591
3527
  if (unpipeInfo && unpipeInfo.hasUnpiped === false) {
3592
3528
  unpipeInfo.hasUnpiped = true;
@@ -3594,23 +3530,21 @@ Readable.prototype.pipe = function (dest, pipeOpts) {
3594
3530
  }
3595
3531
  }
3596
3532
  }
3597
-
3598
3533
  function onend() {
3599
3534
  debug('onend');
3600
3535
  dest.end();
3601
- } // when the dest drains, it reduces the awaitDrain counter
3536
+ }
3537
+
3538
+ // when the dest drains, it reduces the awaitDrain counter
3602
3539
  // on the source. This would be more elegant with a .once()
3603
3540
  // handler in flow(), but adding and removing repeatedly is
3604
3541
  // too slow.
3605
-
3606
-
3607
3542
  var ondrain = pipeOnDrain(src);
3608
3543
  dest.on('drain', ondrain);
3609
3544
  var cleanedUp = false;
3610
-
3611
3545
  function cleanup() {
3612
- debug('cleanup'); // cleanup event handlers once the pipe is broken
3613
-
3546
+ debug('cleanup');
3547
+ // cleanup event handlers once the pipe is broken
3614
3548
  dest.removeListener('close', onclose);
3615
3549
  dest.removeListener('finish', onfinish);
3616
3550
  dest.removeListener('drain', ondrain);
@@ -3619,22 +3553,20 @@ Readable.prototype.pipe = function (dest, pipeOpts) {
3619
3553
  src.removeListener('end', onend);
3620
3554
  src.removeListener('end', unpipe);
3621
3555
  src.removeListener('data', ondata);
3622
- cleanedUp = true; // if the reader is waiting for a drain event from this
3556
+ cleanedUp = true;
3557
+
3558
+ // if the reader is waiting for a drain event from this
3623
3559
  // specific writer, then it would cause it to never start
3624
3560
  // flowing again.
3625
3561
  // So, if this is awaiting a drain, then we just call it now.
3626
3562
  // If we don't know, then assume that we are waiting for one.
3627
-
3628
3563
  if (state.awaitDrain && (!dest._writableState || dest._writableState.needDrain)) ondrain();
3629
3564
  }
3630
-
3631
3565
  src.on('data', ondata);
3632
-
3633
3566
  function ondata(chunk) {
3634
3567
  debug('ondata');
3635
3568
  var ret = dest.write(chunk);
3636
3569
  debug('dest.write', ret);
3637
-
3638
3570
  if (ret === false) {
3639
3571
  // If the user unpiped during `dest.write()`, it is possible
3640
3572
  // to get stuck in a permanently paused state if that write
@@ -3644,87 +3576,84 @@ Readable.prototype.pipe = function (dest, pipeOpts) {
3644
3576
  debug('false write response, pause', state.awaitDrain);
3645
3577
  state.awaitDrain++;
3646
3578
  }
3647
-
3648
3579
  src.pause();
3649
3580
  }
3650
- } // if the dest has an error, then stop piping into it.
3651
- // however, don't suppress the throwing behavior for this.
3652
-
3581
+ }
3653
3582
 
3583
+ // if the dest has an error, then stop piping into it.
3584
+ // however, don't suppress the throwing behavior for this.
3654
3585
  function onerror(er) {
3655
3586
  debug('onerror', er);
3656
3587
  unpipe();
3657
3588
  dest.removeListener('error', onerror);
3658
3589
  if (EElistenerCount(dest, 'error') === 0) errorOrDestroy(dest, er);
3659
- } // Make sure our error handler is attached before userland ones.
3660
-
3590
+ }
3661
3591
 
3662
- prependListener(dest, 'error', onerror); // Both close and finish should trigger unpipe, but only once.
3592
+ // Make sure our error handler is attached before userland ones.
3593
+ prependListener(dest, 'error', onerror);
3663
3594
 
3595
+ // Both close and finish should trigger unpipe, but only once.
3664
3596
  function onclose() {
3665
3597
  dest.removeListener('finish', onfinish);
3666
3598
  unpipe();
3667
3599
  }
3668
-
3669
3600
  dest.once('close', onclose);
3670
-
3671
3601
  function onfinish() {
3672
3602
  debug('onfinish');
3673
3603
  dest.removeListener('close', onclose);
3674
3604
  unpipe();
3675
3605
  }
3676
-
3677
3606
  dest.once('finish', onfinish);
3678
-
3679
3607
  function unpipe() {
3680
3608
  debug('unpipe');
3681
3609
  src.unpipe(dest);
3682
- } // tell the dest that it's being piped to
3683
-
3610
+ }
3684
3611
 
3685
- dest.emit('pipe', src); // start the flow if it hasn't been started already.
3612
+ // tell the dest that it's being piped to
3613
+ dest.emit('pipe', src);
3686
3614
 
3615
+ // start the flow if it hasn't been started already.
3687
3616
  if (!state.flowing) {
3688
3617
  debug('pipe resume');
3689
3618
  src.resume();
3690
3619
  }
3691
-
3692
3620
  return dest;
3693
3621
  };
3694
-
3695
3622
  function pipeOnDrain(src) {
3696
3623
  return function pipeOnDrainFunctionResult() {
3697
3624
  var state = src._readableState;
3698
3625
  debug('pipeOnDrain', state.awaitDrain);
3699
3626
  if (state.awaitDrain) state.awaitDrain--;
3700
-
3701
3627
  if (state.awaitDrain === 0 && EElistenerCount(src, 'data')) {
3702
3628
  state.flowing = true;
3703
3629
  flow(src);
3704
3630
  }
3705
3631
  };
3706
3632
  }
3707
-
3708
3633
  Readable.prototype.unpipe = function (dest) {
3709
3634
  var state = this._readableState;
3710
3635
  var unpipeInfo = {
3711
3636
  hasUnpiped: false
3712
- }; // if we're not piping anywhere, then do nothing.
3637
+ };
3713
3638
 
3714
- if (state.pipesCount === 0) return this; // just one destination. most common case.
3639
+ // if we're not piping anywhere, then do nothing.
3640
+ if (state.pipesCount === 0) return this;
3715
3641
 
3642
+ // just one destination. most common case.
3716
3643
  if (state.pipesCount === 1) {
3717
3644
  // passed in one, but it's not the right one.
3718
3645
  if (dest && dest !== state.pipes) return this;
3719
- if (!dest) dest = state.pipes; // got a match.
3646
+ if (!dest) dest = state.pipes;
3720
3647
 
3648
+ // got a match.
3721
3649
  state.pipes = null;
3722
3650
  state.pipesCount = 0;
3723
3651
  state.flowing = false;
3724
3652
  if (dest) dest.emit('unpipe', this, unpipeInfo);
3725
3653
  return this;
3726
- } // slow case. multiple pipe destinations.
3654
+ }
3727
3655
 
3656
+ // slow case. multiple pipe destinations.
3728
3657
 
3729
3658
  if (!dest) {
3730
3659
  // remove all.
@@ -3733,17 +3662,13 @@ Readable.prototype.unpipe = function (dest) {
3733
3662
  state.pipes = null;
3734
3663
  state.pipesCount = 0;
3735
3664
  state.flowing = false;
3736
-
3737
- for (var i = 0; i < len; i++) {
3738
- dests[i].emit('unpipe', this, {
3739
- hasUnpiped: false
3740
- });
3741
- }
3742
-
3665
+ for (var i = 0; i < len; i++) dests[i].emit('unpipe', this, {
3666
+ hasUnpiped: false
3667
+ });
3743
3668
  return this;
3744
- } // try to find the right one.
3745
-
3669
+ }
3746
3670
 
3671
+ // try to find the right one.
3747
3672
  var index = indexOf(state.pipes, dest);
3748
3673
  if (index === -1) return this;
3749
3674
  state.pipes.splice(index, 1);
@@ -3751,19 +3676,19 @@ Readable.prototype.unpipe = function (dest) {
3751
3676
  if (state.pipesCount === 1) state.pipes = state.pipes[0];
3752
3677
  dest.emit('unpipe', this, unpipeInfo);
3753
3678
  return this;
3754
- }; // set up data events if they are asked for
3755
- // Ensure readable listeners eventually get something
3756
-
3679
+ };
3757
3680
 
3681
+ // set up data events if they are asked for
3682
+ // Ensure readable listeners eventually get something
3758
3683
  Readable.prototype.on = function (ev, fn) {
3759
3684
  var res = Stream.prototype.on.call(this, ev, fn);
3760
3685
  var state = this._readableState;
3761
-
3762
3686
  if (ev === 'data') {
3763
3687
  // update readableListening so that resume() may be a no-op
3764
3688
  // a few lines down. This is needed to support once('readable').
3765
- state.readableListening = this.listenerCount('readable') > 0; // Try start flowing on next tick if stream isn't explicitly paused
3689
+ state.readableListening = this.listenerCount('readable') > 0;
3766
3690
 
3691
+ // Try start flowing on next tick if stream isn't explicitly paused
3767
3692
  if (state.flowing !== false) this.resume();
3768
3693
  } else if (ev === 'readable') {
3769
3694
  if (!state.endEmitted && !state.readableListening) {
@@ -3771,7 +3696,6 @@ Readable.prototype.on = function (ev, fn) {
3771
3696
  state.flowing = false;
3772
3697
  state.emittedReadable = false;
3773
3698
  debug('on readable', state.length, state.reading);
3774
-
3775
3699
  if (state.length) {
3776
3700
  emitReadable(this);
3777
3701
  } else if (!state.reading) {
@@ -3779,15 +3703,11 @@ Readable.prototype.on = function (ev, fn) {
3779
3703
  }
3780
3704
  }
3781
3705
  }
3782
-
3783
3706
  return res;
3784
3707
  };
3785
-
3786
3708
  Readable.prototype.addListener = Readable.prototype.on;
3787
-
3788
3709
  Readable.prototype.removeListener = function (ev, fn) {
3789
3710
  var res = Stream.prototype.removeListener.call(this, ev, fn);
3790
-
3791
3711
  if (ev === 'readable') {
3792
3712
  // We need to check if there is someone still listening to
3793
3713
  // readable and reset the state. However this needs to happen
@@ -3797,13 +3717,10 @@ Readable.prototype.removeListener = function (ev, fn) {
3797
3717
  // effect.
3798
3718
  process.nextTick(updateReadableListening, this);
3799
3719
  }
3800
-
3801
3720
  return res;
3802
3721
  };
3803
-
3804
3722
  Readable.prototype.removeAllListeners = function (ev) {
3805
3723
  var res = Stream.prototype.removeAllListeners.apply(this, arguments);
3806
-
3807
3724
  if (ev === 'readable' || ev === undefined) {
3808
3725
  // We need to check if there is someone still listening to
3809
3726
  // readable and reset the state. However this needs to happen
@@ -3813,121 +3730,103 @@ Readable.prototype.removeAllListeners = function (ev) {
3813
3730
  // effect.
3814
3731
  process.nextTick(updateReadableListening, this);
3815
3732
  }
3816
-
3817
3733
  return res;
3818
3734
  };
3819
-
3820
3735
  function updateReadableListening(self) {
3821
3736
  var state = self._readableState;
3822
3737
  state.readableListening = self.listenerCount('readable') > 0;
3823
-
3824
3738
  if (state.resumeScheduled && !state.paused) {
3825
3739
  // flowing needs to be set to true now, otherwise
3826
3740
  // the upcoming resume will not flow.
3827
- state.flowing = true; // crude way to check if we should resume
3741
+ state.flowing = true;
3742
+
3743
+ // crude way to check if we should resume
3828
3744
  } else if (self.listenerCount('data') > 0) {
3829
3745
  self.resume();
3830
3746
  }
3831
3747
  }
3832
-
3833
3748
  function nReadingNextTick(self) {
3834
3749
  debug('readable nexttick read 0');
3835
3750
  self.read(0);
3836
- } // pause() and resume() are remnants of the legacy readable stream API
3837
- // If the user uses them, then switch into old mode.
3838
-
3751
+ }
3839
3752
 
3753
+ // pause() and resume() are remnants of the legacy readable stream API
3754
+ // If the user uses them, then switch into old mode.
3840
3755
  Readable.prototype.resume = function () {
3841
3756
  var state = this._readableState;
3842
-
3843
3757
  if (!state.flowing) {
3844
- debug('resume'); // we flow only if there is no one listening
3758
+ debug('resume');
3759
+ // we flow only if there is no one listening
3845
3760
  // for readable, but we still have to call
3846
3761
  // resume()
3847
-
3848
3762
  state.flowing = !state.readableListening;
3849
3763
  resume(this, state);
3850
3764
  }
3851
-
3852
3765
  state.paused = false;
3853
3766
  return this;
3854
3767
  };
3855
-
3856
3768
  function resume(stream, state) {
3857
3769
  if (!state.resumeScheduled) {
3858
3770
  state.resumeScheduled = true;
3859
3771
  process.nextTick(resume_, stream, state);
3860
3772
  }
3861
3773
  }
3862
-
3863
3774
  function resume_(stream, state) {
3864
3775
  debug('resume', state.reading);
3865
-
3866
3776
  if (!state.reading) {
3867
3777
  stream.read(0);
3868
3778
  }
3869
-
3870
3779
  state.resumeScheduled = false;
3871
3780
  stream.emit('resume');
3872
3781
  flow(stream);
3873
3782
  if (state.flowing && !state.reading) stream.read(0);
3874
3783
  }
3875
-
3876
3784
  Readable.prototype.pause = function () {
3877
3785
  debug('call pause flowing=%j', this._readableState.flowing);
3878
-
3879
3786
  if (this._readableState.flowing !== false) {
3880
3787
  debug('pause');
3881
3788
  this._readableState.flowing = false;
3882
3789
  this.emit('pause');
3883
3790
  }
3884
-
3885
3791
  this._readableState.paused = true;
3886
3792
  return this;
3887
3793
  };
3888
-
3889
3794
  function flow(stream) {
3890
3795
  var state = stream._readableState;
3891
3796
  debug('flow', state.flowing);
3797
+ while (state.flowing && stream.read() !== null);
3798
+ }
3892
3799
 
3893
- while (state.flowing && stream.read() !== null) {
3894
- ;
3895
- }
3896
- } // wrap an old-style stream as the async data source.
3800
+ // wrap an old-style stream as the async data source.
3897
3801
  // This is *not* part of the readable stream interface.
3898
3802
  // It is an ugly unfortunate mess of history.
3899
-
3900
-
3901
3803
  Readable.prototype.wrap = function (stream) {
3902
3804
  var _this = this;
3903
-
3904
3805
  var state = this._readableState;
3905
3806
  var paused = false;
3906
3807
  stream.on('end', function () {
3907
3808
  debug('wrapped end');
3908
-
3909
3809
  if (state.decoder && !state.ended) {
3910
3810
  var chunk = state.decoder.end();
3911
3811
  if (chunk && chunk.length) _this.push(chunk);
3912
3812
  }
3913
-
3914
3813
  _this.push(null);
3915
3814
  });
3916
3815
  stream.on('data', function (chunk) {
3917
3816
  debug('wrapped data');
3918
- if (state.decoder) chunk = state.decoder.write(chunk); // don't skip over falsy values in objectMode
3817
+ if (state.decoder) chunk = state.decoder.write(chunk);
3919
3818
 
3819
+ // don't skip over falsy values in objectMode
3920
3820
  if (state.objectMode && (chunk === null || chunk === undefined)) return;else if (!state.objectMode && (!chunk || !chunk.length)) return;
3921
-
3922
3821
  var ret = _this.push(chunk);
3923
-
3924
3822
  if (!ret) {
3925
3823
  paused = true;
3926
3824
  stream.pause();
3927
3825
  }
3928
- }); // proxy all the other methods.
3929
- // important when wrapping filters and duplexes.
3826
+ });
3930
3827
 
3828
+ // proxy all the other methods.
3829
+ // important when wrapping filters and duplexes.
3931
3830
  for (var i in stream) {
3932
3831
  if (this[i] === undefined && typeof stream[i] === 'function') {
3933
3832
  this[i] = function methodWrap(method) {
@@ -3936,37 +3835,32 @@ Readable.prototype.wrap = function (stream) {
3936
3835
  };
3937
3836
  }(i);
3938
3837
  }
3939
- } // proxy certain important events.
3940
-
3838
+ }
3941
3839
 
3840
+ // proxy certain important events.
3942
3841
  for (var n = 0; n < kProxyEvents.length; n++) {
3943
3842
  stream.on(kProxyEvents[n], this.emit.bind(this, kProxyEvents[n]));
3944
- } // when we try to consume some more bytes, simply unpause the
3945
- // underlying stream.
3946
-
3843
+ }
3947
3844
 
3845
+ // when we try to consume some more bytes, simply unpause the
3846
+ // underlying stream.
3948
3847
  this._read = function (n) {
3949
3848
  debug('wrapped _read', n);
3950
-
3951
3849
  if (paused) {
3952
3850
  paused = false;
3953
3851
  stream.resume();
3954
3852
  }
3955
3853
  };
3956
-
3957
3854
  return this;
3958
3855
  };
3959
-
3960
3856
  if (typeof Symbol === 'function') {
3961
3857
  Readable.prototype[Symbol.asyncIterator] = function () {
3962
3858
  if (createReadableStreamAsyncIterator === undefined) {
3963
3859
  createReadableStreamAsyncIterator = __nccwpck_require__(3306);
3964
3860
  }
3965
-
3966
3861
  return createReadableStreamAsyncIterator(this);
3967
3862
  };
3968
3863
  }
3969
-
3970
3864
  Object.defineProperty(Readable.prototype, 'readableHighWaterMark', {
3971
3865
  // making it explicit this property is not enumerable
3972
3866
  // because otherwise some prototype manipulation in
@@ -3998,8 +3892,9 @@ Object.defineProperty(Readable.prototype, 'readableFlowing', {
3998
3892
  this._readableState.flowing = state;
3999
3893
  }
4000
3894
  }
4001
- }); // exposed for testing purposes only.
3895
+ });
4002
3896
 
3897
+ // exposed for testing purposes only.
4003
3898
  Readable._fromList = fromList;
4004
3899
  Object.defineProperty(Readable.prototype, 'readableLength', {
4005
3900
  // making it explicit this property is not enumerable
@@ -4009,11 +3904,12 @@ Object.defineProperty(Readable.prototype, 'readableLength', {
4009
3904
  get: function get() {
4010
3905
  return this._readableState.length;
4011
3906
  }
4012
- }); // Pluck off n bytes from an array of buffers.
3907
+ });
3908
+
3909
+ // Pluck off n bytes from an array of buffers.
4013
3910
  // Length is the combined lengths of all the buffers in the list.
4014
3911
  // This function is designed to be inlinable, so please take care when making
4015
3912
  // changes to the function body.
4016
-
4017
3913
  function fromList(n, state) {
4018
3914
  // nothing buffered
4019
3915
  if (state.length === 0) return null;
@@ -4028,52 +3924,44 @@ function fromList(n, state) {
4028
3924
  }
4029
3925
  return ret;
4030
3926
  }
4031
-
4032
3927
  function endReadable(stream) {
4033
3928
  var state = stream._readableState;
4034
3929
  debug('endReadable', state.endEmitted);
4035
-
4036
3930
  if (!state.endEmitted) {
4037
3931
  state.ended = true;
4038
3932
  process.nextTick(endReadableNT, state, stream);
4039
3933
  }
4040
3934
  }
4041
-
4042
3935
  function endReadableNT(state, stream) {
4043
- debug('endReadableNT', state.endEmitted, state.length); // Check that we didn't get one last unshift.
3936
+ debug('endReadableNT', state.endEmitted, state.length);
4044
3937
 
3938
+ // Check that we didn't get one last unshift.
4045
3939
  if (!state.endEmitted && state.length === 0) {
4046
3940
  state.endEmitted = true;
4047
3941
  stream.readable = false;
4048
3942
  stream.emit('end');
4049
-
4050
3943
  if (state.autoDestroy) {
4051
3944
  // In case of duplex streams we need a way to detect
4052
3945
  // if the writable side is ready for autoDestroy as well
4053
3946
  var wState = stream._writableState;
4054
-
4055
3947
  if (!wState || wState.autoDestroy && wState.finished) {
4056
3948
  stream.destroy();
4057
3949
  }
4058
3950
  }
4059
3951
  }
4060
3952
  }
4061
-
4062
3953
  if (typeof Symbol === 'function') {
4063
3954
  Readable.from = function (iterable, opts) {
4064
3955
  if (from === undefined) {
4065
3956
  from = __nccwpck_require__(5621);
4066
3957
  }
4067
-
4068
3958
  return from(Readable, iterable, opts);
4069
3959
  };
4070
3960
  }
4071
-
4072
3961
  function indexOf(xs, x) {
4073
3962
  for (var i = 0, l = xs.length; i < l; i++) {
4074
3963
  if (xs[i] === x) return i;
4075
3964
  }
4076
-
4077
3965
  return -1;
4078
3966
  }
4079
3967
 
@@ -4102,6 +3990,7 @@ function indexOf(xs, x) {
4102
3990
  // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
4103
3991
  // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
4104
3992
  // USE OR OTHER DEALINGS IN THE SOFTWARE.
3993
+
4105
3994
  // a transform stream is a readable/writable stream where you do
4106
3995
  // something with the data. Sometimes it's called a "filter",
4107
3996
  // but that's not a great name for it, since that implies a thing where
@@ -4145,40 +4034,34 @@ function indexOf(xs, x) {
4145
4034
  // the results of the previous transformed chunk were consumed.
4146
4035
 
4147
4036
 
4148
- module.exports = Transform;
4149
4037
 
4038
+ module.exports = Transform;
4150
4039
  var _require$codes = (__nccwpck_require__(7214)/* .codes */ .q),
4151
- ERR_METHOD_NOT_IMPLEMENTED = _require$codes.ERR_METHOD_NOT_IMPLEMENTED,
4152
- ERR_MULTIPLE_CALLBACK = _require$codes.ERR_MULTIPLE_CALLBACK,
4153
- ERR_TRANSFORM_ALREADY_TRANSFORMING = _require$codes.ERR_TRANSFORM_ALREADY_TRANSFORMING,
4154
- ERR_TRANSFORM_WITH_LENGTH_0 = _require$codes.ERR_TRANSFORM_WITH_LENGTH_0;
4155
-
4040
+ ERR_METHOD_NOT_IMPLEMENTED = _require$codes.ERR_METHOD_NOT_IMPLEMENTED,
4041
+ ERR_MULTIPLE_CALLBACK = _require$codes.ERR_MULTIPLE_CALLBACK,
4042
+ ERR_TRANSFORM_ALREADY_TRANSFORMING = _require$codes.ERR_TRANSFORM_ALREADY_TRANSFORMING,
4043
+ ERR_TRANSFORM_WITH_LENGTH_0 = _require$codes.ERR_TRANSFORM_WITH_LENGTH_0;
4156
4044
  var Duplex = __nccwpck_require__(1359);
4157
-
4158
4045
  __nccwpck_require__(4124)(Transform, Duplex);
4159
-
4160
4046
  function afterTransform(er, data) {
4161
4047
  var ts = this._transformState;
4162
4048
  ts.transforming = false;
4163
4049
  var cb = ts.writecb;
4164
-
4165
4050
  if (cb === null) {
4166
4051
  return this.emit('error', new ERR_MULTIPLE_CALLBACK());
4167
4052
  }
4168
-
4169
4053
  ts.writechunk = null;
4170
4054
  ts.writecb = null;
4171
- if (data != null) // single equals check for both `null` and `undefined`
4055
+ if (data != null)
4056
+ // single equals check for both `null` and `undefined`
4172
4057
  this.push(data);
4173
4058
  cb(er);
4174
4059
  var rs = this._readableState;
4175
4060
  rs.reading = false;
4176
-
4177
4061
  if (rs.needReadable || rs.length < rs.highWaterMark) {
4178
4062
  this._read(rs.highWaterMark);
4179
4063
  }
4180
4064
  }
4181
-
4182
4065
  function Transform(options) {
4183
4066
  if (!(this instanceof Transform)) return new Transform(options);
4184
4067
  Duplex.call(this, options);
@@ -4189,26 +4072,25 @@ function Transform(options) {
4189
4072
  writecb: null,
4190
4073
  writechunk: null,
4191
4074
  writeencoding: null
4192
- }; // start out asking for a readable event once data is transformed.
4075
+ };
4076
+
4077
+ // start out asking for a readable event once data is transformed.
4078
+ this._readableState.needReadable = true;
4193
4079
 
4194
- this._readableState.needReadable = true; // we have implemented the _read method, and done the other things
4080
+ // we have implemented the _read method, and done the other things
4195
4081
  // that Readable wants before the first _read call, so unset the
4196
4082
  // sync guard flag.
4197
-
4198
4083
  this._readableState.sync = false;
4199
-
4200
4084
  if (options) {
4201
4085
  if (typeof options.transform === 'function') this._transform = options.transform;
4202
4086
  if (typeof options.flush === 'function') this._flush = options.flush;
4203
- } // When the writable side finishes, then flush out anything remaining.
4204
-
4087
+ }
4205
4088
 
4089
+ // When the writable side finishes, then flush out anything remaining.
4206
4090
  this.on('prefinish', prefinish);
4207
4091
  }
4208
-
4209
4092
  function prefinish() {
4210
4093
  var _this = this;
4211
-
4212
4094
  if (typeof this._flush === 'function' && !this._readableState.destroyed) {
4213
4095
  this._flush(function (er, data) {
4214
4096
  done(_this, er, data);
@@ -4217,11 +4099,12 @@ function prefinish() {
4217
4099
  done(this, null, null);
4218
4100
  }
4219
4101
  }
4220
-
4221
4102
  Transform.prototype.push = function (chunk, encoding) {
4222
4103
  this._transformState.needTransform = false;
4223
4104
  return Duplex.prototype.push.call(this, chunk, encoding);
4224
- }; // This is the part where you do stuff!
4105
+ };
4106
+
4107
+ // This is the part where you do stuff!
4225
4108
  // override this function in implementation classes.
4226
4109
  // 'chunk' is an input chunk.
4227
4110
  //
@@ -4231,33 +4114,27 @@ Transform.prototype.push = function (chunk, encoding) {
4231
4114
  // Call `cb(err)` when you are done with this chunk. If you pass
4232
4115
  // an error, then that'll put the hurt on the whole operation. If you
4233
4116
  // never call cb(), then you'll never get another chunk.
4234
-
4235
-
4236
4117
  Transform.prototype._transform = function (chunk, encoding, cb) {
4237
4118
  cb(new ERR_METHOD_NOT_IMPLEMENTED('_transform()'));
4238
4119
  };
4239
-
4240
4120
  Transform.prototype._write = function (chunk, encoding, cb) {
4241
4121
  var ts = this._transformState;
4242
4122
  ts.writecb = cb;
4243
4123
  ts.writechunk = chunk;
4244
4124
  ts.writeencoding = encoding;
4245
-
4246
4125
  if (!ts.transforming) {
4247
4126
  var rs = this._readableState;
4248
4127
  if (ts.needTransform || rs.needReadable || rs.length < rs.highWaterMark) this._read(rs.highWaterMark);
4249
4128
  }
4250
- }; // Doesn't matter what the args are here.
4129
+ };
4130
+
4131
+ // Doesn't matter what the args are here.
4251
4132
  // _transform does all the work.
4252
4133
  // That we got here means that the readable side wants more data.
4253
-
4254
-
4255
4134
  Transform.prototype._read = function (n) {
4256
4135
  var ts = this._transformState;
4257
-
4258
4136
  if (ts.writechunk !== null && !ts.transforming) {
4259
4137
  ts.transforming = true;
4260
-
4261
4138
  this._transform(ts.writechunk, ts.writeencoding, ts.afterTransform);
4262
4139
  } else {
4263
4140
  // mark that we need a transform, so that any data that comes in
@@ -4265,20 +4142,20 @@ Transform.prototype._read = function (n) {
4265
4142
  ts.needTransform = true;
4266
4143
  }
4267
4144
  };
4268
-
4269
4145
  Transform.prototype._destroy = function (err, cb) {
4270
4146
  Duplex.prototype._destroy.call(this, err, function (err2) {
4271
4147
  cb(err2);
4272
4148
  });
4273
4149
  };
4274
-
4275
4150
  function done(stream, er, data) {
4276
4151
  if (er) return stream.emit('error', er);
4277
- if (data != null) // single equals check for both `null` and `undefined`
4278
- stream.push(data); // TODO(BridgeAR): Write a test for these two error cases
4152
+ if (data != null)
4153
+ // single equals check for both `null` and `undefined`
4154
+ stream.push(data);
4155
+
4156
+ // TODO(BridgeAR): Write a test for these two error cases
4279
4157
  // if there's nothing in the write buffer, then that means
4280
4158
  // that nothing more will ever be provided
4281
-
4282
4159
  if (stream._writableState.length) throw new ERR_TRANSFORM_WITH_LENGTH_0();
4283
4160
  if (stream._transformState.transforming) throw new ERR_TRANSFORM_ALREADY_TRANSFORMING();
4284
4161
  return stream.push(null);
@@ -4309,29 +4186,29 @@ function done(stream, er, data) {
4309
4186
  // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
4310
4187
  // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
4311
4188
  // USE OR OTHER DEALINGS IN THE SOFTWARE.
4189
+
4312
4190
  // A bit simpler than readable streams.
4313
4191
  // Implement an async ._write(chunk, encoding, cb), and it'll handle all
4314
4192
  // the drain event emission and buffering.
4315
4193
 
4316
4194
 
4195
+
4317
4196
  module.exports = Writable;
4318
- /* <replacement> */
4319
4197
 
4198
+ /* <replacement> */
4320
4199
  function WriteReq(chunk, encoding, cb) {
4321
4200
  this.chunk = chunk;
4322
4201
  this.encoding = encoding;
4323
4202
  this.callback = cb;
4324
4203
  this.next = null;
4325
- } // It seems a linked list but it is not
4326
- // there will be only 2 of these for each stream
4327
-
4204
+ }
4328
4205
 
4206
+ // It seems a linked list but it is not
4207
+ // there will be only 2 of these for each stream
4329
4208
  function CorkedRequest(state) {
4330
4209
  var _this = this;
4331
-
4332
4210
  this.next = null;
4333
4211
  this.entry = null;
4334
-
4335
4212
  this.finish = function () {
4336
4213
  onCorkedFinish(_this, state);
4337
4214
  };
@@ -4339,155 +4216,159 @@ function CorkedRequest(state) {
4339
4216
  /* </replacement> */
4340
4217
 
4341
4218
  /*<replacement>*/
4342
-
4343
-
4344
4219
  var Duplex;
4345
4220
  /*</replacement>*/
4346
4221
 
4347
4222
  Writable.WritableState = WritableState;
4348
- /*<replacement>*/
4349
4223
 
4224
+ /*<replacement>*/
4350
4225
  var internalUtil = {
4351
4226
  deprecate: __nccwpck_require__(5278)
4352
4227
  };
4353
4228
  /*</replacement>*/
4354
4229
 
4355
4230
  /*<replacement>*/
4356
-
4357
4231
  var Stream = __nccwpck_require__(2387);
4358
4232
  /*</replacement>*/
4359
4233
 
4360
-
4361
4234
  var Buffer = (__nccwpck_require__(4300).Buffer);
4362
-
4363
- var OurUint8Array = global.Uint8Array || function () {};
4364
-
4235
+ var OurUint8Array = (typeof global !== 'undefined' ? global : typeof window !== 'undefined' ? window : typeof self !== 'undefined' ? self : {}).Uint8Array || function () {};
4365
4236
  function _uint8ArrayToBuffer(chunk) {
4366
4237
  return Buffer.from(chunk);
4367
4238
  }
4368
-
4369
4239
  function _isUint8Array(obj) {
4370
4240
  return Buffer.isBuffer(obj) || obj instanceof OurUint8Array;
4371
4241
  }
4372
-
4373
4242
  var destroyImpl = __nccwpck_require__(7049);
4374
-
4375
4243
  var _require = __nccwpck_require__(9948),
4376
- getHighWaterMark = _require.getHighWaterMark;
4377
-
4244
+ getHighWaterMark = _require.getHighWaterMark;
4378
4245
  var _require$codes = (__nccwpck_require__(7214)/* .codes */ .q),
4379
- ERR_INVALID_ARG_TYPE = _require$codes.ERR_INVALID_ARG_TYPE,
4380
- ERR_METHOD_NOT_IMPLEMENTED = _require$codes.ERR_METHOD_NOT_IMPLEMENTED,
4381
- ERR_MULTIPLE_CALLBACK = _require$codes.ERR_MULTIPLE_CALLBACK,
4382
- ERR_STREAM_CANNOT_PIPE = _require$codes.ERR_STREAM_CANNOT_PIPE,
4383
- ERR_STREAM_DESTROYED = _require$codes.ERR_STREAM_DESTROYED,
4384
- ERR_STREAM_NULL_VALUES = _require$codes.ERR_STREAM_NULL_VALUES,
4385
- ERR_STREAM_WRITE_AFTER_END = _require$codes.ERR_STREAM_WRITE_AFTER_END,
4386
- ERR_UNKNOWN_ENCODING = _require$codes.ERR_UNKNOWN_ENCODING;
4387
-
4246
+ ERR_INVALID_ARG_TYPE = _require$codes.ERR_INVALID_ARG_TYPE,
4247
+ ERR_METHOD_NOT_IMPLEMENTED = _require$codes.ERR_METHOD_NOT_IMPLEMENTED,
4248
+ ERR_MULTIPLE_CALLBACK = _require$codes.ERR_MULTIPLE_CALLBACK,
4249
+ ERR_STREAM_CANNOT_PIPE = _require$codes.ERR_STREAM_CANNOT_PIPE,
4250
+ ERR_STREAM_DESTROYED = _require$codes.ERR_STREAM_DESTROYED,
4251
+ ERR_STREAM_NULL_VALUES = _require$codes.ERR_STREAM_NULL_VALUES,
4252
+ ERR_STREAM_WRITE_AFTER_END = _require$codes.ERR_STREAM_WRITE_AFTER_END,
4253
+ ERR_UNKNOWN_ENCODING = _require$codes.ERR_UNKNOWN_ENCODING;
4388
4254
  var errorOrDestroy = destroyImpl.errorOrDestroy;
4389
-
4390
4255
  __nccwpck_require__(4124)(Writable, Stream);
4391
-
4392
4256
  function nop() {}
4393
-
4394
4257
  function WritableState(options, stream, isDuplex) {
4395
4258
  Duplex = Duplex || __nccwpck_require__(1359);
4396
- options = options || {}; // Duplex streams are both readable and writable, but share
4259
+ options = options || {};
4260
+
4261
+ // Duplex streams are both readable and writable, but share
4397
4262
  // the same options object.
4398
4263
  // However, some cases require setting options to different
4399
4264
  // values for the readable and the writable sides of the duplex stream,
4400
4265
  // e.g. options.readableObjectMode vs. options.writableObjectMode, etc.
4266
+ if (typeof isDuplex !== 'boolean') isDuplex = stream instanceof Duplex;
4401
4267
 
4402
- if (typeof isDuplex !== 'boolean') isDuplex = stream instanceof Duplex; // object stream flag to indicate whether or not this stream
4268
+ // object stream flag to indicate whether or not this stream
4403
4269
  // contains buffers or objects.
4404
-
4405
4270
  this.objectMode = !!options.objectMode;
4406
- if (isDuplex) this.objectMode = this.objectMode || !!options.writableObjectMode; // the point at which write() starts returning false
4271
+ if (isDuplex) this.objectMode = this.objectMode || !!options.writableObjectMode;
4272
+
4273
+ // the point at which write() starts returning false
4407
4274
  // Note: 0 is a valid value, means that we always return false if
4408
4275
  // the entire buffer is not flushed immediately on write()
4276
+ this.highWaterMark = getHighWaterMark(this, options, 'writableHighWaterMark', isDuplex);
4409
4277
 
4410
- this.highWaterMark = getHighWaterMark(this, options, 'writableHighWaterMark', isDuplex); // if _final has been called
4411
-
4412
- this.finalCalled = false; // drain event flag.
4278
+ // if _final has been called
4279
+ this.finalCalled = false;
4413
4280
 
4414
- this.needDrain = false; // at the start of calling end()
4415
-
4416
- this.ending = false; // when end() has been called, and returned
4417
-
4418
- this.ended = false; // when 'finish' is emitted
4281
+ // drain event flag.
4282
+ this.needDrain = false;
4283
+ // at the start of calling end()
4284
+ this.ending = false;
4285
+ // when end() has been called, and returned
4286
+ this.ended = false;
4287
+ // when 'finish' is emitted
4288
+ this.finished = false;
4419
4289
 
4420
- this.finished = false; // has it been destroyed
4290
+ // has it been destroyed
4291
+ this.destroyed = false;
4421
4292
 
4422
- this.destroyed = false; // should we decode strings into buffers before passing to _write?
4293
+ // should we decode strings into buffers before passing to _write?
4423
4294
  // this is here so that some node-core streams can optimize string
4424
4295
  // handling at a lower level.
4425
-
4426
4296
  var noDecode = options.decodeStrings === false;
4427
- this.decodeStrings = !noDecode; // Crypto is kind of old and crusty. Historically, its default string
4297
+ this.decodeStrings = !noDecode;
4298
+
4299
+ // Crypto is kind of old and crusty. Historically, its default string
4428
4300
  // encoding is 'binary' so we have to make this configurable.
4429
4301
  // Everything else in the universe uses 'utf8', though.
4302
+ this.defaultEncoding = options.defaultEncoding || 'utf8';
4430
4303
 
4431
- this.defaultEncoding = options.defaultEncoding || 'utf8'; // not an actual buffer we keep track of, but a measurement
4304
+ // not an actual buffer we keep track of, but a measurement
4432
4305
  // of how much we're waiting to get pushed to some underlying
4433
4306
  // socket or file.
4307
+ this.length = 0;
4434
4308
 
4435
- this.length = 0; // a flag to see when we're in the middle of a write.
4309
+ // a flag to see when we're in the middle of a write.
4310
+ this.writing = false;
4436
4311
 
4437
- this.writing = false; // when true all writes will be buffered until .uncork() call
4312
+ // when true all writes will be buffered until .uncork() call
4313
+ this.corked = 0;
4438
4314
 
4439
- this.corked = 0; // a flag to be able to tell if the onwrite cb is called immediately,
4315
+ // a flag to be able to tell if the onwrite cb is called immediately,
4440
4316
  // or on a later tick. We set this to true at first, because any
4441
4317
  // actions that shouldn't happen until "later" should generally also
4442
4318
  // not happen before the first write call.
4319
+ this.sync = true;
4443
4320
 
4444
- this.sync = true; // a flag to know if we're processing previously buffered items, which
4321
+ // a flag to know if we're processing previously buffered items, which
4445
4322
  // may call the _write() callback in the same tick, so that we don't
4446
4323
  // end up in an overlapped onwrite situation.
4324
+ this.bufferProcessing = false;
4447
4325
 
4448
- this.bufferProcessing = false; // the callback that's passed to _write(chunk,cb)
4449
-
4326
+ // the callback that's passed to _write(chunk,cb)
4450
4327
  this.onwrite = function (er) {
4451
4328
  onwrite(stream, er);
4452
- }; // the callback that the user supplies to write(chunk,encoding,cb)
4453
-
4329
+ };
4454
4330
 
4455
- this.writecb = null; // the amount that is being written when _write is called.
4331
+ // the callback that the user supplies to write(chunk,encoding,cb)
4332
+ this.writecb = null;
4456
4333
 
4334
+ // the amount that is being written when _write is called.
4457
4335
  this.writelen = 0;
4458
4336
  this.bufferedRequest = null;
4459
- this.lastBufferedRequest = null; // number of pending user-supplied write callbacks
4337
+ this.lastBufferedRequest = null;
4338
+
4339
+ // number of pending user-supplied write callbacks
4460
4340
  // this must be 0 before 'finish' can be emitted
4341
+ this.pendingcb = 0;
4461
4342
 
4462
- this.pendingcb = 0; // emit prefinish if the only thing we're waiting for is _write cbs
4343
+ // emit prefinish if the only thing we're waiting for is _write cbs
4463
4344
  // This is relevant for synchronous Transform streams
4345
+ this.prefinished = false;
4464
4346
 
4465
- this.prefinished = false; // True if the error was already emitted and should not be thrown again
4347
+ // True if the error was already emitted and should not be thrown again
4348
+ this.errorEmitted = false;
4466
4349
 
4467
- this.errorEmitted = false; // Should close be emitted on destroy. Defaults to true.
4350
+ // Should close be emitted on destroy. Defaults to true.
4351
+ this.emitClose = options.emitClose !== false;
4468
4352
 
4469
- this.emitClose = options.emitClose !== false; // Should .destroy() be called after 'finish' (and potentially 'end')
4353
+ // Should .destroy() be called after 'finish' (and potentially 'end')
4354
+ this.autoDestroy = !!options.autoDestroy;
4470
4355
 
4471
- this.autoDestroy = !!options.autoDestroy; // count buffered requests
4356
+ // count buffered requests
4357
+ this.bufferedRequestCount = 0;
4472
4358
 
4473
- this.bufferedRequestCount = 0; // allocate the first CorkedRequest, there is always
4359
+ // allocate the first CorkedRequest, there is always
4474
4360
  // one allocated and free to use, and we maintain at most two
4475
-
4476
4361
  this.corkedRequestsFree = new CorkedRequest(this);
4477
4362
  }
4478
-
4479
4363
  WritableState.prototype.getBuffer = function getBuffer() {
4480
4364
  var current = this.bufferedRequest;
4481
4365
  var out = [];
4482
-
4483
4366
  while (current) {
4484
4367
  out.push(current);
4485
4368
  current = current.next;
4486
4369
  }
4487
-
4488
4370
  return out;
4489
4371
  };
4490
-
4491
4372
  (function () {
4492
4373
  try {
4493
4374
  Object.defineProperty(WritableState.prototype, 'buffer', {
@@ -4496,12 +4377,11 @@ WritableState.prototype.getBuffer = function getBuffer() {
4496
4377
  }, '_writableState.buffer is deprecated. Use _writableState.getBuffer ' + 'instead.', 'DEP0003')
4497
4378
  });
4498
4379
  } catch (_) {}
4499
- })(); // Test _writableState for inheritance to account for Duplex streams,
4500
- // whose prototype chain only points to Readable.
4501
-
4380
+ })();
4502
4381
 
4382
+ // Test _writableState for inheritance to account for Duplex streams,
4383
+ // whose prototype chain only points to Readable.
4503
4384
  var realHasInstance;
4504
-
4505
4385
  if (typeof Symbol === 'function' && Symbol.hasInstance && typeof Function.prototype[Symbol.hasInstance] === 'function') {
4506
4386
  realHasInstance = Function.prototype[Symbol.hasInstance];
4507
4387
  Object.defineProperty(Writable, Symbol.hasInstance, {
@@ -4516,81 +4396,73 @@ if (typeof Symbol === 'function' && Symbol.hasInstance && typeof Function.protot
4516
4396
  return object instanceof this;
4517
4397
  };
4518
4398
  }
4519
-
4520
4399
  function Writable(options) {
4521
- Duplex = Duplex || __nccwpck_require__(1359); // Writable ctor is applied to Duplexes, too.
4400
+ Duplex = Duplex || __nccwpck_require__(1359);
4401
+
4402
+ // Writable ctor is applied to Duplexes, too.
4522
4403
  // `realHasInstance` is necessary because using plain `instanceof`
4523
4404
  // would return false, as no `_writableState` property is attached.
4405
+
4524
4406
  // Trying to use the custom `instanceof` for Writable here will also break the
4525
4407
  // Node.js LazyTransform implementation, which has a non-trivial getter for
4526
4408
  // `_writableState` that would lead to infinite recursion.
4409
+
4527
4410
  // Checking for a Stream.Duplex instance is faster here instead of inside
4528
4411
  // the WritableState constructor, at least with V8 6.5
4529
-
4530
4412
  var isDuplex = this instanceof Duplex;
4531
4413
  if (!isDuplex && !realHasInstance.call(Writable, this)) return new Writable(options);
4532
- this._writableState = new WritableState(options, this, isDuplex); // legacy.
4414
+ this._writableState = new WritableState(options, this, isDuplex);
4533
4415
 
4416
+ // legacy.
4534
4417
  this.writable = true;
4535
-
4536
4418
  if (options) {
4537
4419
  if (typeof options.write === 'function') this._write = options.write;
4538
4420
  if (typeof options.writev === 'function') this._writev = options.writev;
4539
4421
  if (typeof options.destroy === 'function') this._destroy = options.destroy;
4540
4422
  if (typeof options.final === 'function') this._final = options.final;
4541
4423
  }
4542
-
4543
4424
  Stream.call(this);
4544
- } // Otherwise people can pipe Writable streams, which is just wrong.
4545
-
4425
+ }
4546
4426
 
4427
+ // Otherwise people can pipe Writable streams, which is just wrong.
4547
4428
  Writable.prototype.pipe = function () {
4548
4429
  errorOrDestroy(this, new ERR_STREAM_CANNOT_PIPE());
4549
4430
  };
4550
-
4551
4431
  function writeAfterEnd(stream, cb) {
4552
- var er = new ERR_STREAM_WRITE_AFTER_END(); // TODO: defer error events consistently everywhere, not just the cb
4553
-
4432
+ var er = new ERR_STREAM_WRITE_AFTER_END();
4433
+ // TODO: defer error events consistently everywhere, not just the cb
4554
4434
  errorOrDestroy(stream, er);
4555
4435
  process.nextTick(cb, er);
4556
- } // Checks that a user-supplied chunk is valid, especially for the particular
4436
+ }
4437
+
4438
+ // Checks that a user-supplied chunk is valid, especially for the particular
4557
4439
  // mode the stream is in. Currently this means that `null` is never accepted
4558
4440
  // and undefined/non-string values are only allowed in object mode.
4559
-
4560
-
4561
4441
  function validChunk(stream, state, chunk, cb) {
4562
4442
  var er;
4563
-
4564
4443
  if (chunk === null) {
4565
4444
  er = new ERR_STREAM_NULL_VALUES();
4566
4445
  } else if (typeof chunk !== 'string' && !state.objectMode) {
4567
4446
  er = new ERR_INVALID_ARG_TYPE('chunk', ['string', 'Buffer'], chunk);
4568
4447
  }
4569
-
4570
4448
  if (er) {
4571
4449
  errorOrDestroy(stream, er);
4572
4450
  process.nextTick(cb, er);
4573
4451
  return false;
4574
4452
  }
4575
-
4576
4453
  return true;
4577
4454
  }
4578
-
4579
4455
  Writable.prototype.write = function (chunk, encoding, cb) {
4580
4456
  var state = this._writableState;
4581
4457
  var ret = false;
4582
-
4583
4458
  var isBuf = !state.objectMode && _isUint8Array(chunk);
4584
-
4585
4459
  if (isBuf && !Buffer.isBuffer(chunk)) {
4586
4460
  chunk = _uint8ArrayToBuffer(chunk);
4587
4461
  }
4588
-
4589
4462
  if (typeof encoding === 'function') {
4590
4463
  cb = encoding;
4591
4464
  encoding = null;
4592
4465
  }
4593
-
4594
4466
  if (isBuf) encoding = 'buffer';else if (!encoding) encoding = state.defaultEncoding;
4595
4467
  if (typeof cb !== 'function') cb = nop;
4596
4468
  if (state.ending) writeAfterEnd(this, cb);else if (isBuf || validChunk(this, state, chunk, cb)) {
@@ -4599,20 +4471,16 @@ Writable.prototype.write = function (chunk, encoding, cb) {
4599
4471
  }
4600
4472
  return ret;
4601
4473
  };
4602
-
4603
4474
  Writable.prototype.cork = function () {
4604
4475
  this._writableState.corked++;
4605
4476
  };
4606
-
4607
4477
  Writable.prototype.uncork = function () {
4608
4478
  var state = this._writableState;
4609
-
4610
4479
  if (state.corked) {
4611
4480
  state.corked--;
4612
4481
  if (!state.writing && !state.corked && !state.bufferProcessing && state.bufferedRequest) clearBuffer(this, state);
4613
4482
  }
4614
4483
  };
4615
-
4616
4484
  Writable.prototype.setDefaultEncoding = function setDefaultEncoding(encoding) {
4617
4485
  // node::ParseEncoding() requires lower case.
4618
4486
  if (typeof encoding === 'string') encoding = encoding.toLowerCase();
@@ -4620,7 +4488,6 @@ Writable.prototype.setDefaultEncoding = function setDefaultEncoding(encoding) {
4620
4488
  this._writableState.defaultEncoding = encoding;
4621
4489
  return this;
4622
4490
  };
4623
-
4624
4491
  Object.defineProperty(Writable.prototype, 'writableBuffer', {
4625
4492
  // making it explicit this property is not enumerable
4626
4493
  // because otherwise some prototype manipulation in
@@ -4630,15 +4497,12 @@ Object.defineProperty(Writable.prototype, 'writableBuffer', {
4630
4497
  return this._writableState && this._writableState.getBuffer();
4631
4498
  }
4632
4499
  });
4633
-
4634
4500
  function decodeChunk(state, chunk, encoding) {
4635
4501
  if (!state.objectMode && state.decodeStrings !== false && typeof chunk === 'string') {
4636
4502
  chunk = Buffer.from(chunk, encoding);
4637
4503
  }
4638
-
4639
4504
  return chunk;
4640
4505
  }
4641
-
4642
4506
  Object.defineProperty(Writable.prototype, 'writableHighWaterMark', {
4643
4507
  // making it explicit this property is not enumerable
4644
4508
  // because otherwise some prototype manipulation in
@@ -4647,27 +4511,25 @@ Object.defineProperty(Writable.prototype, 'writableHighWaterMark', {
4647
4511
  get: function get() {
4648
4512
  return this._writableState.highWaterMark;
4649
4513
  }
4650
- }); // if we're already writing something, then just put this
4514
+ });
4515
+
4516
+ // if we're already writing something, then just put this
4651
4517
  // in the queue, and wait our turn. Otherwise, call _write
4652
4518
  // If we return false, then we need a drain event, so set that flag.
4653
-
4654
4519
  function writeOrBuffer(stream, state, isBuf, chunk, encoding, cb) {
4655
4520
  if (!isBuf) {
4656
4521
  var newChunk = decodeChunk(state, chunk, encoding);
4657
-
4658
4522
  if (chunk !== newChunk) {
4659
4523
  isBuf = true;
4660
4524
  encoding = 'buffer';
4661
4525
  chunk = newChunk;
4662
4526
  }
4663
4527
  }
4664
-
4665
4528
  var len = state.objectMode ? 1 : chunk.length;
4666
4529
  state.length += len;
4667
- var ret = state.length < state.highWaterMark; // we must ensure that previous needDrain will not be reset to false.
4668
-
4530
+ var ret = state.length < state.highWaterMark;
4531
+ // we must ensure that previous needDrain will not be reset to false.
4669
4532
  if (!ret) state.needDrain = true;
4670
-
4671
4533
  if (state.writing || state.corked) {
4672
4534
  var last = state.lastBufferedRequest;
4673
4535
  state.lastBufferedRequest = {
@@ -4677,21 +4539,17 @@ function writeOrBuffer(stream, state, isBuf, chunk, encoding, cb) {
4677
4539
  callback: cb,
4678
4540
  next: null
4679
4541
  };
4680
-
4681
4542
  if (last) {
4682
4543
  last.next = state.lastBufferedRequest;
4683
4544
  } else {
4684
4545
  state.bufferedRequest = state.lastBufferedRequest;
4685
4546
  }
4686
-
4687
4547
  state.bufferedRequestCount += 1;
4688
4548
  } else {
4689
4549
  doWrite(stream, state, false, len, chunk, encoding, cb);
4690
4550
  }
4691
-
4692
4551
  return ret;
4693
4552
  }
4694
-
4695
4553
  function doWrite(stream, state, writev, len, chunk, encoding, cb) {
4696
4554
  state.writelen = len;
4697
4555
  state.writecb = cb;
@@ -4700,16 +4558,14 @@ function doWrite(stream, state, writev, len, chunk, encoding, cb) {
4700
4558
  if (state.destroyed) state.onwrite(new ERR_STREAM_DESTROYED('write'));else if (writev) stream._writev(chunk, state.onwrite);else stream._write(chunk, encoding, state.onwrite);
4701
4559
  state.sync = false;
4702
4560
  }
4703
-
4704
4561
  function onwriteError(stream, state, sync, er, cb) {
4705
4562
  --state.pendingcb;
4706
-
4707
4563
  if (sync) {
4708
4564
  // defer the callback if we are being called synchronously
4709
4565
  // to avoid piling up things on the stack
4710
- process.nextTick(cb, er); // this can emit finish, and it will always happen
4566
+ process.nextTick(cb, er);
4567
+ // this can emit finish, and it will always happen
4711
4568
  // after error
4712
-
4713
4569
  process.nextTick(finishMaybe, stream, state);
4714
4570
  stream._writableState.errorEmitted = true;
4715
4571
  errorOrDestroy(stream, er);
@@ -4718,20 +4574,18 @@ function onwriteError(stream, state, sync, er, cb) {
4718
4574
  // it is async
4719
4575
  cb(er);
4720
4576
  stream._writableState.errorEmitted = true;
4721
- errorOrDestroy(stream, er); // this can emit finish, but finish must
4577
+ errorOrDestroy(stream, er);
4578
+ // this can emit finish, but finish must
4722
4579
  // always follow error
4723
-
4724
4580
  finishMaybe(stream, state);
4725
4581
  }
4726
4582
  }
4727
-
4728
4583
  function onwriteStateUpdate(state) {
4729
4584
  state.writing = false;
4730
4585
  state.writecb = null;
4731
4586
  state.length -= state.writelen;
4732
4587
  state.writelen = 0;
4733
4588
  }
4734
-
4735
4589
  function onwrite(stream, er) {
4736
4590
  var state = stream._writableState;
4737
4591
  var sync = state.sync;
@@ -4741,11 +4595,9 @@ function onwrite(stream, er) {
4741
4595
  if (er) onwriteError(stream, state, sync, er, cb);else {
4742
4596
  // Check if we're actually ready to finish, but don't emit yet
4743
4597
  var finished = needFinish(state) || stream.destroyed;
4744
-
4745
4598
  if (!finished && !state.corked && !state.bufferProcessing && state.bufferedRequest) {
4746
4599
  clearBuffer(stream, state);
4747
4600
  }
4748
-
4749
4601
  if (sync) {
4750
4602
  process.nextTick(afterWrite, stream, state, finished, cb);
4751
4603
  } else {
@@ -4753,29 +4605,27 @@ function onwrite(stream, er) {
4753
4605
  }
4754
4606
  }
4755
4607
  }
4756
-
4757
4608
  function afterWrite(stream, state, finished, cb) {
4758
4609
  if (!finished) onwriteDrain(stream, state);
4759
4610
  state.pendingcb--;
4760
4611
  cb();
4761
4612
  finishMaybe(stream, state);
4762
- } // Must force callback to be called on nextTick, so that we don't
4613
+ }
4614
+
4615
+ // Must force callback to be called on nextTick, so that we don't
4763
4616
  // emit 'drain' before the write() consumer gets the 'false' return
4764
4617
  // value, and has a chance to attach a 'drain' listener.
4765
-
4766
-
4767
4618
  function onwriteDrain(stream, state) {
4768
4619
  if (state.length === 0 && state.needDrain) {
4769
4620
  state.needDrain = false;
4770
4621
  stream.emit('drain');
4771
4622
  }
4772
- } // if there's something in the buffer waiting, then process it
4773
-
4623
+ }
4774
4624
 
4625
+ // if there's something in the buffer waiting, then process it
4775
4626
  function clearBuffer(stream, state) {
4776
4627
  state.bufferProcessing = true;
4777
4628
  var entry = state.bufferedRequest;
4778
-
4779
4629
  if (stream._writev && entry && entry.next) {
4780
4630
  // Fast case, write everything using _writev()
4781
4631
  var l = state.bufferedRequestCount;
@@ -4784,28 +4634,25 @@ function clearBuffer(stream, state) {
4784
4634
  holder.entry = entry;
4785
4635
  var count = 0;
4786
4636
  var allBuffers = true;
4787
-
4788
4637
  while (entry) {
4789
4638
  buffer[count] = entry;
4790
4639
  if (!entry.isBuf) allBuffers = false;
4791
4640
  entry = entry.next;
4792
4641
  count += 1;
4793
4642
  }
4794
-
4795
4643
  buffer.allBuffers = allBuffers;
4796
- doWrite(stream, state, true, state.length, buffer, '', holder.finish); // doWrite is almost always async, defer these to save a bit of time
4797
- // as the hot path ends with doWrite
4644
+ doWrite(stream, state, true, state.length, buffer, '', holder.finish);
4798
4645
 
4646
+ // doWrite is almost always async, defer these to save a bit of time
4647
+ // as the hot path ends with doWrite
4799
4648
  state.pendingcb++;
4800
4649
  state.lastBufferedRequest = null;
4801
-
4802
4650
  if (holder.next) {
4803
4651
  state.corkedRequestsFree = holder.next;
4804
4652
  holder.next = null;
4805
4653
  } else {
4806
4654
  state.corkedRequestsFree = new CorkedRequest(state);
4807
4655
  }
4808
-
4809
4656
  state.bufferedRequestCount = 0;
4810
4657
  } else {
4811
4658
  // Slow case, write chunks one-by-one
@@ -4816,32 +4663,26 @@ function clearBuffer(stream, state) {
4816
4663
  var len = state.objectMode ? 1 : chunk.length;
4817
4664
  doWrite(stream, state, false, len, chunk, encoding, cb);
4818
4665
  entry = entry.next;
4819
- state.bufferedRequestCount--; // if we didn't call the onwrite immediately, then
4666
+ state.bufferedRequestCount--;
4667
+ // if we didn't call the onwrite immediately, then
4820
4668
  // it means that we need to wait until it does.
4821
4669
  // also, that means that the chunk and cb are currently
4822
4670
  // being processed, so move the buffer counter past them.
4823
-
4824
4671
  if (state.writing) {
4825
4672
  break;
4826
4673
  }
4827
4674
  }
4828
-
4829
4675
  if (entry === null) state.lastBufferedRequest = null;
4830
4676
  }
4831
-
4832
4677
  state.bufferedRequest = entry;
4833
4678
  state.bufferProcessing = false;
4834
4679
  }
4835
-
4836
4680
  Writable.prototype._write = function (chunk, encoding, cb) {
4837
4681
  cb(new ERR_METHOD_NOT_IMPLEMENTED('_write()'));
4838
4682
  };
4839
-
4840
4683
  Writable.prototype._writev = null;
4841
-
4842
4684
  Writable.prototype.end = function (chunk, encoding, cb) {
4843
4685
  var state = this._writableState;
4844
-
4845
4686
  if (typeof chunk === 'function') {
4846
4687
  cb = chunk;
4847
4688
  chunk = null;
@@ -4850,19 +4691,18 @@ Writable.prototype.end = function (chunk, encoding, cb) {
4850
4691
  cb = encoding;
4851
4692
  encoding = null;
4852
4693
  }
4694
+ if (chunk !== null && chunk !== undefined) this.write(chunk, encoding);
4853
4695
 
4854
- if (chunk !== null && chunk !== undefined) this.write(chunk, encoding); // .end() fully uncorks
4855
-
4696
+ // .end() fully uncorks
4856
4697
  if (state.corked) {
4857
4698
  state.corked = 1;
4858
4699
  this.uncork();
4859
- } // ignore unnecessary end() calls.
4860
-
4700
+ }
4861
4701
 
4702
+ // ignore unnecessary end() calls.
4862
4703
  if (!state.ending) endWritable(this, state, cb);
4863
4704
  return this;
4864
4705
  };
4865
-
4866
4706
  Object.defineProperty(Writable.prototype, 'writableLength', {
4867
4707
  // making it explicit this property is not enumerable
4868
4708
  // because otherwise some prototype manipulation in
@@ -4872,25 +4712,20 @@ Object.defineProperty(Writable.prototype, 'writableLength', {
4872
4712
  return this._writableState.length;
4873
4713
  }
4874
4714
  });
4875
-
4876
4715
  function needFinish(state) {
4877
4716
  return state.ending && state.length === 0 && state.bufferedRequest === null && !state.finished && !state.writing;
4878
4717
  }
4879
-
4880
4718
  function callFinal(stream, state) {
4881
4719
  stream._final(function (err) {
4882
4720
  state.pendingcb--;
4883
-
4884
4721
  if (err) {
4885
4722
  errorOrDestroy(stream, err);
4886
4723
  }
4887
-
4888
4724
  state.prefinished = true;
4889
4725
  stream.emit('prefinish');
4890
4726
  finishMaybe(stream, state);
4891
4727
  });
4892
4728
  }
4893
-
4894
4729
  function prefinish(stream, state) {
4895
4730
  if (!state.prefinished && !state.finalCalled) {
4896
4731
  if (typeof stream._final === 'function' && !state.destroyed) {
@@ -4903,59 +4738,47 @@ function prefinish(stream, state) {
4903
4738
  }
4904
4739
  }
4905
4740
  }
4906
-
4907
4741
  function finishMaybe(stream, state) {
4908
4742
  var need = needFinish(state);
4909
-
4910
4743
  if (need) {
4911
4744
  prefinish(stream, state);
4912
-
4913
4745
  if (state.pendingcb === 0) {
4914
4746
  state.finished = true;
4915
4747
  stream.emit('finish');
4916
-
4917
4748
  if (state.autoDestroy) {
4918
4749
  // In case of duplex streams we need a way to detect
4919
4750
  // if the readable side is ready for autoDestroy as well
4920
4751
  var rState = stream._readableState;
4921
-
4922
4752
  if (!rState || rState.autoDestroy && rState.endEmitted) {
4923
4753
  stream.destroy();
4924
4754
  }
4925
4755
  }
4926
4756
  }
4927
4757
  }
4928
-
4929
4758
  return need;
4930
4759
  }
4931
-
4932
4760
  function endWritable(stream, state, cb) {
4933
4761
  state.ending = true;
4934
4762
  finishMaybe(stream, state);
4935
-
4936
4763
  if (cb) {
4937
4764
  if (state.finished) process.nextTick(cb);else stream.once('finish', cb);
4938
4765
  }
4939
-
4940
4766
  state.ended = true;
4941
4767
  stream.writable = false;
4942
4768
  }
4943
-
4944
4769
  function onCorkedFinish(corkReq, state, err) {
4945
4770
  var entry = corkReq.entry;
4946
4771
  corkReq.entry = null;
4947
-
4948
4772
  while (entry) {
4949
4773
  var cb = entry.callback;
4950
4774
  state.pendingcb--;
4951
4775
  cb(err);
4952
4776
  entry = entry.next;
4953
- } // reuse the free corkReq.
4954
-
4777
+ }
4955
4778
 
4779
+ // reuse the free corkReq.
4956
4780
  state.corkedRequestsFree.next = corkReq;
4957
4781
  }
4958
-
4959
4782
  Object.defineProperty(Writable.prototype, 'destroyed', {
4960
4783
  // making it explicit this property is not enumerable
4961
4784
  // because otherwise some prototype manipulation in
@@ -4965,7 +4788,6 @@ Object.defineProperty(Writable.prototype, 'destroyed', {
4965
4788
  if (this._writableState === undefined) {
4966
4789
  return false;
4967
4790
  }
4968
-
4969
4791
  return this._writableState.destroyed;
4970
4792
  },
4971
4793
  set: function set(value) {
@@ -4973,16 +4795,15 @@ Object.defineProperty(Writable.prototype, 'destroyed', {
4973
4795
  // has not been initialized yet
4974
4796
  if (!this._writableState) {
4975
4797
  return;
4976
- } // backward compatibility, the user is explicitly
4977
- // managing destroyed
4978
-
4798
+ }
4979
4799
 
4800
+ // backward compatibility, the user is explicitly
4801
+ // managing destroyed
4980
4802
  this._writableState.destroyed = value;
4981
4803
  }
4982
4804
  });
4983
4805
  Writable.prototype.destroy = destroyImpl.destroy;
4984
4806
  Writable.prototype._undestroy = destroyImpl.undestroy;
4985
-
4986
4807
  Writable.prototype._destroy = function (err, cb) {
4987
4808
  cb(err);
4988
4809
  };
@@ -4995,11 +4816,10 @@ Writable.prototype._destroy = function (err, cb) {
4995
4816
 
4996
4817
 
4997
4818
  var _Object$setPrototypeO;
4998
-
4999
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5000
-
4819
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
4820
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
4821
+ function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
5001
4822
  var finished = __nccwpck_require__(6080);
5002
-
5003
4823
  var kLastResolve = Symbol('lastResolve');
5004
4824
  var kLastReject = Symbol('lastReject');
5005
4825
  var kError = Symbol('error');
@@ -5007,22 +4827,19 @@ var kEnded = Symbol('ended');
5007
4827
  var kLastPromise = Symbol('lastPromise');
5008
4828
  var kHandlePromise = Symbol('handlePromise');
5009
4829
  var kStream = Symbol('stream');
5010
-
5011
4830
  function createIterResult(value, done) {
5012
4831
  return {
5013
4832
  value: value,
5014
4833
  done: done
5015
4834
  };
5016
4835
  }
5017
-
5018
4836
  function readAndResolve(iter) {
5019
4837
  var resolve = iter[kLastResolve];
5020
-
5021
4838
  if (resolve !== null) {
5022
- var data = iter[kStream].read(); // we defer if data is null
4839
+ var data = iter[kStream].read();
4840
+ // we defer if data is null
5023
4841
  // we can be expecting either 'end' or
5024
4842
  // 'error'
5025
-
5026
4843
  if (data !== null) {
5027
4844
  iter[kLastPromise] = null;
5028
4845
  iter[kLastResolve] = null;
@@ -5031,13 +4848,11 @@ function readAndResolve(iter) {
5031
4848
  }
5032
4849
  }
5033
4850
  }
5034
-
5035
4851
  function onReadable(iter) {
5036
4852
  // we wait for the next tick, because it might
5037
4853
  // emit an error with process.nextTick
5038
4854
  process.nextTick(readAndResolve, iter);
5039
4855
  }
5040
-
5041
4856
  function wrapForNext(lastPromise, iter) {
5042
4857
  return function (resolve, reject) {
5043
4858
  lastPromise.then(function () {
@@ -5045,33 +4860,26 @@ function wrapForNext(lastPromise, iter) {
5045
4860
  resolve(createIterResult(undefined, true));
5046
4861
  return;
5047
4862
  }
5048
-
5049
4863
  iter[kHandlePromise](resolve, reject);
5050
4864
  }, reject);
5051
4865
  };
5052
4866
  }
5053
-
5054
4867
  var AsyncIteratorPrototype = Object.getPrototypeOf(function () {});
5055
4868
  var ReadableStreamAsyncIteratorPrototype = Object.setPrototypeOf((_Object$setPrototypeO = {
5056
4869
  get stream() {
5057
4870
  return this[kStream];
5058
4871
  },
5059
-
5060
4872
  next: function next() {
5061
4873
  var _this = this;
5062
-
5063
4874
  // if we have detected an error in the meanwhile
5064
4875
  // reject straight away
5065
4876
  var error = this[kError];
5066
-
5067
4877
  if (error !== null) {
5068
4878
  return Promise.reject(error);
5069
4879
  }
5070
-
5071
4880
  if (this[kEnded]) {
5072
4881
  return Promise.resolve(createIterResult(undefined, true));
5073
4882
  }
5074
-
5075
4883
  if (this[kStream].destroyed) {
5076
4884
  // We need to defer via nextTick because if .destroy(err) is
5077
4885
  // called, the error will be emitted via nextTick, and
@@ -5086,29 +4894,25 @@ var ReadableStreamAsyncIteratorPrototype = Object.setPrototypeOf((_Object$setPro
5086
4894
  }
5087
4895
  });
5088
4896
  });
5089
- } // if we have multiple next() calls
4897
+ }
4898
+
4899
+ // if we have multiple next() calls
5090
4900
  // we will wait for the previous Promise to finish
5091
4901
  // this logic is optimized to support for await loops,
5092
4902
  // where next() is only called once at a time
5093
-
5094
-
5095
4903
  var lastPromise = this[kLastPromise];
5096
4904
  var promise;
5097
-
5098
4905
  if (lastPromise) {
5099
4906
  promise = new Promise(wrapForNext(lastPromise, this));
5100
4907
  } else {
5101
4908
  // fast path needed to support multiple this.push()
5102
4909
  // without triggering the next() queue
5103
4910
  var data = this[kStream].read();
5104
-
5105
4911
  if (data !== null) {
5106
4912
  return Promise.resolve(createIterResult(data, false));
5107
4913
  }
5108
-
5109
4914
  promise = new Promise(this[kHandlePromise]);
5110
4915
  }
5111
-
5112
4916
  this[kLastPromise] = promise;
5113
4917
  return promise;
5114
4918
  }
@@ -5116,7 +4920,6 @@ var ReadableStreamAsyncIteratorPrototype = Object.setPrototypeOf((_Object$setPro
5116
4920
  return this;
5117
4921
  }), _defineProperty(_Object$setPrototypeO, "return", function _return() {
5118
4922
  var _this2 = this;
5119
-
5120
4923
  // destroy(err, cb) is a private API
5121
4924
  // we can guarantee we have that here, because we control the
5122
4925
  // Readable class this is attached to
@@ -5126,15 +4929,12 @@ var ReadableStreamAsyncIteratorPrototype = Object.setPrototypeOf((_Object$setPro
5126
4929
  reject(err);
5127
4930
  return;
5128
4931
  }
5129
-
5130
4932
  resolve(createIterResult(undefined, true));
5131
4933
  });
5132
4934
  });
5133
4935
  }), _Object$setPrototypeO), AsyncIteratorPrototype);
5134
-
5135
4936
  var createReadableStreamAsyncIterator = function createReadableStreamAsyncIterator(stream) {
5136
4937
  var _Object$create;
5137
-
5138
4938
  var iterator = Object.create(ReadableStreamAsyncIteratorPrototype, (_Object$create = {}, _defineProperty(_Object$create, kStream, {
5139
4939
  value: stream,
5140
4940
  writable: true
@@ -5153,7 +4953,6 @@ var createReadableStreamAsyncIterator = function createReadableStreamAsyncIterat
5153
4953
  }), _defineProperty(_Object$create, kHandlePromise, {
5154
4954
  value: function value(resolve, reject) {
5155
4955
  var data = iterator[kStream].read();
5156
-
5157
4956
  if (data) {
5158
4957
  iterator[kLastPromise] = null;
5159
4958
  iterator[kLastResolve] = null;
@@ -5169,35 +4968,30 @@ var createReadableStreamAsyncIterator = function createReadableStreamAsyncIterat
5169
4968
  iterator[kLastPromise] = null;
5170
4969
  finished(stream, function (err) {
5171
4970
  if (err && err.code !== 'ERR_STREAM_PREMATURE_CLOSE') {
5172
- var reject = iterator[kLastReject]; // reject if we are waiting for data in the Promise
4971
+ var reject = iterator[kLastReject];
4972
+ // reject if we are waiting for data in the Promise
5173
4973
  // returned by next() and store the error
5174
-
5175
4974
  if (reject !== null) {
5176
4975
  iterator[kLastPromise] = null;
5177
4976
  iterator[kLastResolve] = null;
5178
4977
  iterator[kLastReject] = null;
5179
4978
  reject(err);
5180
4979
  }
5181
-
5182
4980
  iterator[kError] = err;
5183
4981
  return;
5184
4982
  }
5185
-
5186
4983
  var resolve = iterator[kLastResolve];
5187
-
5188
4984
  if (resolve !== null) {
5189
4985
  iterator[kLastPromise] = null;
5190
4986
  iterator[kLastResolve] = null;
5191
4987
  iterator[kLastReject] = null;
5192
4988
  resolve(createIterResult(undefined, true));
5193
4989
  }
5194
-
5195
4990
  iterator[kEnded] = true;
5196
4991
  });
5197
4992
  stream.on('readable', onReadable.bind(null, iterator));
5198
4993
  return iterator;
5199
4994
  };
5200
-
5201
4995
  module.exports = createReadableStreamAsyncIterator;
5202
4996
 
5203
4997
  /***/ }),
@@ -5207,41 +5001,29 @@ module.exports = createReadableStreamAsyncIterator;
5207
5001
 
5208
5002
 
5209
5003
 
5210
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
5211
-
5212
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
5213
-
5214
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5215
-
5004
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
5005
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
5006
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5216
5007
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
5217
-
5218
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
5219
-
5220
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
5221
-
5008
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
5009
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
5010
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
5011
+ function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
5222
5012
  var _require = __nccwpck_require__(4300),
5223
- Buffer = _require.Buffer;
5224
-
5013
+ Buffer = _require.Buffer;
5225
5014
  var _require2 = __nccwpck_require__(3837),
5226
- inspect = _require2.inspect;
5227
-
5015
+ inspect = _require2.inspect;
5228
5016
  var custom = inspect && inspect.custom || 'inspect';
5229
-
5230
5017
  function copyBuffer(src, target, offset) {
5231
5018
  Buffer.prototype.copy.call(src, target, offset);
5232
5019
  }
5233
-
5234
- module.exports =
5235
- /*#__PURE__*/
5236
- function () {
5020
+ module.exports = /*#__PURE__*/function () {
5237
5021
  function BufferList() {
5238
5022
  _classCallCheck(this, BufferList);
5239
-
5240
5023
  this.head = null;
5241
5024
  this.tail = null;
5242
5025
  this.length = 0;
5243
5026
  }
5244
-
5245
5027
  _createClass(BufferList, [{
5246
5028
  key: "push",
5247
5029
  value: function push(v) {
@@ -5285,11 +5067,7 @@ function () {
5285
5067
  if (this.length === 0) return '';
5286
5068
  var p = this.head;
5287
5069
  var ret = '' + p.data;
5288
-
5289
- while (p = p.next) {
5290
- ret += s + p.data;
5291
- }
5292
-
5070
+ while (p = p.next) ret += s + p.data;
5293
5071
  return ret;
5294
5072
  }
5295
5073
  }, {
@@ -5299,21 +5077,19 @@ function () {
5299
5077
  var ret = Buffer.allocUnsafe(n >>> 0);
5300
5078
  var p = this.head;
5301
5079
  var i = 0;
5302
-
5303
5080
  while (p) {
5304
5081
  copyBuffer(p.data, ret, i);
5305
5082
  i += p.data.length;
5306
5083
  p = p.next;
5307
5084
  }
5308
-
5309
5085
  return ret;
5310
- } // Consumes a specified amount of bytes or characters from the buffered data.
5086
+ }
5311
5087
 
5088
+ // Consumes a specified amount of bytes or characters from the buffered data.
5312
5089
  }, {
5313
5090
  key: "consume",
5314
5091
  value: function consume(n, hasStrings) {
5315
5092
  var ret;
5316
-
5317
5093
  if (n < this.head.data.length) {
5318
5094
  // `slice` is the same for buffers and strings.
5319
5095
  ret = this.head.data.slice(0, n);
@@ -5325,15 +5101,15 @@ function () {
5325
5101
  // Result spans more than one buffer.
5326
5102
  ret = hasStrings ? this._getString(n) : this._getBuffer(n);
5327
5103
  }
5328
-
5329
5104
  return ret;
5330
5105
  }
5331
5106
  }, {
5332
5107
  key: "first",
5333
5108
  value: function first() {
5334
5109
  return this.head.data;
5335
- } // Consumes a specified amount of characters from the buffered data.
5110
+ }
5336
5111
 
5112
+ // Consumes a specified amount of characters from the buffered data.
5337
5113
  }, {
5338
5114
  key: "_getString",
5339
5115
  value: function _getString(n) {
@@ -5341,13 +5117,11 @@ function () {
5341
5117
  var c = 1;
5342
5118
  var ret = p.data;
5343
5119
  n -= ret.length;
5344
-
5345
5120
  while (p = p.next) {
5346
5121
  var str = p.data;
5347
5122
  var nb = n > str.length ? str.length : n;
5348
5123
  if (nb === str.length) ret += str;else ret += str.slice(0, n);
5349
5124
  n -= nb;
5350
-
5351
5125
  if (n === 0) {
5352
5126
  if (nb === str.length) {
5353
5127
  ++c;
@@ -5356,17 +5130,15 @@ function () {
5356
5130
  this.head = p;
5357
5131
  p.data = str.slice(nb);
5358
5132
  }
5359
-
5360
5133
  break;
5361
5134
  }
5362
-
5363
5135
  ++c;
5364
5136
  }
5365
-
5366
5137
  this.length -= c;
5367
5138
  return ret;
5368
- } // Consumes a specified amount of bytes from the buffered data.
5139
+ }
5369
5140
 
5141
+ // Consumes a specified amount of bytes from the buffered data.
5370
5142
  }, {
5371
5143
  key: "_getBuffer",
5372
5144
  value: function _getBuffer(n) {
@@ -5375,13 +5147,11 @@ function () {
5375
5147
  var c = 1;
5376
5148
  p.data.copy(ret);
5377
5149
  n -= p.data.length;
5378
-
5379
5150
  while (p = p.next) {
5380
5151
  var buf = p.data;
5381
5152
  var nb = n > buf.length ? buf.length : n;
5382
5153
  buf.copy(ret, ret.length - n, 0, nb);
5383
5154
  n -= nb;
5384
-
5385
5155
  if (n === 0) {
5386
5156
  if (nb === buf.length) {
5387
5157
  ++c;
@@ -5390,21 +5160,19 @@ function () {
5390
5160
  this.head = p;
5391
5161
  p.data = buf.slice(nb);
5392
5162
  }
5393
-
5394
5163
  break;
5395
5164
  }
5396
-
5397
5165
  ++c;
5398
5166
  }
5399
-
5400
5167
  this.length -= c;
5401
5168
  return ret;
5402
- } // Make sure the linked list only shows the minimal necessary information.
5169
+ }
5403
5170
 
5171
+ // Make sure the linked list only shows the minimal necessary information.
5404
5172
  }, {
5405
5173
  key: custom,
5406
5174
  value: function value(_, options) {
5407
- return inspect(this, _objectSpread({}, options, {
5175
+ return inspect(this, _objectSpread(_objectSpread({}, options), {}, {
5408
5176
  // Only inspect one level.
5409
5177
  depth: 0,
5410
5178
  // It should not recurse.
@@ -5412,7 +5180,6 @@ function () {
5412
5180
  }));
5413
5181
  }
5414
5182
  }]);
5415
-
5416
5183
  return BufferList;
5417
5184
  }();
5418
5185
 
@@ -5421,14 +5188,13 @@ function () {
5421
5188
  /***/ 7049:
5422
5189
  /***/ ((module) => {
5423
5190
 
5424
- // undocumented cb() API, needed for core, not for public API
5425
5191
 
5192
+
5193
+ // undocumented cb() API, needed for core, not for public API
5426
5194
  function destroy(err, cb) {
5427
5195
  var _this = this;
5428
-
5429
5196
  var readableDestroyed = this._readableState && this._readableState.destroyed;
5430
5197
  var writableDestroyed = this._writableState && this._writableState.destroyed;
5431
-
5432
5198
  if (readableDestroyed || writableDestroyed) {
5433
5199
  if (cb) {
5434
5200
  cb(err);
@@ -5440,21 +5206,20 @@ function destroy(err, cb) {
5440
5206
  process.nextTick(emitErrorNT, this, err);
5441
5207
  }
5442
5208
  }
5443
-
5444
5209
  return this;
5445
- } // we set destroyed to true before firing error callbacks in order
5446
- // to make it re-entrance safe in case destroy() is called within callbacks
5210
+ }
5447
5211
 
5212
+ // we set destroyed to true before firing error callbacks in order
5213
+ // to make it re-entrance safe in case destroy() is called within callbacks
5448
5214
 
5449
5215
  if (this._readableState) {
5450
5216
  this._readableState.destroyed = true;
5451
- } // if this is a duplex stream mark the writable part as destroyed as well
5452
-
5217
+ }
5453
5218
 
5219
+ // if this is a duplex stream mark the writable part as destroyed as well
5454
5220
  if (this._writableState) {
5455
5221
  this._writableState.destroyed = true;
5456
5222
  }
5457
-
5458
5223
  this._destroy(err || null, function (err) {
5459
5224
  if (!cb && err) {
5460
5225
  if (!_this._writableState) {
@@ -5472,21 +5237,17 @@ function destroy(err, cb) {
5472
5237
  process.nextTick(emitCloseNT, _this);
5473
5238
  }
5474
5239
  });
5475
-
5476
5240
  return this;
5477
5241
  }
5478
-
5479
5242
  function emitErrorAndCloseNT(self, err) {
5480
5243
  emitErrorNT(self, err);
5481
5244
  emitCloseNT(self);
5482
5245
  }
5483
-
5484
5246
  function emitCloseNT(self) {
5485
5247
  if (self._writableState && !self._writableState.emitClose) return;
5486
5248
  if (self._readableState && !self._readableState.emitClose) return;
5487
5249
  self.emit('close');
5488
5250
  }
5489
-
5490
5251
  function undestroy() {
5491
5252
  if (this._readableState) {
5492
5253
  this._readableState.destroyed = false;
@@ -5494,7 +5255,6 @@ function undestroy() {
5494
5255
  this._readableState.ended = false;
5495
5256
  this._readableState.endEmitted = false;
5496
5257
  }
5497
-
5498
5258
  if (this._writableState) {
5499
5259
  this._writableState.destroyed = false;
5500
5260
  this._writableState.ended = false;
@@ -5505,22 +5265,20 @@ function undestroy() {
5505
5265
  this._writableState.errorEmitted = false;
5506
5266
  }
5507
5267
  }
5508
-
5509
5268
  function emitErrorNT(self, err) {
5510
5269
  self.emit('error', err);
5511
5270
  }
5512
-
5513
5271
  function errorOrDestroy(stream, err) {
5514
5272
  // We have tests that rely on errors being emitted
5515
5273
  // in the same tick, so changing this is semver major.
5516
5274
  // For now when you opt-in to autoDestroy we allow
5517
5275
  // the error to be emitted nextTick. In a future
5518
5276
  // semver major update we should change the default to this.
5277
+
5519
5278
  var rState = stream._readableState;
5520
5279
  var wState = stream._writableState;
5521
5280
  if (rState && rState.autoDestroy || wState && wState.autoDestroy) stream.destroy(err);else stream.emit('error', err);
5522
5281
  }
5523
-
5524
5282
  module.exports = {
5525
5283
  destroy: destroy,
5526
5284
  undestroy: undestroy,
@@ -5536,77 +5294,61 @@ module.exports = {
5536
5294
  // permission from the author, Mathias Buus (@mafintosh).
5537
5295
 
5538
5296
 
5539
- var ERR_STREAM_PREMATURE_CLOSE = (__nccwpck_require__(7214)/* .codes.ERR_STREAM_PREMATURE_CLOSE */ .q.ERR_STREAM_PREMATURE_CLOSE);
5540
5297
 
5298
+ var ERR_STREAM_PREMATURE_CLOSE = (__nccwpck_require__(7214)/* .codes.ERR_STREAM_PREMATURE_CLOSE */ .q.ERR_STREAM_PREMATURE_CLOSE);
5541
5299
  function once(callback) {
5542
5300
  var called = false;
5543
5301
  return function () {
5544
5302
  if (called) return;
5545
5303
  called = true;
5546
-
5547
5304
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
5548
5305
  args[_key] = arguments[_key];
5549
5306
  }
5550
-
5551
5307
  callback.apply(this, args);
5552
5308
  };
5553
5309
  }
5554
-
5555
5310
  function noop() {}
5556
-
5557
5311
  function isRequest(stream) {
5558
5312
  return stream.setHeader && typeof stream.abort === 'function';
5559
5313
  }
5560
-
5561
5314
  function eos(stream, opts, callback) {
5562
5315
  if (typeof opts === 'function') return eos(stream, null, opts);
5563
5316
  if (!opts) opts = {};
5564
5317
  callback = once(callback || noop);
5565
5318
  var readable = opts.readable || opts.readable !== false && stream.readable;
5566
5319
  var writable = opts.writable || opts.writable !== false && stream.writable;
5567
-
5568
5320
  var onlegacyfinish = function onlegacyfinish() {
5569
5321
  if (!stream.writable) onfinish();
5570
5322
  };
5571
-
5572
5323
  var writableEnded = stream._writableState && stream._writableState.finished;
5573
-
5574
5324
  var onfinish = function onfinish() {
5575
5325
  writable = false;
5576
5326
  writableEnded = true;
5577
5327
  if (!readable) callback.call(stream);
5578
5328
  };
5579
-
5580
5329
  var readableEnded = stream._readableState && stream._readableState.endEmitted;
5581
-
5582
5330
  var onend = function onend() {
5583
5331
  readable = false;
5584
5332
  readableEnded = true;
5585
5333
  if (!writable) callback.call(stream);
5586
5334
  };
5587
-
5588
5335
  var onerror = function onerror(err) {
5589
5336
  callback.call(stream, err);
5590
5337
  };
5591
-
5592
5338
  var onclose = function onclose() {
5593
5339
  var err;
5594
-
5595
5340
  if (readable && !readableEnded) {
5596
5341
  if (!stream._readableState || !stream._readableState.ended) err = new ERR_STREAM_PREMATURE_CLOSE();
5597
5342
  return callback.call(stream, err);
5598
5343
  }
5599
-
5600
5344
  if (writable && !writableEnded) {
5601
5345
  if (!stream._writableState || !stream._writableState.ended) err = new ERR_STREAM_PREMATURE_CLOSE();
5602
5346
  return callback.call(stream, err);
5603
5347
  }
5604
5348
  };
5605
-
5606
5349
  var onrequest = function onrequest() {
5607
5350
  stream.req.on('finish', onfinish);
5608
5351
  };
5609
-
5610
5352
  if (isRequest(stream)) {
5611
5353
  stream.on('complete', onfinish);
5612
5354
  stream.on('abort', onclose);
@@ -5616,7 +5358,6 @@ function eos(stream, opts, callback) {
5616
5358
  stream.on('end', onlegacyfinish);
5617
5359
  stream.on('close', onlegacyfinish);
5618
5360
  }
5619
-
5620
5361
  stream.on('end', onend);
5621
5362
  stream.on('finish', onfinish);
5622
5363
  if (opts.error !== false) stream.on('error', onerror);
@@ -5634,7 +5375,6 @@ function eos(stream, opts, callback) {
5634
5375
  stream.removeListener('close', onclose);
5635
5376
  };
5636
5377
  }
5637
-
5638
5378
  module.exports = eos;
5639
5379
 
5640
5380
  /***/ }),
@@ -5645,52 +5385,42 @@ module.exports = eos;
5645
5385
 
5646
5386
 
5647
5387
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
5648
-
5649
5388
  function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
5650
-
5651
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
5652
-
5653
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
5654
-
5655
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5656
-
5389
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
5390
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
5391
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5392
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
5393
+ function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
5657
5394
  var ERR_INVALID_ARG_TYPE = (__nccwpck_require__(7214)/* .codes.ERR_INVALID_ARG_TYPE */ .q.ERR_INVALID_ARG_TYPE);
5658
-
5659
5395
  function from(Readable, iterable, opts) {
5660
5396
  var iterator;
5661
-
5662
5397
  if (iterable && typeof iterable.next === 'function') {
5663
5398
  iterator = iterable;
5664
5399
  } else if (iterable && iterable[Symbol.asyncIterator]) iterator = iterable[Symbol.asyncIterator]();else if (iterable && iterable[Symbol.iterator]) iterator = iterable[Symbol.iterator]();else throw new ERR_INVALID_ARG_TYPE('iterable', ['Iterable'], iterable);
5665
-
5666
5400
  var readable = new Readable(_objectSpread({
5667
5401
  objectMode: true
5668
- }, opts)); // Reading boolean to protect against _read
5402
+ }, opts));
5403
+ // Reading boolean to protect against _read
5669
5404
  // being called before last iteration completion.
5670
-
5671
5405
  var reading = false;
5672
-
5673
5406
  readable._read = function () {
5674
5407
  if (!reading) {
5675
5408
  reading = true;
5676
5409
  next();
5677
5410
  }
5678
5411
  };
5679
-
5680
5412
  function next() {
5681
5413
  return _next2.apply(this, arguments);
5682
5414
  }
5683
-
5684
5415
  function _next2() {
5685
5416
  _next2 = _asyncToGenerator(function* () {
5686
5417
  try {
5687
- var _ref = yield iterator.next(),
5688
- value = _ref.value,
5689
- done = _ref.done;
5690
-
5418
+ var _yield$iterator$next = yield iterator.next(),
5419
+ value = _yield$iterator$next.value,
5420
+ done = _yield$iterator$next.done;
5691
5421
  if (done) {
5692
5422
  readable.push(null);
5693
- } else if (readable.push((yield value))) {
5423
+ } else if (readable.push(yield value)) {
5694
5424
  next();
5695
5425
  } else {
5696
5426
  reading = false;
@@ -5701,12 +5431,11 @@ function from(Readable, iterable, opts) {
5701
5431
  });
5702
5432
  return _next2.apply(this, arguments);
5703
5433
  }
5704
-
5705
5434
  return readable;
5706
5435
  }
5707
-
5708
5436
  module.exports = from;
5709
5437
 
5438
+
5710
5439
  /***/ }),
5711
5440
 
5712
5441
  /***/ 6989:
@@ -5716,8 +5445,8 @@ module.exports = from;
5716
5445
  // permission from the author, Mathias Buus (@mafintosh).
5717
5446
 
5718
5447
 
5719
- var eos;
5720
5448
 
5449
+ var eos;
5721
5450
  function once(callback) {
5722
5451
  var called = false;
5723
5452
  return function () {
@@ -5726,20 +5455,16 @@ function once(callback) {
5726
5455
  callback.apply(void 0, arguments);
5727
5456
  };
5728
5457
  }
5729
-
5730
5458
  var _require$codes = (__nccwpck_require__(7214)/* .codes */ .q),
5731
- ERR_MISSING_ARGS = _require$codes.ERR_MISSING_ARGS,
5732
- ERR_STREAM_DESTROYED = _require$codes.ERR_STREAM_DESTROYED;
5733
-
5459
+ ERR_MISSING_ARGS = _require$codes.ERR_MISSING_ARGS,
5460
+ ERR_STREAM_DESTROYED = _require$codes.ERR_STREAM_DESTROYED;
5734
5461
  function noop(err) {
5735
5462
  // Rethrow the error if it exists to avoid swallowing it
5736
5463
  if (err) throw err;
5737
5464
  }
5738
-
5739
5465
  function isRequest(stream) {
5740
5466
  return stream.setHeader && typeof stream.abort === 'function';
5741
5467
  }
5742
-
5743
5468
  function destroyer(stream, reading, writing, callback) {
5744
5469
  callback = once(callback);
5745
5470
  var closed = false;
@@ -5759,40 +5484,34 @@ function destroyer(stream, reading, writing, callback) {
5759
5484
  return function (err) {
5760
5485
  if (closed) return;
5761
5486
  if (destroyed) return;
5762
- destroyed = true; // request.destroy just do .end - .abort is what we want
5487
+ destroyed = true;
5763
5488
 
5489
+ // request.destroy just do .end - .abort is what we want
5764
5490
  if (isRequest(stream)) return stream.abort();
5765
5491
  if (typeof stream.destroy === 'function') return stream.destroy();
5766
5492
  callback(err || new ERR_STREAM_DESTROYED('pipe'));
5767
5493
  };
5768
5494
  }
5769
-
5770
5495
  function call(fn) {
5771
5496
  fn();
5772
5497
  }
5773
-
5774
5498
  function pipe(from, to) {
5775
5499
  return from.pipe(to);
5776
5500
  }
5777
-
5778
5501
  function popCallback(streams) {
5779
5502
  if (!streams.length) return noop;
5780
5503
  if (typeof streams[streams.length - 1] !== 'function') return noop;
5781
5504
  return streams.pop();
5782
5505
  }
5783
-
5784
5506
  function pipeline() {
5785
5507
  for (var _len = arguments.length, streams = new Array(_len), _key = 0; _key < _len; _key++) {
5786
5508
  streams[_key] = arguments[_key];
5787
5509
  }
5788
-
5789
5510
  var callback = popCallback(streams);
5790
5511
  if (Array.isArray(streams[0])) streams = streams[0];
5791
-
5792
5512
  if (streams.length < 2) {
5793
5513
  throw new ERR_MISSING_ARGS('streams');
5794
5514
  }
5795
-
5796
5515
  var error;
5797
5516
  var destroys = streams.map(function (stream, i) {
5798
5517
  var reading = i < streams.length - 1;
@@ -5807,7 +5526,6 @@ function pipeline() {
5807
5526
  });
5808
5527
  return streams.reduce(pipe);
5809
5528
  }
5810
-
5811
5529
  module.exports = pipeline;
5812
5530
 
5813
5531
  /***/ }),
@@ -5818,27 +5536,22 @@ module.exports = pipeline;
5818
5536
 
5819
5537
 
5820
5538
  var ERR_INVALID_OPT_VALUE = (__nccwpck_require__(7214)/* .codes.ERR_INVALID_OPT_VALUE */ .q.ERR_INVALID_OPT_VALUE);
5821
-
5822
5539
  function highWaterMarkFrom(options, isDuplex, duplexKey) {
5823
5540
  return options.highWaterMark != null ? options.highWaterMark : isDuplex ? options[duplexKey] : null;
5824
5541
  }
5825
-
5826
5542
  function getHighWaterMark(state, options, duplexKey, isDuplex) {
5827
5543
  var hwm = highWaterMarkFrom(options, isDuplex, duplexKey);
5828
-
5829
5544
  if (hwm != null) {
5830
5545
  if (!(isFinite(hwm) && Math.floor(hwm) === hwm) || hwm < 0) {
5831
5546
  var name = isDuplex ? duplexKey : 'highWaterMark';
5832
5547
  throw new ERR_INVALID_OPT_VALUE(name, hwm);
5833
5548
  }
5834
-
5835
5549
  return Math.floor(hwm);
5836
- } // Default value
5837
-
5550
+ }
5838
5551
 
5552
+ // Default value
5839
5553
  return state.objectMode ? 16 : 16 * 1024;
5840
5554
  }
5841
-
5842
5555
  module.exports = {
5843
5556
  getHighWaterMark: getHighWaterMark
5844
5557
  };
@@ -7123,16 +6836,16 @@ function chalkTemplate(firstString, ...arguments_) {
7123
6836
 
7124
6837
  /***/ }),
7125
6838
 
7126
- /***/ 67:
6839
+ /***/ 2719:
7127
6840
  /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __nccwpck_require__) => {
7128
6841
 
7129
6842
 
7130
6843
  // EXPORTS
7131
6844
  __nccwpck_require__.d(__webpack_exports__, {
7132
- "Z": () => (/* binding */ ora)
6845
+ "ZP": () => (/* binding */ ora)
7133
6846
  });
7134
6847
 
7135
- // UNUSED EXPORTS: oraPromise
6848
+ // UNUSED EXPORTS: oraPromise, spinners
7136
6849
 
7137
6850
  // EXTERNAL MODULE: external "node:process"
7138
6851
  var external_node_process_ = __nccwpck_require__(7742);
@@ -7930,7 +7643,7 @@ function isInteractive({stream = process.stdout} = {}) {
7930
7643
  const external_node_readline_namespaceObject = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("node:readline");
7931
7644
  // EXTERNAL MODULE: ./node_modules/bl/bl.js
7932
7645
  var bl = __nccwpck_require__(336);
7933
- ;// CONCATENATED MODULE: ./node_modules/ora/utilities.js
7646
+ ;// CONCATENATED MODULE: ./node_modules/stdin-discarder/index.js
7934
7647
 
7935
7648
 
7936
7649
 
@@ -7947,7 +7660,7 @@ class StdinDiscarder {
7947
7660
  this.#mutedStream.pipe(external_node_process_.stdout);
7948
7661
 
7949
7662
  const self = this; // eslint-disable-line unicorn/no-this-assignment
7950
- this.#ourEmit = function (event, data, ...args) {
7663
+ this.#ourEmit = function (event, data, ...arguments_) {
7951
7664
  const {stdin} = external_node_process_;
7952
7665
  if (self.#requests > 0 || stdin.emit === self.#ourEmit) {
7953
7666
  if (event === 'keypress') { // Fixes readline behavior
@@ -7958,9 +7671,9 @@ class StdinDiscarder {
7958
7671
  external_node_process_.emit('SIGINT');
7959
7672
  }
7960
7673
 
7961
- Reflect.apply(self.#ourEmit, this, [event, data, ...args]);
7674
+ Reflect.apply(self.#ourEmit, this, [event, data, ...arguments_]);
7962
7675
  } else {
7963
- Reflect.apply(external_node_process_.stdin.emit, this, [event, data, ...args]);
7676
+ Reflect.apply(external_node_process_.stdin.emit, this, [event, data, ...arguments_]);
7964
7677
  }
7965
7678
  };
7966
7679
  }
@@ -8017,8 +7730,11 @@ class StdinDiscarder {
8017
7730
  }
8018
7731
  }
8019
7732
 
8020
- ;// CONCATENATED MODULE: ./node_modules/ora/index.js
7733
+ const stdinDiscarder = new StdinDiscarder();
7734
+
7735
+ /* harmony default export */ const stdin_discarder = (stdinDiscarder);
8021
7736
 
7737
+ ;// CONCATENATED MODULE: ./node_modules/ora/index.js
8022
7738
 
8023
7739
 
8024
7740
 
@@ -8029,7 +7745,6 @@ class StdinDiscarder {
8029
7745
 
8030
7746
 
8031
7747
 
8032
- let stdinDiscarder;
8033
7748
 
8034
7749
  class Ora {
8035
7750
  #linesToClear = 0;
@@ -8050,10 +7765,6 @@ class Ora {
8050
7765
  color;
8051
7766
 
8052
7767
  constructor(options) {
8053
- if (!stdinDiscarder) {
8054
- stdinDiscarder = new StdinDiscarder();
8055
- }
8056
-
8057
7768
  if (typeof options === 'string') {
8058
7769
  options = {
8059
7770
  text: options,
@@ -8303,7 +8014,7 @@ class Ora {
8303
8014
 
8304
8015
  if (this.#options.discardStdin && external_node_process_.stdin.isTTY) {
8305
8016
  this.#isDiscardingStdin = true;
8306
- stdinDiscarder.start();
8017
+ stdin_discarder.start();
8307
8018
  }
8308
8019
 
8309
8020
  this.render();
@@ -8326,7 +8037,7 @@ class Ora {
8326
8037
  }
8327
8038
 
8328
8039
  if (this.#options.discardStdin && external_node_process_.stdin.isTTY && this.#isDiscardingStdin) {
8329
- stdinDiscarder.stop();
8040
+ stdin_discarder.stop();
8330
8041
  this.#isDiscardingStdin = false;
8331
8042
  }
8332
8043
 
@@ -8406,6 +8117,8 @@ async function oraPromise(action, options) {
8406
8117
  }
8407
8118
 
8408
8119
 
8120
+
8121
+
8409
8122
  /***/ }),
8410
8123
 
8411
8124
  /***/ 1124:
@@ -8465,6 +8178,8 @@ __nccwpck_require__.d(__webpack_exports__, {
8465
8178
 
8466
8179
 
8467
8180
 
8181
+
8182
+
8468
8183
  function characters(str) {
8469
8184
  return str.split("");
8470
8185
  }
@@ -8518,48 +8233,26 @@ function return_this() { return this; }
8518
8233
  function return_null() { return null; }
8519
8234
 
8520
8235
  var MAP = (function() {
8521
- function MAP(a, f, backwards) {
8522
- var ret = [], top = [], i;
8523
- function doit() {
8524
- var val = f(a[i], i);
8525
- var is_last = val instanceof Last;
8526
- if (is_last) val = val.v;
8527
- if (val instanceof AtTop) {
8528
- val = val.v;
8529
- if (val instanceof Splice) {
8530
- top.push.apply(top, backwards ? val.v.slice().reverse() : val.v);
8531
- } else {
8532
- top.push(val);
8533
- }
8534
- } else if (val !== skip) {
8535
- if (val instanceof Splice) {
8536
- ret.push.apply(ret, backwards ? val.v.slice().reverse() : val.v);
8537
- } else {
8538
- ret.push(val);
8539
- }
8540
- }
8541
- return is_last;
8542
- }
8543
- if (Array.isArray(a)) {
8544
- if (backwards) {
8545
- for (i = a.length; --i >= 0;) if (doit()) break;
8546
- ret.reverse();
8547
- top.reverse();
8548
- } else {
8549
- for (i = 0; i < a.length; ++i) if (doit()) break;
8236
+ function MAP(a, tw, allow_splicing = true) {
8237
+ const new_a = [];
8238
+
8239
+ for (let i = 0; i < a.length; ++i) {
8240
+ let item = a[i];
8241
+ let ret = item.transform(tw, allow_splicing);
8242
+
8243
+ if (ret instanceof ast_AST_Node) {
8244
+ new_a.push(ret);
8245
+ } else if (ret instanceof Splice) {
8246
+ new_a.push(...ret.v);
8550
8247
  }
8551
- } else {
8552
- for (i in a) if (HOP(a, i)) if (doit()) break;
8553
8248
  }
8554
- return top.concat(ret);
8249
+
8250
+ return new_a;
8555
8251
  }
8556
- MAP.at_top = function(val) { return new AtTop(val); };
8252
+
8557
8253
  MAP.splice = function(val) { return new Splice(val); };
8558
- MAP.last = function(val) { return new Last(val); };
8559
- var skip = MAP.skip = {};
8560
- function AtTop(val) { this.v = val; }
8254
+ MAP.skip = {};
8561
8255
  function Splice(val) { this.v = val; }
8562
- function Last(val) { this.v = val; }
8563
8256
  return MAP;
8564
8257
  })();
8565
8258
 
@@ -8852,6 +8545,19 @@ var UNICODE = {
8852
8545
  ID_Continue: /(?:[$0-9A-Z_a-z\xAA\xB5\xB7\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0300-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u0483-\u0487\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u05D0-\u05EA\u05F0-\u05F2\u0610-\u061A\u0620-\u0669\u066E-\u06D3\u06D5-\u06DC\u06DF-\u06E8\u06EA-\u06FC\u06FF\u0710-\u074A\u074D-\u07B1\u07C0-\u07F5\u07FA\u0800-\u082D\u0840-\u085B\u08A0-\u08B4\u08E3-\u0963\u0966-\u096F\u0971-\u0983\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BC-\u09C4\u09C7\u09C8\u09CB-\u09CE\u09D7\u09DC\u09DD\u09DF-\u09E3\u09E6-\u09F1\u0A01-\u0A03\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A59-\u0A5C\u0A5E\u0A66-\u0A75\u0A81-\u0A83\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABC-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AD0\u0AE0-\u0AE3\u0AE6-\u0AEF\u0AF9\u0B01-\u0B03\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3C-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B5C\u0B5D\u0B5F-\u0B63\u0B66-\u0B6F\u0B71\u0B82\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD0\u0BD7\u0BE6-\u0BEF\u0C00-\u0C03\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C58-\u0C5A\u0C60-\u0C63\u0C66-\u0C6F\u0C81-\u0C83\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBC-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CDE\u0CE0-\u0CE3\u0CE6-\u0CEF\u0CF1\u0CF2\u0D01-\u0D03\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D-\u0D44\u0D46-\u0D48\u0D4A-\u0D4E\u0D57\u0D5F-\u0D63\u0D66-\u0D6F\u0D7A-\u0D7F\u0D82\u0D83\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DE6-\u0DEF\u0DF2\u0DF3\u0E01-\u0E3A\u0E40-\u0E4E\u0E50-\u0E59\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB9\u0EBB-\u0EBD\u0EC0-\u0EC4\u0EC6\u0EC8-\u0ECD\u0ED0-\u0ED9\u0EDC-\u0EDF\u0F00\u0F18\u0F19\u0F20-\u0F29\u0F35\u0F37\u0F39\u0F3E-\u0F47\u0F49-\u0F6C\u0F71-\u0F84\u0F86-\u0F97\u0F99-\u0FBC\u0FC6\u1000-\u1049\u1050-\u109D\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u135D-\u135F\u1369-\u1371\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1714\u1720-\u1734\u1740-\u1753\u1760-\u176C\u176E-\u1770\u1772\u1773\u1780-\u17D3\u17D7\u17DC\u17DD\u17E0-\u17E9\u180B-\u180D\u1810-\u1819\u1820-\u1877\u1880-\u18AA\u18B0-\u18F5\u1900-\u191E\u1920-\u192B\u1930-\u193B\u1946-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u19D0-\u19DA\u1A00-\u1A1B\u1A20-\u1A5E\u1A60-\u1A7C\u1A7F-\u1A89\u1A90-\u1A99\u1AA7\u1AB0-\u1ABD\u1B00-\u1B4B\u1B50-\u1B59\u1B6B-\u1B73\u1B80-\u1BF3\u1C00-\u1C37\u1C40-\u1C49\u1C4D-\u1C7D\u1CD0-\u1CD2\u1CD4-\u1CF6\u1CF8\u1CF9\u1D00-\u1DF5\u1DFC-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u200C\u200D\u203F\u2040\u2054\u2071\u207F\u2090-\u209C\u20D0-\u20DC\u20E1\u20E5-\u20F0\u2102\u2107\u210A-\u2113\u2115\u2118-\u211D\u2124\u2126\u2128\u212A-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D7F-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2DE0-\u2DFF\u3005-\u3007\u3021-\u302F\u3031-\u3035\u3038-\u303C\u3041-\u3096\u3099-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312D\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FD5\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA62B\uA640-\uA66F\uA674-\uA67D\uA67F-\uA6F1\uA717-\uA71F\uA722-\uA788\uA78B-\uA7AD\uA7B0-\uA7B7\uA7F7-\uA827\uA840-\uA873\uA880-\uA8C4\uA8D0-\uA8D9\uA8E0-\uA8F7\uA8FB\uA8FD\uA900-\uA92D\uA930-\uA953\uA960-\uA97C\uA980-\uA9C0\uA9CF-\uA9D9\uA9E0-\uA9FE\uAA00-\uAA36\uAA40-\uAA4D\uAA50-\uAA59\uAA60-\uAA76\uAA7A-\uAAC2\uAADB-\uAADD\uAAE0-\uAAEF\uAAF2-\uAAF6\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB65\uAB70-\uABEA\uABEC\uABED\uABF0-\uABF9\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE00-\uFE0F\uFE20-\uFE2F\uFE33\uFE34\uFE4D-\uFE4F\uFE70-\uFE74\uFE76-\uFEFC\uFF10-\uFF19\uFF21-\uFF3A\uFF3F\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDD40-\uDD74\uDDFD\uDE80-\uDE9C\uDEA0-\uDED0\uDEE0\uDF00-\uDF1F\uDF30-\uDF4A\uDF50-\uDF7A\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\uDCA0-\uDCA9\uDD00-\uDD27\uDD30-\uDD63\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00-\uDE03\uDE05\uDE06\uDE0C-\uDE13\uDE15-\uDE17\uDE19-\uDE33\uDE38-\uDE3A\uDE3F\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE6\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2]|\uD804[\uDC00-\uDC46\uDC66-\uDC6F\uDC7F-\uDCBA\uDCD0-\uDCE8\uDCF0-\uDCF9\uDD00-\uDD34\uDD36-\uDD3F\uDD50-\uDD73\uDD76\uDD80-\uDDC4\uDDCA-\uDDCC\uDDD0-\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE37\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEEA\uDEF0-\uDEF9\uDF00-\uDF03\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3C-\uDF44\uDF47\uDF48\uDF4B-\uDF4D\uDF50\uDF57\uDF5D-\uDF63\uDF66-\uDF6C\uDF70-\uDF74]|\uD805[\uDC80-\uDCC5\uDCC7\uDCD0-\uDCD9\uDD80-\uDDB5\uDDB8-\uDDC0\uDDD8-\uDDDD\uDE00-\uDE40\uDE44\uDE50-\uDE59\uDE80-\uDEB7\uDEC0-\uDEC9\uDF00-\uDF19\uDF1D-\uDF2B\uDF30-\uDF39]|\uD806[\uDCA0-\uDCE9\uDCFF\uDEC0-\uDEF8]|\uD808[\uDC00-\uDF99]|\uD809[\uDC00-\uDC6E\uDC80-\uDD43]|[\uD80C\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDE60-\uDE69\uDED0-\uDEED\uDEF0-\uDEF4\uDF00-\uDF36\uDF40-\uDF43\uDF50-\uDF59\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDF00-\uDF44\uDF50-\uDF7E\uDF8F-\uDF9F]|\uD82C[\uDC00\uDC01]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99\uDC9D\uDC9E]|\uD834[\uDD65-\uDD69\uDD6D-\uDD72\uDD7B-\uDD82\uDD85-\uDD8B\uDDAA-\uDDAD\uDE42-\uDE44]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB\uDFCE-\uDFFF]|\uD836[\uDE00-\uDE36\uDE3B-\uDE6C\uDE75\uDE84\uDE9B-\uDE9F\uDEA1-\uDEAF]|\uD83A[\uDC00-\uDCC4\uDCD0-\uDCD6]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1]|\uD87E[\uDC00-\uDE1D]|\uDB40[\uDD00-\uDDEF])+/,
8853
8546
  };
8854
8547
 
8548
+ try {
8549
+ UNICODE = {
8550
+ // https://262.ecma-international.org/13.0/#prod-IdentifierStartChar
8551
+ // $, _, ID_Start
8552
+ ID_Start: new RegExp("[_$\\p{ID_Start}]", "u"),
8553
+ // https://262.ecma-international.org/13.0/#prod-IdentifierPartChar
8554
+ // $, zero-width-joiner, zero-width-non-joiner, ID_Continue
8555
+ ID_Continue: new RegExp("[$\\u200C\\u200D\\p{ID_Continue}]+", "u"),
8556
+ };
8557
+ } catch(e) {
8558
+ // Could not use modern JS \p{...}. UNICODE is already defined above so let's continue
8559
+ }
8560
+
8855
8561
  function get_full_char(str, pos) {
8856
8562
  if (is_surrogate_pair_head(str.charCodeAt(pos))) {
8857
8563
  if (is_surrogate_pair_tail(str.charCodeAt(pos + 1))) {
@@ -10645,7 +10351,12 @@ function parse_parse($TEXT, options) {
10645
10351
  }
10646
10352
 
10647
10353
  function try_() {
10648
- var body = block_(), bcatch = null, bfinally = null;
10354
+ var body, bcatch = null, bfinally = null;
10355
+ body = new AST_TryBlock({
10356
+ start : S.token,
10357
+ body : block_(),
10358
+ end : prev(),
10359
+ });
10649
10360
  if (is("keyword", "catch")) {
10650
10361
  var start = S.token;
10651
10362
  next();
@@ -10681,14 +10392,20 @@ function parse_parse($TEXT, options) {
10681
10392
  });
10682
10393
  }
10683
10394
 
10395
+ /**
10396
+ * var
10397
+ * vardef1 = 2,
10398
+ * vardef2 = 3;
10399
+ */
10684
10400
  function vardefs(no_in, kind) {
10685
- var a = [];
10401
+ var var_defs = [];
10686
10402
  var def;
10687
10403
  for (;;) {
10688
10404
  var sym_type =
10689
10405
  kind === "var" ? AST_SymbolVar :
10690
10406
  kind === "const" ? AST_SymbolConst :
10691
10407
  kind === "let" ? AST_SymbolLet : null;
10408
+ // var { a } = b
10692
10409
  if (is("punc", "{") || is("punc", "[")) {
10693
10410
  def = new AST_VarDef({
10694
10411
  start: S.token,
@@ -10708,12 +10425,12 @@ function parse_parse($TEXT, options) {
10708
10425
  });
10709
10426
  if (def.name.name == "import") croak("Unexpected token: import");
10710
10427
  }
10711
- a.push(def);
10428
+ var_defs.push(def);
10712
10429
  if (!is("punc", ","))
10713
10430
  break;
10714
10431
  next();
10715
10432
  }
10716
- return a;
10433
+ return var_defs;
10717
10434
  }
10718
10435
 
10719
10436
  var var_ = function(no_in) {
@@ -10874,7 +10591,7 @@ function parse_parse($TEXT, options) {
10874
10591
  if (is("operator", "new")) {
10875
10592
  return new_(allow_calls);
10876
10593
  }
10877
- if (is("operator", "import")) {
10594
+ if (is("name", "import") && is_token(peek(), "punc", ".")) {
10878
10595
  return import_meta();
10879
10596
  }
10880
10597
  var start = S.token;
@@ -11370,7 +11087,7 @@ function parse_parse($TEXT, options) {
11370
11087
 
11371
11088
  function import_meta() {
11372
11089
  var start = S.token;
11373
- expect_token("operator", "import");
11090
+ expect_token("name", "import");
11374
11091
  expect_token("punc", ".");
11375
11092
  expect_token("name", "meta");
11376
11093
  return subscripts(new AST_ImportMeta({
@@ -11380,9 +11097,10 @@ function parse_parse($TEXT, options) {
11380
11097
  }
11381
11098
 
11382
11099
  function map_name(is_import) {
11383
- function make_symbol(type) {
11100
+ function make_symbol(type, quote) {
11384
11101
  return new type({
11385
11102
  name: as_property_name(),
11103
+ quote: quote || undefined,
11386
11104
  start: prev(),
11387
11105
  end: prev()
11388
11106
  });
@@ -11395,16 +11113,16 @@ function parse_parse($TEXT, options) {
11395
11113
  var name;
11396
11114
 
11397
11115
  if (is_import) {
11398
- foreign_name = make_symbol(foreign_type);
11116
+ foreign_name = make_symbol(foreign_type, start.quote);
11399
11117
  } else {
11400
- name = make_symbol(type);
11118
+ name = make_symbol(type, start.quote);
11401
11119
  }
11402
11120
  if (is("name", "as")) {
11403
11121
  next(); // The "as" word
11404
11122
  if (is_import) {
11405
11123
  name = make_symbol(type);
11406
11124
  } else {
11407
- foreign_name = make_symbol(foreign_type);
11125
+ foreign_name = make_symbol(foreign_type, S.token.quote);
11408
11126
  }
11409
11127
  } else if (is_import) {
11410
11128
  name = new type(foreign_name);
@@ -11420,20 +11138,26 @@ function parse_parse($TEXT, options) {
11420
11138
  });
11421
11139
  }
11422
11140
 
11423
- function map_nameAsterisk(is_import, name) {
11141
+ function map_nameAsterisk(is_import, import_or_export_foreign_name) {
11424
11142
  var foreign_type = is_import ? AST_SymbolImportForeign : AST_SymbolExportForeign;
11425
11143
  var type = is_import ? AST_SymbolImport : AST_SymbolExport;
11426
11144
  var start = S.token;
11427
- var foreign_name;
11145
+ var name, foreign_name;
11428
11146
  var end = prev();
11429
11147
 
11148
+ if (is_import) {
11149
+ name = import_or_export_foreign_name;
11150
+ } else {
11151
+ foreign_name = import_or_export_foreign_name;
11152
+ }
11153
+
11430
11154
  name = name || new type({
11431
11155
  start: start,
11432
11156
  name: "*",
11433
11157
  end: end,
11434
11158
  });
11435
11159
 
11436
- foreign_name = new foreign_type({
11160
+ foreign_name = foreign_name || new foreign_type({
11437
11161
  start: start,
11438
11162
  name: "*",
11439
11163
  end: end,
@@ -11462,9 +11186,9 @@ function parse_parse($TEXT, options) {
11462
11186
  } else if (is("operator", "*")) {
11463
11187
  var name;
11464
11188
  next();
11465
- if (is_import && is("name", "as")) {
11189
+ if (is("name", "as")) {
11466
11190
  next(); // The "as" word
11467
- name = as_symbol(is_import ? AST_SymbolImport : AST_SymbolExportForeign);
11191
+ name = is_import ? as_symbol(AST_SymbolImport) : as_symbol_or_string(AST_SymbolExportForeign);
11468
11192
  }
11469
11193
  names = [map_nameAsterisk(is_import, name)];
11470
11194
  }
@@ -11629,6 +11353,27 @@ function parse_parse($TEXT, options) {
11629
11353
  return sym;
11630
11354
  }
11631
11355
 
11356
+ function as_symbol_or_string(type) {
11357
+ if (!is("name")) {
11358
+ if (!is("string")) {
11359
+ croak("Name or string expected");
11360
+ }
11361
+ var tok = S.token;
11362
+ var ret = new type({
11363
+ start : tok,
11364
+ end : tok,
11365
+ name : tok.value,
11366
+ quote : tok.quote
11367
+ });
11368
+ next();
11369
+ return ret;
11370
+ }
11371
+ var sym = _make_symbol(type);
11372
+ _verify_symbol(sym);
11373
+ next();
11374
+ return sym;
11375
+ }
11376
+
11632
11377
  // Annotate AST_Call, AST_Lambda or AST_New with the special comments
11633
11378
  function annotate(node) {
11634
11379
  var start = node.start;
@@ -12114,6 +11859,14 @@ class ast_AST_Token {
12114
11859
  Object.seal(this);
12115
11860
  }
12116
11861
 
11862
+ // Return a string summary of the token for node.js console.log
11863
+ [Symbol.for("nodejs.util.inspect.custom")](_depth, options) {
11864
+ const special = str => options.stylize(str, "special");
11865
+ const quote = typeof this.value === "string" && this.value.includes("`") ? "'" : "`";
11866
+ const value = `${quote}${this.value}${quote}`;
11867
+ return `${special("[AST_Token")} ${value} at ${this.line}:${this.col}${special("]")}`;
11868
+ }
11869
+
12117
11870
  get nlb() {
12118
11871
  return has_tok_flag(this, TOK_FLAG_NLB);
12119
11872
  }
@@ -12244,8 +11997,21 @@ var AST_SimpleStatement = DEFNODE("SimpleStatement", "body", function AST_Simple
12244
11997
 
12245
11998
  function walk_body(node, visitor) {
12246
11999
  const body = node.body;
12247
- for (var i = 0, len = body.length; i < len; i++) {
12248
- body[i]._walk(visitor);
12000
+ if (visitor.walk_defun_first) {
12001
+ for (var i = 0, len = body.length; i < len; i++) {
12002
+ if (body[i] instanceof AST_Defun) {
12003
+ body[i]._walk(visitor);
12004
+ }
12005
+ }
12006
+ for (var i = 0, len = body.length; i < len; i++) {
12007
+ if (!(body[i] instanceof AST_Defun)) {
12008
+ body[i]._walk(visitor);
12009
+ }
12010
+ }
12011
+ } else {
12012
+ for (var i = 0, len = body.length; i < len; i++) {
12013
+ body[i]._walk(visitor);
12014
+ }
12249
12015
  }
12250
12016
  }
12251
12017
 
@@ -12997,6 +12763,7 @@ var AST_Jump = DEFNODE("Jump", null, function AST_Jump(props) {
12997
12763
  $documentation: "Base class for “jumps” (for now that's `return`, `throw`, `break` and `continue`)"
12998
12764
  }, AST_Statement);
12999
12765
 
12766
+ /** Base class for “exits” (`return` and `throw`) */
13000
12767
  var AST_Exit = DEFNODE("Exit", "value", function AST_Exit(props) {
13001
12768
  if (props) {
13002
12769
  this.value = props.value;
@@ -13259,12 +13026,11 @@ var AST_Case = DEFNODE("Case", "expression", function AST_Case(props) {
13259
13026
 
13260
13027
  /* -----[ EXCEPTIONS ]----- */
13261
13028
 
13262
- var AST_Try = DEFNODE("Try", "bcatch bfinally", function AST_Try(props) {
13029
+ var AST_Try = DEFNODE("Try", "body bcatch bfinally", function AST_Try(props) {
13263
13030
  if (props) {
13031
+ this.body = props.body;
13264
13032
  this.bcatch = props.bcatch;
13265
13033
  this.bfinally = props.bfinally;
13266
- this.body = props.body;
13267
- this.block_scope = props.block_scope;
13268
13034
  this.start = props.start;
13269
13035
  this.end = props.end;
13270
13036
  }
@@ -13273,12 +13039,13 @@ var AST_Try = DEFNODE("Try", "bcatch bfinally", function AST_Try(props) {
13273
13039
  }, {
13274
13040
  $documentation: "A `try` statement",
13275
13041
  $propdoc: {
13042
+ body: "[AST_TryBlock] the try block",
13276
13043
  bcatch: "[AST_Catch?] the catch block, or null if not present",
13277
13044
  bfinally: "[AST_Finally?] the finally block, or null if not present"
13278
13045
  },
13279
13046
  _walk: function(visitor) {
13280
13047
  return visitor._visit(this, function() {
13281
- walk_body(this, visitor);
13048
+ this.body._walk(visitor);
13282
13049
  if (this.bcatch) this.bcatch._walk(visitor);
13283
13050
  if (this.bfinally) this.bfinally._walk(visitor);
13284
13051
  });
@@ -13286,9 +13053,21 @@ var AST_Try = DEFNODE("Try", "bcatch bfinally", function AST_Try(props) {
13286
13053
  _children_backwards(push) {
13287
13054
  if (this.bfinally) push(this.bfinally);
13288
13055
  if (this.bcatch) push(this.bcatch);
13289
- let i = this.body.length;
13290
- while (i--) push(this.body[i]);
13056
+ push(this.body);
13291
13057
  },
13058
+ }, AST_Statement);
13059
+
13060
+ var AST_TryBlock = DEFNODE("TryBlock", null, function AST_TryBlock(props) {
13061
+ if (props) {
13062
+ this.body = props.body;
13063
+ this.block_scope = props.block_scope;
13064
+ this.start = props.start;
13065
+ this.end = props.end;
13066
+ }
13067
+
13068
+ this.flags = 0;
13069
+ }, {
13070
+ $documentation: "The `try` block of a try statement"
13292
13071
  }, AST_Block);
13293
13072
 
13294
13073
  var AST_Catch = DEFNODE("Catch", "argname", function AST_Catch(props) {
@@ -14591,6 +14370,7 @@ var AST_SymbolImportForeign = DEFNODE("SymbolImportForeign", null, function AST_
14591
14370
  this.scope = props.scope;
14592
14371
  this.name = props.name;
14593
14372
  this.thedef = props.thedef;
14373
+ this.quote = props.quote;
14594
14374
  this.start = props.start;
14595
14375
  this.end = props.end;
14596
14376
  }
@@ -14642,6 +14422,7 @@ var AST_SymbolExport = DEFNODE("SymbolExport", null, function AST_SymbolExport(p
14642
14422
  this.scope = props.scope;
14643
14423
  this.name = props.name;
14644
14424
  this.thedef = props.thedef;
14425
+ this.quote = props.quote;
14645
14426
  this.start = props.start;
14646
14427
  this.end = props.end;
14647
14428
  }
@@ -14656,6 +14437,7 @@ var AST_SymbolExportForeign = DEFNODE("SymbolExportForeign", null, function AST_
14656
14437
  this.scope = props.scope;
14657
14438
  this.name = props.name;
14658
14439
  this.thedef = props.thedef;
14440
+ this.quote = props.quote;
14659
14441
  this.start = props.start;
14660
14442
  this.end = props.end;
14661
14443
  }
@@ -15008,10 +14790,11 @@ const walk_abort = Symbol("abort walk");
15008
14790
  /* -----[ TreeWalker ]----- */
15009
14791
 
15010
14792
  class TreeWalker {
15011
- constructor(callback) {
14793
+ constructor(callback, { walk_defun_first = false } = {}) {
15012
14794
  this.visit = callback;
15013
14795
  this.stack = [];
15014
14796
  this.directives = Object.create(null);
14797
+ this.walk_defun_first = walk_defun_first;
15015
14798
  }
15016
14799
 
15017
14800
  _visit(node, descend) {
@@ -15183,12 +14966,6 @@ function def_transform(node, descend) {
15183
14966
  });
15184
14967
  }
15185
14968
 
15186
- function do_list(list, tw) {
15187
- return MAP(list, function(node) {
15188
- return node.transform(tw, true);
15189
- });
15190
- }
15191
-
15192
14969
  def_transform(ast_AST_Node, noop);
15193
14970
 
15194
14971
  def_transform(AST_LabeledStatement, function(self, tw) {
@@ -15201,7 +14978,7 @@ def_transform(AST_SimpleStatement, function(self, tw) {
15201
14978
  });
15202
14979
 
15203
14980
  def_transform(AST_Block, function(self, tw) {
15204
- self.body = do_list(self.body, tw);
14981
+ self.body = MAP(self.body, tw);
15205
14982
  });
15206
14983
 
15207
14984
  def_transform(AST_Do, function(self, tw) {
@@ -15248,27 +15025,27 @@ def_transform(AST_If, function(self, tw) {
15248
15025
 
15249
15026
  def_transform(AST_Switch, function(self, tw) {
15250
15027
  self.expression = self.expression.transform(tw);
15251
- self.body = do_list(self.body, tw);
15028
+ self.body = MAP(self.body, tw);
15252
15029
  });
15253
15030
 
15254
15031
  def_transform(AST_Case, function(self, tw) {
15255
15032
  self.expression = self.expression.transform(tw);
15256
- self.body = do_list(self.body, tw);
15033
+ self.body = MAP(self.body, tw);
15257
15034
  });
15258
15035
 
15259
15036
  def_transform(AST_Try, function(self, tw) {
15260
- self.body = do_list(self.body, tw);
15037
+ self.body = self.body.transform(tw);
15261
15038
  if (self.bcatch) self.bcatch = self.bcatch.transform(tw);
15262
15039
  if (self.bfinally) self.bfinally = self.bfinally.transform(tw);
15263
15040
  });
15264
15041
 
15265
15042
  def_transform(AST_Catch, function(self, tw) {
15266
15043
  if (self.argname) self.argname = self.argname.transform(tw);
15267
- self.body = do_list(self.body, tw);
15044
+ self.body = MAP(self.body, tw);
15268
15045
  });
15269
15046
 
15270
15047
  def_transform(AST_Definitions, function(self, tw) {
15271
- self.definitions = do_list(self.definitions, tw);
15048
+ self.definitions = MAP(self.definitions, tw);
15272
15049
  });
15273
15050
 
15274
15051
  def_transform(AST_VarDef, function(self, tw) {
@@ -15277,26 +15054,26 @@ def_transform(AST_VarDef, function(self, tw) {
15277
15054
  });
15278
15055
 
15279
15056
  def_transform(AST_Destructuring, function(self, tw) {
15280
- self.names = do_list(self.names, tw);
15057
+ self.names = MAP(self.names, tw);
15281
15058
  });
15282
15059
 
15283
15060
  def_transform(AST_Lambda, function(self, tw) {
15284
15061
  if (self.name) self.name = self.name.transform(tw);
15285
- self.argnames = do_list(self.argnames, tw);
15062
+ self.argnames = MAP(self.argnames, tw, /* allow_splicing */ false);
15286
15063
  if (self.body instanceof ast_AST_Node) {
15287
15064
  self.body = self.body.transform(tw);
15288
15065
  } else {
15289
- self.body = do_list(self.body, tw);
15066
+ self.body = MAP(self.body, tw);
15290
15067
  }
15291
15068
  });
15292
15069
 
15293
15070
  def_transform(AST_Call, function(self, tw) {
15294
15071
  self.expression = self.expression.transform(tw);
15295
- self.args = do_list(self.args, tw);
15072
+ self.args = MAP(self.args, tw, /* allow_splicing */ false);
15296
15073
  });
15297
15074
 
15298
15075
  def_transform(ast_AST_Sequence, function(self, tw) {
15299
- const result = do_list(self.expressions, tw);
15076
+ const result = MAP(self.expressions, tw);
15300
15077
  self.expressions = result.length
15301
15078
  ? result
15302
15079
  : [new AST_Number({ value: 0 })];
@@ -15344,11 +15121,11 @@ def_transform(AST_Conditional, function(self, tw) {
15344
15121
  });
15345
15122
 
15346
15123
  def_transform(ast_AST_Array, function(self, tw) {
15347
- self.elements = do_list(self.elements, tw);
15124
+ self.elements = MAP(self.elements, tw);
15348
15125
  });
15349
15126
 
15350
15127
  def_transform(AST_Object, function(self, tw) {
15351
- self.properties = do_list(self.properties, tw);
15128
+ self.properties = MAP(self.properties, tw);
15352
15129
  });
15353
15130
 
15354
15131
  def_transform(AST_ObjectProperty, function(self, tw) {
@@ -15361,11 +15138,11 @@ def_transform(AST_ObjectProperty, function(self, tw) {
15361
15138
  def_transform(AST_Class, function(self, tw) {
15362
15139
  if (self.name) self.name = self.name.transform(tw);
15363
15140
  if (self.extends) self.extends = self.extends.transform(tw);
15364
- self.properties = do_list(self.properties, tw);
15141
+ self.properties = MAP(self.properties, tw);
15365
15142
  });
15366
15143
 
15367
15144
  def_transform(AST_ClassStaticBlock, function(self, tw) {
15368
- self.body = do_list(self.body, tw);
15145
+ self.body = MAP(self.body, tw);
15369
15146
  });
15370
15147
 
15371
15148
  def_transform(AST_Expansion, function(self, tw) {
@@ -15379,19 +15156,19 @@ def_transform(AST_NameMapping, function(self, tw) {
15379
15156
 
15380
15157
  def_transform(AST_Import, function(self, tw) {
15381
15158
  if (self.imported_name) self.imported_name = self.imported_name.transform(tw);
15382
- if (self.imported_names) do_list(self.imported_names, tw);
15159
+ if (self.imported_names) MAP(self.imported_names, tw);
15383
15160
  self.module_name = self.module_name.transform(tw);
15384
15161
  });
15385
15162
 
15386
15163
  def_transform(AST_Export, function(self, tw) {
15387
15164
  if (self.exported_definition) self.exported_definition = self.exported_definition.transform(tw);
15388
15165
  if (self.exported_value) self.exported_value = self.exported_value.transform(tw);
15389
- if (self.exported_names) do_list(self.exported_names, tw);
15166
+ if (self.exported_names) MAP(self.exported_names, tw);
15390
15167
  if (self.module_name) self.module_name = self.module_name.transform(tw);
15391
15168
  });
15392
15169
 
15393
15170
  def_transform(AST_TemplateString, function(self, tw) {
15394
- self.segments = do_list(self.segments, tw);
15171
+ self.segments = MAP(self.segments, tw);
15395
15172
  });
15396
15173
 
15397
15174
  def_transform(AST_PrefixedTemplateString, function(self, tw) {
@@ -15630,7 +15407,7 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
15630
15407
  return new AST_Try({
15631
15408
  start : my_start_token(M),
15632
15409
  end : my_end_token(M),
15633
- body : from_moz(M.block).body,
15410
+ body : new AST_TryBlock(from_moz(M.block)),
15634
15411
  bcatch : from_moz(handlers[0]),
15635
15412
  bfinally : M.finalizer ? new AST_Finally(from_moz(M.finalizer)) : null
15636
15413
  });
@@ -15815,24 +15592,11 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
15815
15592
  var imported_name = null;
15816
15593
  var imported_names = null;
15817
15594
  M.specifiers.forEach(function (specifier) {
15818
- if (specifier.type === "ImportSpecifier") {
15595
+ if (specifier.type === "ImportSpecifier" || specifier.type === "ImportNamespaceSpecifier") {
15819
15596
  if (!imported_names) { imported_names = []; }
15820
- imported_names.push(new AST_NameMapping({
15821
- start: my_start_token(specifier),
15822
- end: my_end_token(specifier),
15823
- foreign_name: from_moz(specifier.imported),
15824
- name: from_moz(specifier.local)
15825
- }));
15597
+ imported_names.push(from_moz(specifier));
15826
15598
  } else if (specifier.type === "ImportDefaultSpecifier") {
15827
- imported_name = from_moz(specifier.local);
15828
- } else if (specifier.type === "ImportNamespaceSpecifier") {
15829
- if (!imported_names) { imported_names = []; }
15830
- imported_names.push(new AST_NameMapping({
15831
- start: my_start_token(specifier),
15832
- end: my_end_token(specifier),
15833
- foreign_name: new AST_SymbolImportForeign({ name: "*" }),
15834
- name: from_moz(specifier.local)
15835
- }));
15599
+ imported_name = from_moz(specifier);
15836
15600
  }
15837
15601
  });
15838
15602
  return new AST_Import({
@@ -15845,14 +15609,39 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
15845
15609
  });
15846
15610
  },
15847
15611
 
15612
+ ImportSpecifier: function(M) {
15613
+ return new AST_NameMapping({
15614
+ start: my_start_token(M),
15615
+ end: my_end_token(M),
15616
+ foreign_name: from_moz(M.imported),
15617
+ name: from_moz(M.local)
15618
+ });
15619
+ },
15620
+
15621
+ ImportDefaultSpecifier: function(M) {
15622
+ return from_moz(M.local);
15623
+ },
15624
+
15625
+ ImportNamespaceSpecifier: function(M) {
15626
+ return new AST_NameMapping({
15627
+ start: my_start_token(M),
15628
+ end: my_end_token(M),
15629
+ foreign_name: new AST_SymbolImportForeign({ name: "*" }),
15630
+ name: from_moz(M.local)
15631
+ });
15632
+ },
15633
+
15848
15634
  ExportAllDeclaration: function(M) {
15635
+ var foreign_name = M.exported == null ?
15636
+ new AST_SymbolExportForeign({ name: "*" }) :
15637
+ from_moz(M.exported);
15849
15638
  return new AST_Export({
15850
15639
  start: my_start_token(M),
15851
15640
  end: my_end_token(M),
15852
15641
  exported_names: [
15853
15642
  new AST_NameMapping({
15854
15643
  name: new AST_SymbolExportForeign({ name: "*" }),
15855
- foreign_name: new AST_SymbolExportForeign({ name: "*" })
15644
+ foreign_name: foreign_name
15856
15645
  })
15857
15646
  ],
15858
15647
  module_name: from_moz(M.source),
@@ -15866,10 +15655,7 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
15866
15655
  end: my_end_token(M),
15867
15656
  exported_definition: from_moz(M.declaration),
15868
15657
  exported_names: M.specifiers && M.specifiers.length ? M.specifiers.map(function (specifier) {
15869
- return new AST_NameMapping({
15870
- foreign_name: from_moz(specifier.exported),
15871
- name: from_moz(specifier.local)
15872
- });
15658
+ return from_moz(specifier);
15873
15659
  }) : null,
15874
15660
  module_name: from_moz(M.source),
15875
15661
  assert_clause: assert_clause_from_moz(M.assertions)
@@ -15885,6 +15671,13 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
15885
15671
  });
15886
15672
  },
15887
15673
 
15674
+ ExportSpecifier: function(M) {
15675
+ return new AST_NameMapping({
15676
+ foreign_name: from_moz(M.exported),
15677
+ name: from_moz(M.local)
15678
+ });
15679
+ },
15680
+
15888
15681
  Literal: function(M) {
15889
15682
  var val = M.value, args = {
15890
15683
  start : my_start_token(M),
@@ -15910,6 +15703,22 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
15910
15703
  if (val === null) return new AST_Null(args);
15911
15704
  switch (typeof val) {
15912
15705
  case "string":
15706
+ args.quote = "\"";
15707
+ var p = FROM_MOZ_STACK[FROM_MOZ_STACK.length - 2];
15708
+ if (p.type == "ImportSpecifier") {
15709
+ args.name = val;
15710
+ return new AST_SymbolImportForeign(args);
15711
+ } else if (p.type == "ExportSpecifier") {
15712
+ args.name = val;
15713
+ if (M == p.exported) {
15714
+ return new AST_SymbolExportForeign(args);
15715
+ } else {
15716
+ return new AST_SymbolExport(args);
15717
+ }
15718
+ } else if (p.type == "ExportAllDeclaration" && M == p.exported) {
15719
+ args.name = val;
15720
+ return new AST_SymbolExportForeign(args);
15721
+ }
15913
15722
  args.value = val;
15914
15723
  return new AST_String(args);
15915
15724
  case "number":
@@ -16569,7 +16378,7 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
16569
16378
  def_to_moz(AST_Try, function To_Moz_TryStatement(M) {
16570
16379
  return {
16571
16380
  type: "TryStatement",
16572
- block: to_moz_block(M),
16381
+ block: to_moz_block(M.body),
16573
16382
  handler: to_moz(M.bcatch),
16574
16383
  guardedHandlers: [],
16575
16384
  finalizer: to_moz(M.bfinally)
@@ -16614,10 +16423,17 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
16614
16423
 
16615
16424
  def_to_moz(AST_Export, function To_Moz_ExportDeclaration(M) {
16616
16425
  if (M.exported_names) {
16617
- if (M.exported_names[0].name.name === "*") {
16426
+ var first_exported = M.exported_names[0];
16427
+ var first_exported_name = first_exported.name;
16428
+ if (first_exported_name.name === "*" && !first_exported_name.quote) {
16429
+ var foreign_name = first_exported.foreign_name;
16430
+ var exported = foreign_name.name === "*" && !foreign_name.quote
16431
+ ? null
16432
+ : to_moz(foreign_name);
16618
16433
  return {
16619
16434
  type: "ExportAllDeclaration",
16620
16435
  source: to_moz(M.module_name),
16436
+ exported: exported,
16621
16437
  assertions: assert_clause_to_moz(M.assert_clause)
16622
16438
  };
16623
16439
  }
@@ -16649,19 +16465,22 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
16649
16465
  local: to_moz(M.imported_name)
16650
16466
  });
16651
16467
  }
16652
- if (M.imported_names && M.imported_names[0].foreign_name.name === "*") {
16653
- specifiers.push({
16654
- type: "ImportNamespaceSpecifier",
16655
- local: to_moz(M.imported_names[0].name)
16656
- });
16657
- } else if (M.imported_names) {
16658
- M.imported_names.forEach(function(name_mapping) {
16468
+ if (M.imported_names) {
16469
+ var first_imported_foreign_name = M.imported_names[0].foreign_name;
16470
+ if (first_imported_foreign_name.name === "*" && !first_imported_foreign_name.quote) {
16659
16471
  specifiers.push({
16660
- type: "ImportSpecifier",
16661
- local: to_moz(name_mapping.name),
16662
- imported: to_moz(name_mapping.foreign_name)
16472
+ type: "ImportNamespaceSpecifier",
16473
+ local: to_moz(M.imported_names[0].name)
16663
16474
  });
16664
- });
16475
+ } else {
16476
+ M.imported_names.forEach(function(name_mapping) {
16477
+ specifiers.push({
16478
+ type: "ImportSpecifier",
16479
+ local: to_moz(name_mapping.name),
16480
+ imported: to_moz(name_mapping.foreign_name)
16481
+ });
16482
+ });
16483
+ }
16665
16484
  }
16666
16485
  return {
16667
16486
  type: "ImportDeclaration",
@@ -16925,7 +16744,14 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
16925
16744
  });
16926
16745
 
16927
16746
  def_to_moz(ast_AST_Symbol, function To_Moz_Identifier(M, parent) {
16928
- if (M instanceof AST_SymbolMethod && parent.quote) {
16747
+ if (
16748
+ (M instanceof AST_SymbolMethod && parent.quote) ||
16749
+ ((
16750
+ M instanceof AST_SymbolImportForeign ||
16751
+ M instanceof AST_SymbolExportForeign ||
16752
+ M instanceof AST_SymbolExport
16753
+ ) && M.quote)
16754
+ ) {
16929
16755
  return {
16930
16756
  type: "Literal",
16931
16757
  value: M.name
@@ -18250,7 +18076,7 @@ function output_OutputStream(options) {
18250
18076
  }
18251
18077
 
18252
18078
  AST_StatementWithBody.DEFMETHOD("_do_print_body", function(output) {
18253
- force_statement(this.body, output);
18079
+ print_maybe_braced_body(this.body, output);
18254
18080
  });
18255
18081
 
18256
18082
  DEFPRINT(AST_Statement, function(self, output) {
@@ -18579,7 +18405,7 @@ function output_OutputStream(options) {
18579
18405
  b = b.body;
18580
18406
  } else break;
18581
18407
  }
18582
- force_statement(self.body, output);
18408
+ print_maybe_braced_body(self.body, output);
18583
18409
  }
18584
18410
  DEFPRINT(AST_If, function(self, output) {
18585
18411
  output.print("if");
@@ -18596,7 +18422,7 @@ function output_OutputStream(options) {
18596
18422
  if (self.alternative instanceof AST_If)
18597
18423
  self.alternative.print(output);
18598
18424
  else
18599
- force_statement(self.alternative, output);
18425
+ print_maybe_braced_body(self.alternative, output);
18600
18426
  } else {
18601
18427
  self._do_print_body(output);
18602
18428
  }
@@ -18645,7 +18471,7 @@ function output_OutputStream(options) {
18645
18471
  DEFPRINT(AST_Try, function(self, output) {
18646
18472
  output.print("try");
18647
18473
  output.space();
18648
- print_braced(self, output);
18474
+ self.body.print(output);
18649
18475
  if (self.bcatch) {
18650
18476
  output.space();
18651
18477
  self.bcatch.print(output);
@@ -18655,6 +18481,9 @@ function output_OutputStream(options) {
18655
18481
  self.bfinally.print(output);
18656
18482
  }
18657
18483
  });
18484
+ DEFPRINT(AST_TryBlock, function(self, output) {
18485
+ print_braced(self, output);
18486
+ });
18658
18487
  DEFPRINT(AST_Catch, function(self, output) {
18659
18488
  output.print("catch");
18660
18489
  if (self.argname) {
@@ -18706,7 +18535,9 @@ function output_OutputStream(options) {
18706
18535
  output.space();
18707
18536
  }
18708
18537
  if (self.imported_names) {
18709
- if (self.imported_names.length === 1 && self.imported_names[0].foreign_name.name === "*") {
18538
+ if (self.imported_names.length === 1 &&
18539
+ self.imported_names[0].foreign_name.name === "*" &&
18540
+ !self.imported_names[0].foreign_name.quote) {
18710
18541
  self.imported_names[0].print(output);
18711
18542
  } else {
18712
18543
  output.print("{");
@@ -18740,14 +18571,31 @@ function output_OutputStream(options) {
18740
18571
  DEFPRINT(AST_NameMapping, function(self, output) {
18741
18572
  var is_import = output.parent() instanceof AST_Import;
18742
18573
  var definition = self.name.definition();
18574
+ var foreign_name = self.foreign_name;
18743
18575
  var names_are_different =
18744
18576
  (definition && definition.mangled_name || self.name.name) !==
18745
- self.foreign_name.name;
18577
+ foreign_name.name;
18578
+ if (!names_are_different &&
18579
+ foreign_name.name === "*" &&
18580
+ foreign_name.quote != self.name.quote) {
18581
+ // export * as "*"
18582
+ names_are_different = true;
18583
+ }
18584
+ var foreign_name_is_name = foreign_name.quote == null;
18746
18585
  if (names_are_different) {
18747
18586
  if (is_import) {
18748
- output.print(self.foreign_name.name);
18587
+ if (foreign_name_is_name) {
18588
+ output.print(foreign_name.name);
18589
+ } else {
18590
+ output.print_string(foreign_name.name, foreign_name.quote);
18591
+ }
18749
18592
  } else {
18750
- self.name.print(output);
18593
+ if (self.name.quote == null) {
18594
+ self.name.print(output);
18595
+ } else {
18596
+ output.print_string(self.name.name, self.name.quote);
18597
+ }
18598
+
18751
18599
  }
18752
18600
  output.space();
18753
18601
  output.print("as");
@@ -18755,10 +18603,18 @@ function output_OutputStream(options) {
18755
18603
  if (is_import) {
18756
18604
  self.name.print(output);
18757
18605
  } else {
18758
- output.print(self.foreign_name.name);
18606
+ if (foreign_name_is_name) {
18607
+ output.print(foreign_name.name);
18608
+ } else {
18609
+ output.print_string(foreign_name.name, foreign_name.quote);
18610
+ }
18759
18611
  }
18760
18612
  } else {
18761
- self.name.print(output);
18613
+ if (self.name.quote == null) {
18614
+ self.name.print(output);
18615
+ } else {
18616
+ output.print_string(self.name.name, self.name.quote);
18617
+ }
18762
18618
  }
18763
18619
  });
18764
18620
 
@@ -18770,8 +18626,10 @@ function output_OutputStream(options) {
18770
18626
  output.space();
18771
18627
  }
18772
18628
  if (self.exported_names) {
18773
- if (self.exported_names.length === 1 && self.exported_names[0].name.name === "*") {
18774
- self.exported_names[0].print(output);
18629
+ if (self.exported_names.length === 1 &&
18630
+ self.exported_names[0].name.name === "*" &&
18631
+ !self.exported_names[0].name.quote) {
18632
+ self.exported_names[0].print(output);
18775
18633
  } else {
18776
18634
  output.print("{");
18777
18635
  self.exported_names.forEach(function(name_export, i) {
@@ -19291,12 +19149,15 @@ function output_OutputStream(options) {
19291
19149
  }
19292
19150
  });
19293
19151
 
19294
- function force_statement(stat, output) {
19152
+ /** if, for, while, may or may not have braces surrounding its body */
19153
+ function print_maybe_braced_body(stat, output) {
19295
19154
  if (output.option("braces")) {
19296
19155
  make_block(stat, output);
19297
19156
  } else {
19298
19157
  if (!stat || stat instanceof AST_EmptyStatement)
19299
19158
  output.force_semicolon();
19159
+ else if (stat instanceof AST_Let || stat instanceof AST_Const || stat instanceof AST_Class)
19160
+ make_block(stat, output);
19300
19161
  else
19301
19162
  stat.print(output);
19302
19163
  }
@@ -19520,7 +19381,7 @@ AST_Switch.prototype.shallow_cmp = pass_through;
19520
19381
  AST_SwitchBranch.prototype.shallow_cmp = pass_through;
19521
19382
 
19522
19383
  AST_Try.prototype.shallow_cmp = function(other) {
19523
- return (this.bcatch == null ? other.bcatch == null : this.bcatch === other.bcatch) && (this.bfinally == null ? other.bfinally == null : this.bfinally === other.bfinally);
19384
+ return (this.body === other.body) && (this.bcatch == null ? other.bcatch == null : this.bcatch === other.bcatch) && (this.bfinally == null ? other.bfinally == null : this.bfinally === other.bfinally);
19524
19385
  };
19525
19386
 
19526
19387
  AST_Catch.prototype.shallow_cmp = function(other) {
@@ -19794,16 +19655,12 @@ AST_Scope.DEFMETHOD("figure_out_scope", function(options, { parent_scope = null,
19794
19655
  const save_scope = scope;
19795
19656
  node.block_scope = scope = new AST_Scope(node);
19796
19657
  scope._block_scope = true;
19797
- // AST_Try in the AST sadly *is* (not has) a body itself,
19798
- // and its catch and finally branches are children of the AST_Try itself
19799
- const parent_scope = node instanceof AST_Catch
19800
- ? save_scope.parent_scope
19801
- : save_scope;
19802
- scope.init_scope_vars(parent_scope);
19658
+ scope.init_scope_vars(save_scope);
19803
19659
  scope.uses_with = save_scope.uses_with;
19804
19660
  scope.uses_eval = save_scope.uses_eval;
19661
+
19805
19662
  if (options.safari10) {
19806
- if (node instanceof AST_For || node instanceof AST_ForIn) {
19663
+ if (node instanceof AST_For || node instanceof AST_ForIn || node instanceof AST_ForOf) {
19807
19664
  for_scopes.push(scope);
19808
19665
  }
19809
19666
  }
@@ -19813,7 +19670,7 @@ AST_Scope.DEFMETHOD("figure_out_scope", function(options, { parent_scope = null,
19813
19670
  // AST_Switch has a scope within the body, but it itself "is a block scope"
19814
19671
  // This means the switched expression has to belong to the outer scope
19815
19672
  // while the body inside belongs to the switch itself.
19816
- // This is pretty nasty and warrants an AST change similar to AST_Try (read above)
19673
+ // This is pretty nasty and warrants an AST change
19817
19674
  const the_block_scope = scope;
19818
19675
  scope = save_scope;
19819
19676
  node.expression.walk(tw);
@@ -20765,9 +20622,7 @@ AST_Default.prototype._size = function () {
20765
20622
  return 8 + list_overhead(this.body);
20766
20623
  };
20767
20624
 
20768
- AST_Try.prototype._size = function () {
20769
- return 3 + list_overhead(this.body);
20770
- };
20625
+ AST_Try.prototype._size = () => 3;
20771
20626
 
20772
20627
  AST_Catch.prototype._size = function () {
20773
20628
  let size = 7 + list_overhead(this.body);
@@ -21312,9 +21167,10 @@ function is_func_expr(node) {
21312
21167
  return node instanceof AST_Arrow || node instanceof AST_Function;
21313
21168
  }
21314
21169
 
21170
+ /**
21171
+ * Used to determine whether the node can benefit from negation.
21172
+ * Not the case with arrow functions (you need an extra set of parens). */
21315
21173
  function is_iife_call(node) {
21316
- // Used to determine whether the node can benefit from negation.
21317
- // Not the case with arrow functions (you need an extra set of parens).
21318
21174
  if (node.TYPE != "Call") return false;
21319
21175
  return node.expression instanceof AST_Function || is_iife_call(node.expression);
21320
21176
  }
@@ -21497,6 +21353,9 @@ const object_methods = [
21497
21353
 
21498
21354
  const is_pure_native_method = make_nested_lookup({
21499
21355
  Array: [
21356
+ "at",
21357
+ "flat",
21358
+ "includes",
21500
21359
  "indexOf",
21501
21360
  "join",
21502
21361
  "lastIndexOf",
@@ -21517,22 +21376,41 @@ const is_pure_native_method = make_nested_lookup({
21517
21376
  ...object_methods,
21518
21377
  ],
21519
21378
  String: [
21379
+ "at",
21520
21380
  "charAt",
21521
21381
  "charCodeAt",
21382
+ "charPointAt",
21522
21383
  "concat",
21384
+ "endsWith",
21385
+ "fromCharCode",
21386
+ "fromCodePoint",
21387
+ "includes",
21523
21388
  "indexOf",
21524
21389
  "italics",
21525
21390
  "lastIndexOf",
21391
+ "localeCompare",
21526
21392
  "match",
21393
+ "matchAll",
21394
+ "normalize",
21395
+ "padStart",
21396
+ "padEnd",
21397
+ "repeat",
21527
21398
  "replace",
21399
+ "replaceAll",
21528
21400
  "search",
21529
21401
  "slice",
21530
21402
  "split",
21403
+ "startsWith",
21531
21404
  "substr",
21532
21405
  "substring",
21406
+ "repeat",
21407
+ "toLocaleLowerCase",
21408
+ "toLocaleUpperCase",
21533
21409
  "toLowerCase",
21534
21410
  "toUpperCase",
21535
21411
  "trim",
21412
+ "trimEnd",
21413
+ "trimStart",
21536
21414
  ...object_methods,
21537
21415
  ],
21538
21416
  });
@@ -21697,7 +21575,7 @@ const unary_side_effects = makePredicate("delete ++ --");
21697
21575
  def_is_number(AST_Number, return_true);
21698
21576
  const unary = makePredicate("+ - ~ ++ --");
21699
21577
  def_is_number(AST_Unary, function() {
21700
- return unary.has(this.operator);
21578
+ return unary.has(this.operator) && !(this.expression instanceof AST_BigInt);
21701
21579
  });
21702
21580
  const numeric_ops = makePredicate("- * / % & | ^ << >> >>>");
21703
21581
  def_is_number(AST_Binary, function(compressor) {
@@ -21826,7 +21704,7 @@ function is_nullish(node, compressor) {
21826
21704
  || any(this.body, compressor);
21827
21705
  });
21828
21706
  def_has_side_effects(AST_Try, function(compressor) {
21829
- return any(this.body, compressor)
21707
+ return this.body.has_side_effects(compressor)
21830
21708
  || this.bcatch && this.bcatch.has_side_effects(compressor)
21831
21709
  || this.bfinally && this.bfinally.has_side_effects(compressor);
21832
21710
  });
@@ -21835,6 +21713,7 @@ function is_nullish(node, compressor) {
21835
21713
  || this.body && this.body.has_side_effects(compressor)
21836
21714
  || this.alternative && this.alternative.has_side_effects(compressor);
21837
21715
  });
21716
+ def_has_side_effects(AST_ImportMeta, return_false);
21838
21717
  def_has_side_effects(AST_LabeledStatement, function(compressor) {
21839
21718
  return this.body.has_side_effects(compressor);
21840
21719
  });
@@ -21938,6 +21817,7 @@ function is_nullish(node, compressor) {
21938
21817
  def_may_throw(AST_Lambda, return_false);
21939
21818
  def_may_throw(AST_SymbolDeclaration, return_false);
21940
21819
  def_may_throw(AST_This, return_false);
21820
+ def_may_throw(AST_ImportMeta, return_false);
21941
21821
 
21942
21822
  function any(list, compressor) {
21943
21823
  for (var i = list.length; --i >= 0;)
@@ -22055,7 +21935,7 @@ function is_nullish(node, compressor) {
22055
21935
  });
22056
21936
  def_may_throw(AST_SymbolClassProperty, return_false);
22057
21937
  def_may_throw(AST_Try, function(compressor) {
22058
- return this.bcatch ? this.bcatch.may_throw(compressor) : any(this.body, compressor)
21938
+ return this.bcatch ? this.bcatch.may_throw(compressor) : this.body.may_throw(compressor)
22059
21939
  || this.bfinally && this.bfinally.may_throw(compressor);
22060
21940
  });
22061
21941
  def_may_throw(AST_Unary, function(compressor) {
@@ -22301,6 +22181,11 @@ function is_lhs(node, parent) {
22301
22181
  var name = this.name + suffix;
22302
22182
  if (HOP(defines, name)) return to_node(defines[name], this);
22303
22183
  });
22184
+ def_find_defs(AST_ImportMeta, function(compressor, suffix) {
22185
+ var defines = compressor.option("global_defs");
22186
+ var name = "import.meta" + suffix;
22187
+ if (HOP(defines, name)) return to_node(defines[name], this);
22188
+ });
22304
22189
  })(function(node, func) {
22305
22190
  node.DEFMETHOD("_find_defs", func);
22306
22191
  });
@@ -23737,15 +23622,17 @@ AST_Scope.DEFMETHOD("drop_unused", function(compressor) {
23737
23622
 
23738
23623
 
23739
23624
 
23740
- // Define the method AST_Node#reduce_vars, which goes through the AST in
23741
- // execution order to perform basic flow analysis
23742
-
23625
+ /**
23626
+ * Define the method AST_Node#reduce_vars, which goes through the AST in
23627
+ * execution order to perform basic flow analysis
23628
+ */
23743
23629
  function def_reduce_vars(node, func) {
23744
23630
  node.DEFMETHOD("reduce_vars", func);
23745
23631
  }
23746
23632
 
23747
23633
  def_reduce_vars(ast_AST_Node, noop);
23748
23634
 
23635
+ /** Clear definition properties */
23749
23636
  function reset_def(compressor, def) {
23750
23637
  def.assignments = 0;
23751
23638
  def.chained = false;
@@ -23754,7 +23641,10 @@ function reset_def(compressor, def) {
23754
23641
  def.recursive_refs = 0;
23755
23642
  def.references = [];
23756
23643
  def.single_use = undefined;
23757
- if (def.scope.pinned()) {
23644
+ if (
23645
+ def.scope.pinned()
23646
+ || (def.orig[0] instanceof AST_SymbolFunarg && def.scope.uses_arguments)
23647
+ ) {
23758
23648
  def.fixed = false;
23759
23649
  } else if (def.orig[0] instanceof AST_SymbolConst || !compressor.exposed(def)) {
23760
23650
  def.fixed = def.init;
@@ -24076,15 +23966,15 @@ def_reduce_vars(AST_Default, function(tw, descend) {
24076
23966
 
24077
23967
  function mark_lambda(tw, descend, compressor) {
24078
23968
  clear_flag(this, INLINED);
23969
+
24079
23970
  push(tw);
23971
+
24080
23972
  reset_variables(tw, compressor, this);
24081
- if (this.uses_arguments) {
24082
- descend();
24083
- pop(tw);
24084
- return;
24085
- }
23973
+
24086
23974
  var iife;
24087
23975
  if (!this.name
23976
+ && !this.uses_arguments
23977
+ && !this.pinned()
24088
23978
  && (iife = tw.parent()) instanceof AST_Call
24089
23979
  && iife.expression === this
24090
23980
  && !iife.args.some(arg => arg instanceof AST_Expansion)
@@ -24109,8 +23999,10 @@ function mark_lambda(tw, descend, compressor) {
24109
23999
  }
24110
24000
  });
24111
24001
  }
24002
+
24112
24003
  descend();
24113
24004
  pop(tw);
24005
+
24114
24006
  return true;
24115
24007
  }
24116
24008
 
@@ -24239,7 +24131,7 @@ def_reduce_vars(AST_Toplevel, function(tw, descend, compressor) {
24239
24131
  def_reduce_vars(AST_Try, function(tw, descend, compressor) {
24240
24132
  reset_block_variables(compressor, this);
24241
24133
  push(tw);
24242
- walk_body(this, tw);
24134
+ this.body.walk(tw);
24243
24135
  pop(tw);
24244
24136
  if (this.bcatch) {
24245
24137
  push(tw);
@@ -24452,13 +24344,11 @@ function tighten_body(statements, compressor) {
24452
24344
  function find_loop_scope_try() {
24453
24345
  var node = compressor.self(), level = 0, in_loop = false, in_try = false;
24454
24346
  do {
24455
- if (node instanceof AST_Catch || node instanceof AST_Finally) {
24456
- level++;
24457
- } else if (node instanceof AST_IterationStatement) {
24347
+ if (node instanceof AST_IterationStatement) {
24458
24348
  in_loop = true;
24459
24349
  } else if (node instanceof AST_Scope) {
24460
24350
  break;
24461
- } else if (node instanceof AST_Try) {
24351
+ } else if (node instanceof AST_TryBlock) {
24462
24352
  in_try = true;
24463
24353
  }
24464
24354
  } while (node = compressor.parent(level++));
@@ -24502,6 +24392,9 @@ function tighten_body(statements, compressor) {
24502
24392
  && (node.logical || node.operator != "=" && lhs.equivalent_to(node.left))
24503
24393
  || node instanceof AST_Await
24504
24394
  || node instanceof AST_Call && lhs instanceof ast_AST_PropAccess && lhs.equivalent_to(node.expression)
24395
+ ||
24396
+ (node instanceof AST_Call || node instanceof ast_AST_PropAccess)
24397
+ && node.optional
24505
24398
  || node instanceof AST_Debugger
24506
24399
  || node instanceof AST_Destructuring
24507
24400
  || node instanceof AST_Expansion
@@ -24675,7 +24568,11 @@ function tighten_body(statements, compressor) {
24675
24568
  var hit = funarg;
24676
24569
  var abort = false, replaced = 0, can_replace = !args || !hit;
24677
24570
  if (!can_replace) {
24678
- for (var j = compressor.self().argnames.lastIndexOf(candidate.name) + 1; !abort && j < args.length; j++) {
24571
+ for (
24572
+ let j = compressor.self().argnames.lastIndexOf(candidate.name) + 1;
24573
+ !abort && j < args.length;
24574
+ j++
24575
+ ) {
24679
24576
  args[j].transform(scanner);
24680
24577
  }
24681
24578
  can_replace = true;
@@ -25622,14 +25519,21 @@ function tighten_body(statements, compressor) {
25622
25519
  CHANGED = true;
25623
25520
  stat.init = exprs.length ? make_sequence(stat.init, exprs) : null;
25624
25521
  statements[++j] = stat;
25625
- } else if (prev instanceof AST_Var && (!stat.init || stat.init.TYPE == prev.TYPE)) {
25522
+ } else if (
25523
+ prev instanceof AST_Var
25524
+ && (!stat.init || stat.init.TYPE == prev.TYPE)
25525
+ ) {
25626
25526
  if (stat.init) {
25627
25527
  prev.definitions = prev.definitions.concat(stat.init.definitions);
25628
25528
  }
25629
25529
  stat.init = prev;
25630
25530
  statements[j] = stat;
25631
25531
  CHANGED = true;
25632
- } else if (defs && stat.init && defs.TYPE == stat.init.TYPE && declarations_only(stat.init)) {
25532
+ } else if (
25533
+ defs instanceof AST_Var
25534
+ && stat.init instanceof AST_Var
25535
+ && declarations_only(stat.init)
25536
+ ) {
25633
25537
  defs.definitions = defs.definitions.concat(stat.init.definitions);
25634
25538
  stat.init = null;
25635
25539
  statements[++j] = stat;
@@ -25732,7 +25636,13 @@ function tighten_body(statements, compressor) {
25732
25636
 
25733
25637
 
25734
25638
 
25735
-
25639
+ /**
25640
+ * Module that contains the inlining logic.
25641
+ *
25642
+ * @module
25643
+ *
25644
+ * The stars of the show are `inline_into_symbolref` and `inline_into_call`.
25645
+ */
25736
25646
 
25737
25647
  function within_array_or_object_literal(compressor) {
25738
25648
  var node, level = 0;
@@ -25763,136 +25673,135 @@ function scope_encloses_variables_in_this_scope(scope, pulled_scope) {
25763
25673
 
25764
25674
  function inline_into_symbolref(self, compressor) {
25765
25675
  const parent = compressor.parent();
25766
- if (compressor.option("reduce_vars") && is_lhs(self, parent) !== self) {
25767
- const def = self.definition();
25768
- const nearest_scope = compressor.find_scope();
25769
- if (compressor.top_retain && def.global && compressor.top_retain(def)) {
25770
- def.fixed = false;
25771
- def.single_use = false;
25772
- return self;
25676
+
25677
+ const def = self.definition();
25678
+ const nearest_scope = compressor.find_scope();
25679
+ if (compressor.top_retain && def.global && compressor.top_retain(def)) {
25680
+ def.fixed = false;
25681
+ def.single_use = false;
25682
+ return self;
25683
+ }
25684
+
25685
+ let fixed = self.fixed_value();
25686
+ let single_use = def.single_use
25687
+ && !(parent instanceof AST_Call
25688
+ && (parent.is_callee_pure(compressor))
25689
+ || has_annotation(parent, _NOINLINE))
25690
+ && !(parent instanceof AST_Export
25691
+ && fixed instanceof AST_Lambda
25692
+ && fixed.name);
25693
+
25694
+ if (single_use && fixed instanceof ast_AST_Node) {
25695
+ single_use =
25696
+ !fixed.has_side_effects(compressor)
25697
+ && !fixed.may_throw(compressor);
25698
+ }
25699
+
25700
+ if (single_use && (fixed instanceof AST_Lambda || fixed instanceof AST_Class)) {
25701
+ if (retain_top_func(fixed, compressor)) {
25702
+ single_use = false;
25703
+ } else if (def.scope !== self.scope
25704
+ && (def.escaped == 1
25705
+ || has_flag(fixed, INLINED)
25706
+ || within_array_or_object_literal(compressor)
25707
+ || !compressor.option("reduce_funcs"))) {
25708
+ single_use = false;
25709
+ } else if (is_recursive_ref(compressor, def)) {
25710
+ single_use = false;
25711
+ } else if (def.scope !== self.scope || def.orig[0] instanceof AST_SymbolFunarg) {
25712
+ single_use = fixed.is_constant_expression(self.scope);
25713
+ if (single_use == "f") {
25714
+ var scope = self.scope;
25715
+ do {
25716
+ if (scope instanceof AST_Defun || is_func_expr(scope)) {
25717
+ set_flag(scope, INLINED);
25718
+ }
25719
+ } while (scope = scope.parent_scope);
25720
+ }
25773
25721
  }
25722
+ }
25774
25723
 
25775
- let fixed = self.fixed_value();
25776
- let single_use = def.single_use
25777
- && !(parent instanceof AST_Call
25778
- && (parent.is_callee_pure(compressor))
25779
- || has_annotation(parent, _NOINLINE))
25780
- && !(parent instanceof AST_Export
25781
- && fixed instanceof AST_Lambda
25782
- && fixed.name);
25783
-
25784
- if (single_use && fixed instanceof ast_AST_Node) {
25785
- single_use =
25786
- !fixed.has_side_effects(compressor)
25787
- && !fixed.may_throw(compressor);
25788
- }
25789
-
25790
- if (single_use && (fixed instanceof AST_Lambda || fixed instanceof AST_Class)) {
25791
- if (retain_top_func(fixed, compressor)) {
25792
- single_use = false;
25793
- } else if (def.scope !== self.scope
25794
- && (def.escaped == 1
25795
- || has_flag(fixed, INLINED)
25796
- || within_array_or_object_literal(compressor)
25797
- || !compressor.option("reduce_funcs"))) {
25798
- single_use = false;
25799
- } else if (is_recursive_ref(compressor, def)) {
25800
- single_use = false;
25801
- } else if (def.scope !== self.scope || def.orig[0] instanceof AST_SymbolFunarg) {
25802
- single_use = fixed.is_constant_expression(self.scope);
25803
- if (single_use == "f") {
25804
- var scope = self.scope;
25805
- do {
25806
- if (scope instanceof AST_Defun || is_func_expr(scope)) {
25807
- set_flag(scope, INLINED);
25808
- }
25809
- } while (scope = scope.parent_scope);
25724
+ if (single_use && (fixed instanceof AST_Lambda || fixed instanceof AST_Class)) {
25725
+ single_use =
25726
+ def.scope === self.scope
25727
+ && !scope_encloses_variables_in_this_scope(nearest_scope, fixed)
25728
+ || parent instanceof AST_Call
25729
+ && parent.expression === self
25730
+ && !scope_encloses_variables_in_this_scope(nearest_scope, fixed)
25731
+ && !(fixed.name && fixed.name.definition().recursive_refs > 0);
25732
+ }
25733
+
25734
+ if (single_use && fixed) {
25735
+ if (fixed instanceof AST_DefClass) {
25736
+ set_flag(fixed, SQUEEZED);
25737
+ fixed = make_node(AST_ClassExpression, fixed, fixed);
25738
+ }
25739
+ if (fixed instanceof AST_Defun) {
25740
+ set_flag(fixed, SQUEEZED);
25741
+ fixed = make_node(AST_Function, fixed, fixed);
25742
+ }
25743
+ if (def.recursive_refs > 0 && fixed.name instanceof AST_SymbolDefun) {
25744
+ const defun_def = fixed.name.definition();
25745
+ let lambda_def = fixed.variables.get(fixed.name.name);
25746
+ let name = lambda_def && lambda_def.orig[0];
25747
+ if (!(name instanceof AST_SymbolLambda)) {
25748
+ name = make_node(AST_SymbolLambda, fixed.name, fixed.name);
25749
+ name.scope = fixed;
25750
+ fixed.name = name;
25751
+ lambda_def = fixed.def_function(name);
25752
+ }
25753
+ ast_walk(fixed, node => {
25754
+ if (node instanceof AST_SymbolRef && node.definition() === defun_def) {
25755
+ node.thedef = lambda_def;
25756
+ lambda_def.references.push(node);
25810
25757
  }
25811
- }
25758
+ });
25812
25759
  }
25760
+ if (
25761
+ (fixed instanceof AST_Lambda || fixed instanceof AST_Class)
25762
+ && fixed.parent_scope !== nearest_scope
25763
+ ) {
25764
+ fixed = fixed.clone(true, compressor.get_toplevel());
25813
25765
 
25814
- if (single_use && (fixed instanceof AST_Lambda || fixed instanceof AST_Class)) {
25815
- single_use =
25816
- def.scope === self.scope
25817
- && !scope_encloses_variables_in_this_scope(nearest_scope, fixed)
25818
- || parent instanceof AST_Call
25819
- && parent.expression === self
25820
- && !scope_encloses_variables_in_this_scope(nearest_scope, fixed)
25821
- && !(fixed.name && fixed.name.definition().recursive_refs > 0);
25766
+ nearest_scope.add_child_scope(fixed);
25822
25767
  }
25768
+ return fixed.optimize(compressor);
25769
+ }
25823
25770
 
25824
- if (single_use && fixed) {
25825
- if (fixed instanceof AST_DefClass) {
25826
- set_flag(fixed, SQUEEZED);
25827
- fixed = make_node(AST_ClassExpression, fixed, fixed);
25828
- }
25829
- if (fixed instanceof AST_Defun) {
25830
- set_flag(fixed, SQUEEZED);
25831
- fixed = make_node(AST_Function, fixed, fixed);
25832
- }
25833
- if (def.recursive_refs > 0 && fixed.name instanceof AST_SymbolDefun) {
25834
- const defun_def = fixed.name.definition();
25835
- let lambda_def = fixed.variables.get(fixed.name.name);
25836
- let name = lambda_def && lambda_def.orig[0];
25837
- if (!(name instanceof AST_SymbolLambda)) {
25838
- name = make_node(AST_SymbolLambda, fixed.name, fixed.name);
25839
- name.scope = fixed;
25840
- fixed.name = name;
25841
- lambda_def = fixed.def_function(name);
25842
- }
25843
- ast_walk(fixed, node => {
25844
- if (node instanceof AST_SymbolRef && node.definition() === defun_def) {
25845
- node.thedef = lambda_def;
25846
- lambda_def.references.push(node);
25847
- }
25848
- });
25771
+ // multiple uses
25772
+ if (fixed) {
25773
+ let replace;
25774
+
25775
+ if (fixed instanceof AST_This) {
25776
+ if (!(def.orig[0] instanceof AST_SymbolFunarg)
25777
+ && def.references.every((ref) =>
25778
+ def.scope === ref.scope
25779
+ )) {
25780
+ replace = fixed;
25849
25781
  }
25782
+ } else {
25783
+ var ev = fixed.evaluate(compressor);
25850
25784
  if (
25851
- (fixed instanceof AST_Lambda || fixed instanceof AST_Class)
25852
- && fixed.parent_scope !== nearest_scope
25785
+ ev !== fixed
25786
+ && (compressor.option("unsafe_regexp") || !(ev instanceof RegExp))
25853
25787
  ) {
25854
- fixed = fixed.clone(true, compressor.get_toplevel());
25855
-
25856
- nearest_scope.add_child_scope(fixed);
25788
+ replace = make_node_from_constant(ev, fixed);
25857
25789
  }
25858
- return fixed.optimize(compressor);
25859
25790
  }
25860
25791
 
25861
- // multiple uses
25862
- if (fixed) {
25863
- let replace;
25792
+ if (replace) {
25793
+ const name_length = self.size(compressor);
25794
+ const replace_size = replace.size(compressor);
25864
25795
 
25865
- if (fixed instanceof AST_This) {
25866
- if (!(def.orig[0] instanceof AST_SymbolFunarg)
25867
- && def.references.every((ref) =>
25868
- def.scope === ref.scope
25869
- )) {
25870
- replace = fixed;
25871
- }
25872
- } else {
25873
- var ev = fixed.evaluate(compressor);
25874
- if (
25875
- ev !== fixed
25876
- && (compressor.option("unsafe_regexp") || !(ev instanceof RegExp))
25877
- ) {
25878
- replace = make_node_from_constant(ev, fixed);
25879
- }
25796
+ let overhead = 0;
25797
+ if (compressor.option("unused") && !compressor.exposed(def)) {
25798
+ overhead =
25799
+ (name_length + 2 + replace_size) /
25800
+ (def.references.length - def.assignments);
25880
25801
  }
25881
25802
 
25882
- if (replace) {
25883
- const name_length = self.size(compressor);
25884
- const replace_size = replace.size(compressor);
25885
-
25886
- let overhead = 0;
25887
- if (compressor.option("unused") && !compressor.exposed(def)) {
25888
- overhead =
25889
- (name_length + 2 + replace_size) /
25890
- (def.references.length - def.assignments);
25891
- }
25892
-
25893
- if (replace_size <= name_length + overhead) {
25894
- return replace;
25895
- }
25803
+ if (replace_size <= name_length + overhead) {
25804
+ return replace;
25896
25805
  }
25897
25806
  }
25898
25807
  }
@@ -26632,7 +26541,7 @@ AST_Toplevel.DEFMETHOD("reset_opt_flags", function(compressor) {
26632
26541
  }
26633
26542
  return node.reduce_vars(preparation, descend, compressor);
26634
26543
  }
26635
- });
26544
+ }, { walk_defun_first: true });
26636
26545
  // Stack of look-up tables to keep track of whether a `SymbolDef` has been
26637
26546
  // properly assigned before use:
26638
26547
  // - `push()` & `pop()` when visiting conditional branches
@@ -27622,9 +27531,9 @@ def_optimize(AST_Switch, function(self, compressor) {
27622
27531
  });
27623
27532
 
27624
27533
  def_optimize(AST_Try, function(self, compressor) {
27625
- tighten_body(self.body, compressor);
27626
27534
  if (self.bcatch && self.bfinally && self.bfinally.body.every(is_empty)) self.bfinally = null;
27627
- if (compressor.option("dead_code") && self.body.every(is_empty)) {
27535
+
27536
+ if (compressor.option("dead_code") && self.body.body.every(is_empty)) {
27628
27537
  var body = [];
27629
27538
  if (self.bcatch) {
27630
27539
  trim_unreachable_code(compressor, self.bcatch, body);
@@ -28830,16 +28739,21 @@ def_optimize(ast_AST_Assign, function(self, compressor) {
28830
28739
  return self;
28831
28740
 
28832
28741
  function in_try(level, node) {
28833
- var right = self.right;
28834
- self.right = make_node(AST_Null, right);
28835
- var may_throw = node.may_throw(compressor);
28836
- self.right = right;
28837
- var scope = self.left.definition().scope;
28742
+ function may_assignment_throw() {
28743
+ const right = self.right;
28744
+ self.right = make_node(AST_Null, right);
28745
+ const may_throw = node.may_throw(compressor);
28746
+ self.right = right;
28747
+
28748
+ return may_throw;
28749
+ }
28750
+
28751
+ var stop_at = self.left.definition().scope.get_defun_scope();
28838
28752
  var parent;
28839
- while ((parent = compressor.parent(level++)) !== scope) {
28753
+ while ((parent = compressor.parent(level++)) !== stop_at) {
28840
28754
  if (parent instanceof AST_Try) {
28841
28755
  if (parent.bfinally) return true;
28842
- if (may_throw && parent.bcatch) return true;
28756
+ if (parent.bcatch && may_assignment_throw()) return true;
28843
28757
  }
28844
28758
  }
28845
28759
  }
@@ -28852,7 +28766,13 @@ def_optimize(AST_DefaultAssign, function(self, compressor) {
28852
28766
  var evaluateRight = self.right.evaluate(compressor);
28853
28767
 
28854
28768
  // `[x = undefined] = foo` ---> `[x] = foo`
28855
- if (evaluateRight === undefined) {
28769
+ // `(arg = undefined) => ...` ---> `(arg) => ...` (unless `keep_fargs`)
28770
+ if (
28771
+ evaluateRight === undefined &&
28772
+ (compressor.parent() instanceof AST_Lambda
28773
+ ? compressor.option("keep_fargs") === false
28774
+ : true)
28775
+ ) {
28856
28776
  self = self.left;
28857
28777
  } else if (evaluateRight !== self.right) {
28858
28778
  evaluateRight = make_node_from_constant(evaluateRight, self.right);
@@ -39081,12 +39001,15 @@ function mangle_properties(ast, options) {
39081
39001
 
39082
39002
 
39083
39003
 
39084
- var to_ascii = typeof atob == "undefined" ? function(b64) {
39085
- return Buffer.from(b64, "base64").toString();
39086
- } : atob;
39087
- var to_base64 = typeof btoa == "undefined" ? function(str) {
39088
- return Buffer.from(str).toString("base64");
39089
- } : btoa;
39004
+ // to/from base64 functions
39005
+ // Prefer built-in Buffer, if available, then use hack
39006
+ // https://developer.mozilla.org/en-US/docs/Glossary/Base64#The_Unicode_Problem
39007
+ var to_ascii = typeof Buffer !== "undefined"
39008
+ ? (b64) => Buffer.from(b64, "base64").toString()
39009
+ : (b64) => decodeURIComponent(escape(atob(b64)));
39010
+ var to_base64 = typeof Buffer !== "undefined"
39011
+ ? (str) => Buffer.from(str).toString("base64")
39012
+ : (str) => btoa(unescape(encodeURIComponent(str)));
39090
39013
 
39091
39014
  function read_source_map(code) {
39092
39015
  var match = /(?:^|[^.])\/\/# sourceMappingURL=data:application\/json(;[\w=-]*)?;base64,([+/0-9A-Za-z]*=*)\s*$/.exec(code);
@@ -39336,10 +39259,13 @@ async function minify_minify(files, options, _fs_module) {
39336
39259
  if (options.format.spidermonkey) {
39337
39260
  result.ast = toplevel.to_mozilla_ast();
39338
39261
  }
39262
+ let format_options;
39339
39263
  if (!HOP(options.format, "code") || options.format.code) {
39340
- if (!options.format.ast) {
39264
+ // Make a shallow copy so that we can modify without mutating the user's input.
39265
+ format_options = {...options.format};
39266
+ if (!format_options.ast) {
39341
39267
  // Destroy stuff to save RAM. (unless the deprecated `ast` option is on)
39342
- options.format._destroy_ast = true;
39268
+ format_options._destroy_ast = true;
39343
39269
 
39344
39270
  ast_walk(toplevel, node => {
39345
39271
  if (node instanceof AST_Scope) {
@@ -39359,17 +39285,17 @@ async function minify_minify(files, options, _fs_module) {
39359
39285
  if (options.sourceMap.includeSources && files instanceof AST_Toplevel) {
39360
39286
  throw new Error("original source content unavailable");
39361
39287
  }
39362
- options.format.source_map = await SourceMap({
39288
+ format_options.source_map = await SourceMap({
39363
39289
  file: options.sourceMap.filename,
39364
39290
  orig: options.sourceMap.content,
39365
39291
  root: options.sourceMap.root,
39366
39292
  files: options.sourceMap.includeSources ? files : null,
39367
39293
  });
39368
39294
  }
39369
- delete options.format.ast;
39370
- delete options.format.code;
39371
- delete options.format.spidermonkey;
39372
- var stream = output_OutputStream(options.format);
39295
+ delete format_options.ast;
39296
+ delete format_options.code;
39297
+ delete format_options.spidermonkey;
39298
+ var stream = output_OutputStream(format_options);
39373
39299
  toplevel.print(stream);
39374
39300
  result.code = stream.get();
39375
39301
  if (options.sourceMap) {
@@ -39377,7 +39303,7 @@ async function minify_minify(files, options, _fs_module) {
39377
39303
  configurable: true,
39378
39304
  enumerable: true,
39379
39305
  get() {
39380
- const map = options.format.source_map.getEncoded();
39306
+ const map = format_options.source_map.getEncoded();
39381
39307
  return (result.map = options.sourceMap.asObject ? map : JSON.stringify(map));
39382
39308
  },
39383
39309
  set(value) {
@@ -39387,7 +39313,7 @@ async function minify_minify(files, options, _fs_module) {
39387
39313
  });
39388
39314
  }
39389
39315
  });
39390
- result.decoded_map = options.format.source_map.getDecoded();
39316
+ result.decoded_map = format_options.source_map.getDecoded();
39391
39317
  if (options.sourceMap.url == "inline") {
39392
39318
  var sourceMap = typeof result.map === "object" ? JSON.stringify(result.map) : result.map;
39393
39319
  result.code += "\n//# sourceMappingURL=data:application/json;charset=utf-8;base64," + to_base64(sourceMap);
@@ -39402,8 +39328,8 @@ async function minify_minify(files, options, _fs_module) {
39402
39328
  options.nameCache.props = cache_to_json(options.mangle.properties.cache);
39403
39329
  }
39404
39330
  }
39405
- if (options.format && options.format.source_map) {
39406
- options.format.source_map.destroy();
39331
+ if (format_options && format_options.source_map) {
39332
+ format_options.source_map.destroy();
39407
39333
  }
39408
39334
  if (timings) {
39409
39335
  timings.end = Date.now();
@@ -40920,7 +40846,9 @@ __nccwpck_require__.a(__webpack_module__, async (__webpack_handle_async_dependen
40920
40846
  /* harmony export */ "S0": () => (/* binding */ print),
40921
40847
  /* harmony export */ "Xs": () => (/* binding */ metadataAdd),
40922
40848
  /* harmony export */ "YO": () => (/* binding */ componentWit),
40923
- /* harmony export */ "eL": () => (/* binding */ metadataShow)
40849
+ /* harmony export */ "eL": () => (/* binding */ metadataShow),
40850
+ /* harmony export */ "ol": () => (/* binding */ preview1AdapterCommandPath),
40851
+ /* harmony export */ "tc": () => (/* binding */ preview1AdapterReactorPath)
40924
40852
  /* harmony export */ });
40925
40853
  /* harmony import */ var _cmd_opt_js__WEBPACK_IMPORTED_MODULE_0__ = __nccwpck_require__(5862);
40926
40854
  /* harmony import */ var _cmd_transpile_js__WEBPACK_IMPORTED_MODULE_1__ = __nccwpck_require__(2229);
@@ -40931,6 +40859,12 @@ var __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([_cmd
40931
40859
 
40932
40860
 
40933
40861
  const { parse, print, componentNew, componentWit, componentEmbed, metadataAdd, metadataShow } = _obj_wasm_tools_js__WEBPACK_IMPORTED_MODULE_2__/* .exports */ .I;
40862
+ function preview1AdapterCommandPath () {
40863
+ return __nccwpck_require__.ab + "wasi_snapshot_preview1.command.wasm";
40864
+ }
40865
+ function preview1AdapterReactorPath () {
40866
+ return __nccwpck_require__.ab + "wasi_snapshot_preview1.reactor.wasm";
40867
+ }
40934
40868
 
40935
40869
  __webpack_async_result__();
40936
40870
  } catch(e) { __webpack_async_result__(e); } });
@@ -40950,7 +40884,7 @@ __nccwpck_require__.a(__webpack_module__, async (__webpack_handle_async_dependen
40950
40884
  /* harmony import */ var url__WEBPACK_IMPORTED_MODULE_2__ = __nccwpck_require__(7310);
40951
40885
  /* harmony import */ var chalk_template__WEBPACK_IMPORTED_MODULE_3__ = __nccwpck_require__(267);
40952
40886
  /* harmony import */ var _common_js__WEBPACK_IMPORTED_MODULE_4__ = __nccwpck_require__(8649);
40953
- /* harmony import */ var ora__WEBPACK_IMPORTED_MODULE_5__ = __nccwpck_require__(67);
40887
+ /* harmony import */ var ora__WEBPACK_IMPORTED_MODULE_5__ = __nccwpck_require__(2719);
40954
40888
  var __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([_obj_wasm_tools_js__WEBPACK_IMPORTED_MODULE_0__]);
40955
40889
  _obj_wasm_tools_js__WEBPACK_IMPORTED_MODULE_0__ = (__webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__)[0];
40956
40890
 
@@ -41021,7 +40955,7 @@ async function optimizeComponent (componentBytes, opts) {
41021
40955
  let completed = 0;
41022
40956
  const spinnerText = () => chalk_template__WEBPACK_IMPORTED_MODULE_3__/* ["default"] */ .Z`{cyan ${completed} / ${coreModules.length}} Running Binaryen on WebAssembly Component Internal Core Modules \n`;
41023
40957
  if (showSpinner) {
41024
- spinner = (0,ora__WEBPACK_IMPORTED_MODULE_5__/* ["default"] */ .Z)({
40958
+ spinner = (0,ora__WEBPACK_IMPORTED_MODULE_5__/* ["default"] */ .ZP)({
41025
40959
  color: 'cyan',
41026
40960
  spinner: 'bouncingBar'
41027
40961
  }).start();
@@ -41093,7 +41027,7 @@ async function optimizeComponent (componentBytes, opts) {
41093
41027
  * @param {Uint8Array} source
41094
41028
  * @returns {Promise<Uint8Array>}
41095
41029
  */
41096
- async function wasmOpt (source, args = ['-tnh', '--gufa', '--flatten', '--rereloop', '-Oz', '-Oz', '--low-memory-unused', '--enable-bulk-memory']) {
41030
+ async function wasmOpt (source, args = ['-O1', '--low-memory-unused', '--enable-bulk-memory']) {
41097
41031
  try {
41098
41032
  return await (0,_common_js__WEBPACK_IMPORTED_MODULE_4__/* .spawnIOTmp */ .np)(WASM_OPT, source, [
41099
41033
  ...args, '-o'
@@ -41126,7 +41060,7 @@ __nccwpck_require__.a(__webpack_module__, async (__webpack_handle_async_dependen
41126
41060
  /* harmony import */ var _opt_js__WEBPACK_IMPORTED_MODULE_5__ = __nccwpck_require__(5862);
41127
41061
  /* harmony import */ var terser__WEBPACK_IMPORTED_MODULE_6__ = __nccwpck_require__(1124);
41128
41062
  /* harmony import */ var url__WEBPACK_IMPORTED_MODULE_7__ = __nccwpck_require__(7310);
41129
- /* harmony import */ var ora__WEBPACK_IMPORTED_MODULE_8__ = __nccwpck_require__(67);
41063
+ /* harmony import */ var ora__WEBPACK_IMPORTED_MODULE_8__ = __nccwpck_require__(2719);
41130
41064
  var __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([_obj_js_component_bindgen_component_js__WEBPACK_IMPORTED_MODULE_0__, _opt_js__WEBPACK_IMPORTED_MODULE_5__]);
41131
41065
  ([_obj_js_component_bindgen_component_js__WEBPACK_IMPORTED_MODULE_0__, _opt_js__WEBPACK_IMPORTED_MODULE_5__] = __webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__);
41132
41066
 
@@ -41249,7 +41183,7 @@ async function transpileComponent (component, opts = {}) {
41249
41183
  let completed = 0;
41250
41184
  const spinnerText = () => chalk_template__WEBPACK_IMPORTED_MODULE_3__/* ["default"] */ .Z`{cyan ${completed} / ${wasmFiles.length}} Running Binaryen wasm2js on Wasm core modules (this takes a while)...\n`;
41251
41185
  if (showSpinner) {
41252
- spinner = (0,ora__WEBPACK_IMPORTED_MODULE_8__/* ["default"] */ .Z)({
41186
+ spinner = (0,ora__WEBPACK_IMPORTED_MODULE_8__/* ["default"] */ .ZP)({
41253
41187
  color: 'cyan',
41254
41188
  spinner: 'bouncingBar'
41255
41189
  }).start();
@@ -41828,7 +41762,9 @@ module.exports = JSON.parse('{"dots":{"interval":80,"frames":["⠋","⠙","⠹",
41828
41762
  /******/ var __webpack_exports__metadataShow = __webpack_exports__.eL;
41829
41763
  /******/ var __webpack_exports__opt = __webpack_exports__.MD;
41830
41764
  /******/ var __webpack_exports__parse = __webpack_exports__.Qc;
41765
+ /******/ var __webpack_exports__preview1AdapterCommandPath = __webpack_exports__.ol;
41766
+ /******/ var __webpack_exports__preview1AdapterReactorPath = __webpack_exports__.tc;
41831
41767
  /******/ var __webpack_exports__print = __webpack_exports__.S0;
41832
41768
  /******/ var __webpack_exports__transpile = __webpack_exports__.LZ;
41833
- /******/ export { __webpack_exports__componentEmbed as componentEmbed, __webpack_exports__componentNew as componentNew, __webpack_exports__componentWit as componentWit, __webpack_exports__metadataAdd as metadataAdd, __webpack_exports__metadataShow as metadataShow, __webpack_exports__opt as opt, __webpack_exports__parse as parse, __webpack_exports__print as print, __webpack_exports__transpile as transpile };
41769
+ /******/ export { __webpack_exports__componentEmbed as componentEmbed, __webpack_exports__componentNew as componentNew, __webpack_exports__componentWit as componentWit, __webpack_exports__metadataAdd as metadataAdd, __webpack_exports__metadataShow as metadataShow, __webpack_exports__opt as opt, __webpack_exports__parse as parse, __webpack_exports__preview1AdapterCommandPath as preview1AdapterCommandPath, __webpack_exports__preview1AdapterReactorPath as preview1AdapterReactorPath, __webpack_exports__print as print, __webpack_exports__transpile as transpile };
41834
41770
  /******/