msw 0.34.0 → 0.35.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/lib/esm/index.js CHANGED
@@ -1428,8 +1428,10 @@ Read more: https://mswjs.io/docs/getting-started/mocks\
1428
1428
  const message = messageTemplate.join('\n\n');
1429
1429
  switch (strategy) {
1430
1430
  case 'error': {
1431
+ // Print a developer-friendly error.
1431
1432
  devUtils.error('Error: %s', message);
1432
- break;
1433
+ // Throw an exception to halt request processing and not perform the original request.
1434
+ throw new Error('Cannot bypass a request when using the "error" strategy for the "onUnhandledRequest" option.');
1433
1435
  }
1434
1436
  case 'warn': {
1435
1437
  devUtils.warn('Warning: %s', message);
@@ -1709,16 +1711,14 @@ function printStopMessage(args = {}) {
1709
1711
  }
1710
1712
 
1711
1713
  const createStop = (context) => {
1712
- /**
1713
- * Signal the Service Worker to disable mocking for this client.
1714
- * Use this an an explicit way to stop the mocking, while preserving
1715
- * the worker-client relation. Does not affect the worker's lifecycle.
1716
- */
1717
1714
  return function stop() {
1718
1715
  var _a;
1716
+ /**
1717
+ * Signal the Service Worker to disable mocking for this client.
1718
+ * Use this an an explicit way to stop the mocking, while preserving
1719
+ * the worker-client relation. Does not affect the worker's lifecycle.
1720
+ */
1719
1721
  context.workerChannel.send('MOCK_DEACTIVATE');
1720
- context.events.removeAllListeners();
1721
- context.emitter.removeAllListeners();
1722
1722
  window.clearInterval(context.keepAliveInterval);
1723
1723
  printStopMessage({ quiet: (_a = context.startOptions) === null || _a === void 0 ? void 0 : _a.quiet });
1724
1724
  };
@@ -2169,9 +2169,179 @@ var XMLHttpRequestOverride = {};
2169
2169
 
2170
2170
  var domParser = {};
2171
2171
 
2172
- var entities = {};
2172
+ var conventions$2 = {};
2173
+
2174
+ /**
2175
+ * "Shallow freezes" an object to render it immutable.
2176
+ * Uses `Object.freeze` if available,
2177
+ * otherwise the immutability is only in the type.
2178
+ *
2179
+ * Is used to create "enum like" objects.
2180
+ *
2181
+ * @template T
2182
+ * @param {T} object the object to freeze
2183
+ * @param {Pick<ObjectConstructor, 'freeze'> = Object} oc `Object` by default,
2184
+ * allows to inject custom object constructor for tests
2185
+ * @returns {Readonly<T>}
2186
+ *
2187
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze
2188
+ */
2189
+ function freeze(object, oc) {
2190
+ if (oc === undefined) {
2191
+ oc = Object;
2192
+ }
2193
+ return oc && typeof oc.freeze === 'function' ? oc.freeze(object) : object
2194
+ }
2195
+
2196
+ /**
2197
+ * All mime types that are allowed as input to `DOMParser.parseFromString`
2198
+ *
2199
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/DOMParser/parseFromString#Argument02 MDN
2200
+ * @see https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#domparsersupportedtype WHATWG HTML Spec
2201
+ * @see DOMParser.prototype.parseFromString
2202
+ */
2203
+ var MIME_TYPE = freeze({
2204
+ /**
2205
+ * `text/html`, the only mime type that triggers treating an XML document as HTML.
2206
+ *
2207
+ * @see DOMParser.SupportedType.isHTML
2208
+ * @see https://www.iana.org/assignments/media-types/text/html IANA MimeType registration
2209
+ * @see https://en.wikipedia.org/wiki/HTML Wikipedia
2210
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/DOMParser/parseFromString MDN
2211
+ * @see https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-domparser-parsefromstring WHATWG HTML Spec
2212
+ */
2213
+ HTML: 'text/html',
2214
+
2215
+ /**
2216
+ * Helper method to check a mime type if it indicates an HTML document
2217
+ *
2218
+ * @param {string} [value]
2219
+ * @returns {boolean}
2220
+ *
2221
+ * @see https://www.iana.org/assignments/media-types/text/html IANA MimeType registration
2222
+ * @see https://en.wikipedia.org/wiki/HTML Wikipedia
2223
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/DOMParser/parseFromString MDN
2224
+ * @see https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-domparser-parsefromstring */
2225
+ isHTML: function (value) {
2226
+ return value === MIME_TYPE.HTML
2227
+ },
2228
+
2229
+ /**
2230
+ * `application/xml`, the standard mime type for XML documents.
2231
+ *
2232
+ * @see https://www.iana.org/assignments/media-types/application/xml IANA MimeType registration
2233
+ * @see https://tools.ietf.org/html/rfc7303#section-9.1 RFC 7303
2234
+ * @see https://en.wikipedia.org/wiki/XML_and_MIME Wikipedia
2235
+ */
2236
+ XML_APPLICATION: 'application/xml',
2173
2237
 
2174
- entities.entityMap = {
2238
+ /**
2239
+ * `text/html`, an alias for `application/xml`.
2240
+ *
2241
+ * @see https://tools.ietf.org/html/rfc7303#section-9.2 RFC 7303
2242
+ * @see https://www.iana.org/assignments/media-types/text/xml IANA MimeType registration
2243
+ * @see https://en.wikipedia.org/wiki/XML_and_MIME Wikipedia
2244
+ */
2245
+ XML_TEXT: 'text/xml',
2246
+
2247
+ /**
2248
+ * `application/xhtml+xml`, indicates an XML document that has the default HTML namespace,
2249
+ * but is parsed as an XML document.
2250
+ *
2251
+ * @see https://www.iana.org/assignments/media-types/application/xhtml+xml IANA MimeType registration
2252
+ * @see https://dom.spec.whatwg.org/#dom-domimplementation-createdocument WHATWG DOM Spec
2253
+ * @see https://en.wikipedia.org/wiki/XHTML Wikipedia
2254
+ */
2255
+ XML_XHTML_APPLICATION: 'application/xhtml+xml',
2256
+
2257
+ /**
2258
+ * `image/svg+xml`,
2259
+ *
2260
+ * @see https://www.iana.org/assignments/media-types/image/svg+xml IANA MimeType registration
2261
+ * @see https://www.w3.org/TR/SVG11/ W3C SVG 1.1
2262
+ * @see https://en.wikipedia.org/wiki/Scalable_Vector_Graphics Wikipedia
2263
+ */
2264
+ XML_SVG_IMAGE: 'image/svg+xml',
2265
+ });
2266
+
2267
+ /**
2268
+ * Namespaces that are used in this code base.
2269
+ *
2270
+ * @see http://www.w3.org/TR/REC-xml-names
2271
+ */
2272
+ var NAMESPACE$3 = freeze({
2273
+ /**
2274
+ * The XHTML namespace.
2275
+ *
2276
+ * @see http://www.w3.org/1999/xhtml
2277
+ */
2278
+ HTML: 'http://www.w3.org/1999/xhtml',
2279
+
2280
+ /**
2281
+ * Checks if `uri` equals `NAMESPACE.HTML`.
2282
+ *
2283
+ * @param {string} [uri]
2284
+ *
2285
+ * @see NAMESPACE.HTML
2286
+ */
2287
+ isHTML: function (uri) {
2288
+ return uri === NAMESPACE$3.HTML
2289
+ },
2290
+
2291
+ /**
2292
+ * The SVG namespace.
2293
+ *
2294
+ * @see http://www.w3.org/2000/svg
2295
+ */
2296
+ SVG: 'http://www.w3.org/2000/svg',
2297
+
2298
+ /**
2299
+ * The `xml:` namespace.
2300
+ *
2301
+ * @see http://www.w3.org/XML/1998/namespace
2302
+ */
2303
+ XML: 'http://www.w3.org/XML/1998/namespace',
2304
+
2305
+ /**
2306
+ * The `xmlns:` namespace
2307
+ *
2308
+ * @see https://www.w3.org/2000/xmlns/
2309
+ */
2310
+ XMLNS: 'http://www.w3.org/2000/xmlns/',
2311
+ });
2312
+
2313
+ conventions$2.freeze = freeze;
2314
+ conventions$2.MIME_TYPE = MIME_TYPE;
2315
+ conventions$2.NAMESPACE = NAMESPACE$3;
2316
+
2317
+ var entities$1 = {};
2318
+
2319
+ (function (exports) {
2320
+ var freeze = conventions$2.freeze;
2321
+
2322
+ /**
2323
+ * The entities that are predefined in every XML document.
2324
+ *
2325
+ * @see https://www.w3.org/TR/2006/REC-xml11-20060816/#sec-predefined-ent W3C XML 1.1
2326
+ * @see https://www.w3.org/TR/2008/REC-xml-20081126/#sec-predefined-ent W3C XML 1.0
2327
+ * @see https://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references#Predefined_entities_in_XML Wikipedia
2328
+ */
2329
+ exports.XML_ENTITIES = freeze({amp:'&', apos:"'", gt:'>', lt:'<', quot:'"'});
2330
+
2331
+ /**
2332
+ * A map of currently 241 entities that are detected in an HTML document.
2333
+ * They contain all entries from `XML_ENTITIES`.
2334
+ *
2335
+ * @see XML_ENTITIES
2336
+ * @see DOMParser.parseFromString
2337
+ * @see DOMImplementation.prototype.createHTMLDocument
2338
+ * @see https://html.spec.whatwg.org/#named-character-references WHATWG HTML(5) Spec
2339
+ * @see https://www.w3.org/TR/xml-entity-names/ W3C XML Entity Names
2340
+ * @see https://www.w3.org/TR/html4/sgml/entities.html W3C HTML4/SGML
2341
+ * @see https://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references#Character_entity_references_in_HTML Wikipedia (HTML)
2342
+ * @see https://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references#Entities_representing_special_characters_in_XHTML Wikpedia (XHTML)
2343
+ */
2344
+ exports.HTML_ENTITIES = freeze({
2175
2345
  lt: '<',
2176
2346
  gt: '>',
2177
2347
  amp: '&',
@@ -2413,10 +2583,19 @@ entities.entityMap = {
2413
2583
  clubs: "♣",
2414
2584
  hearts: "♥",
2415
2585
  diams: "♦"
2416
- };
2586
+ });
2587
+
2588
+ /**
2589
+ * @deprecated use `HTML_ENTITIES` instead
2590
+ * @see HTML_ENTITIES
2591
+ */
2592
+ exports.entityMap = exports.HTML_ENTITIES;
2593
+ }(entities$1));
2417
2594
 
2418
2595
  var sax$1 = {};
2419
2596
 
2597
+ var NAMESPACE$2 = conventions$2.NAMESPACE;
2598
+
2420
2599
  //[4] NameStartChar ::= ":" | [A-Z] | "_" | [a-z] | [#xC0-#xD6] | [#xD8-#xF6] | [#xF8-#x2FF] | [#x370-#x37D] | [#x37F-#x1FFF] | [#x200C-#x200D] | [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF]
2421
2600
  //[4a] NameChar ::= NameStartChar | "-" | "." | [0-9] | #xB7 | [#x0300-#x036F] | [#x203F-#x2040]
2422
2601
  //[5] Name ::= NameStartChar (NameChar)*
@@ -2534,7 +2713,7 @@ function parse(source,defaultNSMapCopy,entityMap,domBuilder,errorHandler){
2534
2713
  switch(source.charAt(tagStart+1)){
2535
2714
  case '/':
2536
2715
  var end = source.indexOf('>',tagStart+3);
2537
- var tagName = source.substring(tagStart+2,end);
2716
+ var tagName = source.substring(tagStart + 2, end).replace(/[ \t\n\r]+$/g, '');
2538
2717
  var config = parseStack.pop();
2539
2718
  if(end<0){
2540
2719
 
@@ -2607,12 +2786,10 @@ function parse(source,defaultNSMapCopy,entityMap,domBuilder,errorHandler){
2607
2786
  parseStack.push(el);
2608
2787
  }
2609
2788
  }
2610
-
2611
-
2612
-
2613
- if(el.uri === 'http://www.w3.org/1999/xhtml' && !el.closed){
2789
+
2790
+ if (NAMESPACE$2.isHTML(el.uri) && !el.closed) {
2614
2791
  end = parseHtmlSpecialContent(source,end,el.tagName,entityReplacer,domBuilder);
2615
- }else {
2792
+ } else {
2616
2793
  end++;
2617
2794
  }
2618
2795
  }
@@ -2748,7 +2925,7 @@ function parseElementStartPart(source,start,el,currentNSMap,entityReplacer,error
2748
2925
  errorHandler.warning('attribute "'+value+'" missed quot(")!');
2749
2926
  addAttribute(attrName, value.replace(/&#?\w+;/g,entityReplacer), start);
2750
2927
  }else {
2751
- if(currentNSMap[''] !== 'http://www.w3.org/1999/xhtml' || !value.match(/^(?:disabled|checked|selected)$/i)){
2928
+ if(!NAMESPACE$2.isHTML(currentNSMap['']) || !value.match(/^(?:disabled|checked|selected)$/i)){
2752
2929
  errorHandler.warning('attribute "'+value+'" missed value!! "'+value+'" instead!!');
2753
2930
  }
2754
2931
  addAttribute(value, value, start);
@@ -2796,7 +2973,7 @@ function parseElementStartPart(source,start,el,currentNSMap,entityReplacer,error
2796
2973
  //case S_ATTR_NOQUOT_VALUE:void();break;
2797
2974
  case S_ATTR_SPACE:
2798
2975
  el.tagName;
2799
- if(currentNSMap[''] !== 'http://www.w3.org/1999/xhtml' || !attrName.match(/^(?:disabled|checked|selected)$/i)){
2976
+ if (!NAMESPACE$2.isHTML(currentNSMap['']) || !attrName.match(/^(?:disabled|checked|selected)$/i)) {
2800
2977
  errorHandler.warning('attribute "'+attrName+'" missed value!! "'+attrName+'" instead2!!');
2801
2978
  }
2802
2979
  addAttribute(attrName, attrName, start);
@@ -2855,7 +3032,7 @@ function appendElement$1(el,domBuilder,currentNSMap){
2855
3032
  //console.log(currentNSMap,1)
2856
3033
  }
2857
3034
  currentNSMap[nsPrefix] = localNSMap[nsPrefix] = value;
2858
- a.uri = 'http://www.w3.org/2000/xmlns/';
3035
+ a.uri = NAMESPACE$2.XMLNS;
2859
3036
  domBuilder.startPrefixMapping(nsPrefix, value);
2860
3037
  }
2861
3038
  }
@@ -2865,7 +3042,7 @@ function appendElement$1(el,domBuilder,currentNSMap){
2865
3042
  var prefix = a.prefix;
2866
3043
  if(prefix){//no prefix attribute has no namespace
2867
3044
  if(prefix === 'xml'){
2868
- a.uri = 'http://www.w3.org/XML/1998/namespace';
3045
+ a.uri = NAMESPACE$2.XML;
2869
3046
  }if(prefix !== 'xmlns'){
2870
3047
  a.uri = currentNSMap[prefix || ''];
2871
3048
 
@@ -3062,11 +3239,74 @@ sax$1.ParseError = ParseError$1;
3062
3239
 
3063
3240
  var dom = {};
3064
3241
 
3242
+ var conventions$1 = conventions$2;
3243
+
3244
+ var NAMESPACE$1 = conventions$1.NAMESPACE;
3245
+
3246
+ /**
3247
+ * A prerequisite for `[].filter`, to drop elements that are empty
3248
+ * @param {string} input
3249
+ * @returns {boolean}
3250
+ */
3251
+ function notEmptyString (input) {
3252
+ return input !== ''
3253
+ }
3254
+ /**
3255
+ * @see https://infra.spec.whatwg.org/#split-on-ascii-whitespace
3256
+ * @see https://infra.spec.whatwg.org/#ascii-whitespace
3257
+ *
3258
+ * @param {string} input
3259
+ * @returns {string[]} (can be empty)
3260
+ */
3261
+ function splitOnASCIIWhitespace(input) {
3262
+ // U+0009 TAB, U+000A LF, U+000C FF, U+000D CR, U+0020 SPACE
3263
+ return input ? input.split(/[\t\n\f\r ]+/).filter(notEmptyString) : []
3264
+ }
3265
+
3266
+ /**
3267
+ * Adds element as a key to current if it is not already present.
3268
+ *
3269
+ * @param {Record<string, boolean | undefined>} current
3270
+ * @param {string} element
3271
+ * @returns {Record<string, boolean | undefined>}
3272
+ */
3273
+ function orderedSetReducer (current, element) {
3274
+ if (!current.hasOwnProperty(element)) {
3275
+ current[element] = true;
3276
+ }
3277
+ return current;
3278
+ }
3279
+
3280
+ /**
3281
+ * @see https://infra.spec.whatwg.org/#ordered-set
3282
+ * @param {string} input
3283
+ * @returns {string[]}
3284
+ */
3285
+ function toOrderedSet(input) {
3286
+ if (!input) return [];
3287
+ var list = splitOnASCIIWhitespace(input);
3288
+ return Object.keys(list.reduce(orderedSetReducer, {}))
3289
+ }
3290
+
3291
+ /**
3292
+ * Uses `list.indexOf` to implement something like `Array.prototype.includes`,
3293
+ * which we can not rely on being available.
3294
+ *
3295
+ * @param {any[]} list
3296
+ * @returns {function(any): boolean}
3297
+ */
3298
+ function arrayIncludes (list) {
3299
+ return function(element) {
3300
+ return list && list.indexOf(element) !== -1;
3301
+ }
3302
+ }
3303
+
3065
3304
  function copy(src,dest){
3066
3305
  for(var p in src){
3067
3306
  dest[p] = src[p];
3068
3307
  }
3069
3308
  }
3309
+
3070
3310
  /**
3071
3311
  ^\w+\.prototype\.([_\w]+)\s*=\s*((?:.*\{\s*?[\r\n][\s\S]*?^})|\S.*?(?=[;\r\n]));?
3072
3312
  ^\w+\.prototype\.([_\w]+)\s*=\s*(\S.*?(?=[;\r\n]));?
@@ -3086,7 +3326,7 @@ function _extends(Class,Super){
3086
3326
  pt.constructor = Class;
3087
3327
  }
3088
3328
  }
3089
- var htmlns = 'http://www.w3.org/1999/xhtml' ;
3329
+
3090
3330
  // Node Types
3091
3331
  var NodeType = {};
3092
3332
  var ELEMENT_NODE = NodeType.ELEMENT_NODE = 1;
@@ -3142,6 +3382,7 @@ function DOMException(code, message) {
3142
3382
  return error;
3143
3383
  }DOMException.prototype = Error.prototype;
3144
3384
  copy(ExceptionCode,DOMException);
3385
+
3145
3386
  /**
3146
3387
  * @see http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-536297177
3147
3388
  * The NodeList interface provides the abstraction of an ordered collection of nodes, without defining or constraining how this collection is implemented. NodeList objects in the DOM are live.
@@ -3172,6 +3413,7 @@ function NodeList() {
3172
3413
  return buf.join('');
3173
3414
  }
3174
3415
  };
3416
+
3175
3417
  function LiveNodeList(node,refresh){
3176
3418
  this._node = node;
3177
3419
  this._refresh = refresh;
@@ -3193,9 +3435,15 @@ LiveNodeList.prototype.item = function(i){
3193
3435
  };
3194
3436
 
3195
3437
  _extends(LiveNodeList,NodeList);
3438
+
3196
3439
  /**
3197
- *
3198
- * Objects implementing the NamedNodeMap interface are used to represent collections of nodes that can be accessed by name. Note that NamedNodeMap does not inherit from NodeList; NamedNodeMaps are not maintained in any particular order. Objects contained in an object implementing NamedNodeMap may also be accessed by an ordinal index, but this is simply to allow convenient enumeration of the contents of a NamedNodeMap, and does not imply that the DOM specifies an order to these Nodes.
3440
+ * Objects implementing the NamedNodeMap interface are used
3441
+ * to represent collections of nodes that can be accessed by name.
3442
+ * Note that NamedNodeMap does not inherit from NodeList;
3443
+ * NamedNodeMaps are not maintained in any particular order.
3444
+ * Objects contained in an object implementing NamedNodeMap may also be accessed by an ordinal index,
3445
+ * but this is simply to allow convenient enumeration of the contents of a NamedNodeMap,
3446
+ * and does not imply that the DOM specifies an order to these Nodes.
3199
3447
  * NamedNodeMap objects in the DOM are live.
3200
3448
  * used for attributes or DocumentType entities
3201
3449
  */
@@ -3306,54 +3554,108 @@ NamedNodeMap.prototype = {
3306
3554
  return null;
3307
3555
  }
3308
3556
  };
3557
+
3309
3558
  /**
3310
- * @see http://www.w3.org/TR/REC-DOM-Level-1/level-one-core.html#ID-102161490
3559
+ * The DOMImplementation interface represents an object providing methods
3560
+ * which are not dependent on any particular document.
3561
+ * Such an object is returned by the `Document.implementation` property.
3562
+ *
3563
+ * __The individual methods describe the differences compared to the specs.__
3564
+ *
3565
+ * @constructor
3566
+ *
3567
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/DOMImplementation MDN
3568
+ * @see https://www.w3.org/TR/REC-DOM-Level-1/level-one-core.html#ID-102161490 DOM Level 1 Core (Initial)
3569
+ * @see https://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-102161490 DOM Level 2 Core
3570
+ * @see https://www.w3.org/TR/DOM-Level-3-Core/core.html#ID-102161490 DOM Level 3 Core
3571
+ * @see https://dom.spec.whatwg.org/#domimplementation DOM Living Standard
3311
3572
  */
3312
- function DOMImplementation$1(/* Object */ features) {
3313
- this._features = {};
3314
- if (features) {
3315
- for (var feature in features) {
3316
- this._features = features[feature];
3317
- }
3318
- }
3573
+ function DOMImplementation$1() {
3319
3574
  }
3575
+
3320
3576
  DOMImplementation$1.prototype = {
3321
- hasFeature: function(/* string */ feature, /* string */ version) {
3322
- var versions = this._features[feature.toLowerCase()];
3323
- if (versions && (!version || version in versions)) {
3577
+ /**
3578
+ * The DOMImplementation.hasFeature() method returns a Boolean flag indicating if a given feature is supported.
3579
+ * The different implementations fairly diverged in what kind of features were reported.
3580
+ * The latest version of the spec settled to force this method to always return true, where the functionality was accurate and in use.
3581
+ *
3582
+ * @deprecated It is deprecated and modern browsers return true in all cases.
3583
+ *
3584
+ * @param {string} feature
3585
+ * @param {string} [version]
3586
+ * @returns {boolean} always true
3587
+ *
3588
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/DOMImplementation/hasFeature MDN
3589
+ * @see https://www.w3.org/TR/REC-DOM-Level-1/level-one-core.html#ID-5CED94D7 DOM Level 1 Core
3590
+ * @see https://dom.spec.whatwg.org/#dom-domimplementation-hasfeature DOM Living Standard
3591
+ */
3592
+ hasFeature: function(feature, version) {
3324
3593
  return true;
3325
- } else {
3326
- return false;
3327
- }
3328
3594
  },
3329
- // Introduced in DOM Level 2:
3330
- createDocument:function(namespaceURI, qualifiedName, doctype){// raises:INVALID_CHARACTER_ERR,NAMESPACE_ERR,WRONG_DOCUMENT_ERR
3595
+ /**
3596
+ * Creates an XML Document object of the specified type with its document element.
3597
+ *
3598
+ * __It behaves slightly different from the description in the living standard__:
3599
+ * - There is no interface/class `XMLDocument`, it returns a `Document` instance.
3600
+ * - `contentType`, `encoding`, `mode`, `origin`, `url` fields are currently not declared.
3601
+ * - this implementation is not validating names or qualified names
3602
+ * (when parsing XML strings, the SAX parser takes care of that)
3603
+ *
3604
+ * @param {string|null} namespaceURI
3605
+ * @param {string} qualifiedName
3606
+ * @param {DocumentType=null} doctype
3607
+ * @returns {Document}
3608
+ *
3609
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/DOMImplementation/createDocument MDN
3610
+ * @see https://www.w3.org/TR/DOM-Level-2-Core/core.html#Level-2-Core-DOM-createDocument DOM Level 2 Core (initial)
3611
+ * @see https://dom.spec.whatwg.org/#dom-domimplementation-createdocument DOM Level 2 Core
3612
+ *
3613
+ * @see https://dom.spec.whatwg.org/#validate-and-extract DOM: Validate and extract
3614
+ * @see https://www.w3.org/TR/xml/#NT-NameStartChar XML Spec: Names
3615
+ * @see https://www.w3.org/TR/xml-names/#ns-qualnames XML Namespaces: Qualified names
3616
+ */
3617
+ createDocument: function(namespaceURI, qualifiedName, doctype){
3331
3618
  var doc = new Document();
3332
3619
  doc.implementation = this;
3333
3620
  doc.childNodes = new NodeList();
3334
- doc.doctype = doctype;
3335
- if(doctype){
3621
+ doc.doctype = doctype || null;
3622
+ if (doctype){
3336
3623
  doc.appendChild(doctype);
3337
3624
  }
3338
- if(qualifiedName){
3339
- var root = doc.createElementNS(namespaceURI,qualifiedName);
3625
+ if (qualifiedName){
3626
+ var root = doc.createElementNS(namespaceURI, qualifiedName);
3340
3627
  doc.appendChild(root);
3341
3628
  }
3342
3629
  return doc;
3343
3630
  },
3344
- // Introduced in DOM Level 2:
3345
- createDocumentType:function(qualifiedName, publicId, systemId){// raises:INVALID_CHARACTER_ERR,NAMESPACE_ERR
3631
+ /**
3632
+ * Returns a doctype, with the given `qualifiedName`, `publicId`, and `systemId`.
3633
+ *
3634
+ * __This behavior is slightly different from the in the specs__:
3635
+ * - this implementation is not validating names or qualified names
3636
+ * (when parsing XML strings, the SAX parser takes care of that)
3637
+ *
3638
+ * @param {string} qualifiedName
3639
+ * @param {string} [publicId]
3640
+ * @param {string} [systemId]
3641
+ * @returns {DocumentType} which can either be used with `DOMImplementation.createDocument` upon document creation
3642
+ * or can be put into the document via methods like `Node.insertBefore()` or `Node.replaceChild()`
3643
+ *
3644
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/DOMImplementation/createDocumentType MDN
3645
+ * @see https://www.w3.org/TR/DOM-Level-2-Core/core.html#Level-2-Core-DOM-createDocType DOM Level 2 Core
3646
+ * @see https://dom.spec.whatwg.org/#dom-domimplementation-createdocumenttype DOM Living Standard
3647
+ *
3648
+ * @see https://dom.spec.whatwg.org/#validate-and-extract DOM: Validate and extract
3649
+ * @see https://www.w3.org/TR/xml/#NT-NameStartChar XML Spec: Names
3650
+ * @see https://www.w3.org/TR/xml-names/#ns-qualnames XML Namespaces: Qualified names
3651
+ */
3652
+ createDocumentType: function(qualifiedName, publicId, systemId){
3346
3653
  var node = new DocumentType();
3347
3654
  node.name = qualifiedName;
3348
3655
  node.nodeName = qualifiedName;
3349
- node.publicId = publicId;
3350
- node.systemId = systemId;
3351
- // Introduced in DOM Level 2:
3352
- //readonly attribute DOMString internalSubset;
3353
-
3354
- //TODO:..
3355
- // readonly attribute NamedNodeMap entities;
3356
- // readonly attribute NamedNodeMap notations;
3656
+ node.publicId = publicId || '';
3657
+ node.systemId = systemId || '';
3658
+
3357
3659
  return node;
3358
3660
  }
3359
3661
  };
@@ -3492,22 +3794,25 @@ function _visitNode(node,callback){
3492
3794
 
3493
3795
  function Document(){
3494
3796
  }
3797
+
3495
3798
  function _onAddAttribute(doc,el,newAttr){
3496
3799
  doc && doc._inc++;
3497
3800
  var ns = newAttr.namespaceURI ;
3498
- if(ns == 'http://www.w3.org/2000/xmlns/'){
3801
+ if(ns === NAMESPACE$1.XMLNS){
3499
3802
  //update namespace
3500
3803
  el._nsMap[newAttr.prefix?newAttr.localName:''] = newAttr.value;
3501
3804
  }
3502
3805
  }
3806
+
3503
3807
  function _onRemoveAttribute(doc,el,newAttr,remove){
3504
3808
  doc && doc._inc++;
3505
3809
  var ns = newAttr.namespaceURI ;
3506
- if(ns == 'http://www.w3.org/2000/xmlns/'){
3810
+ if(ns === NAMESPACE$1.XMLNS){
3507
3811
  //update namespace
3508
3812
  delete el._nsMap[newAttr.prefix?newAttr.localName:''];
3509
3813
  }
3510
3814
  }
3815
+
3511
3816
  function _onUpdateChild(doc,el,newChild){
3512
3817
  if(doc && doc._inc){
3513
3818
  doc._inc++;
@@ -3623,8 +3928,8 @@ Document.prototype = {
3623
3928
  doctype : null,
3624
3929
  documentElement : null,
3625
3930
  _inc : 1,
3626
-
3627
- insertBefore : function(newChild, refChild){//raises
3931
+
3932
+ insertBefore : function(newChild, refChild){//raises
3628
3933
  if(newChild.nodeType == DOCUMENT_FRAGMENT_NODE){
3629
3934
  var child = newChild.firstChild;
3630
3935
  while(child){
@@ -3637,7 +3942,7 @@ Document.prototype = {
3637
3942
  if(this.documentElement == null && newChild.nodeType == ELEMENT_NODE){
3638
3943
  this.documentElement = newChild;
3639
3944
  }
3640
-
3945
+
3641
3946
  return _insertBefore(this,newChild,refChild),(newChild.ownerDocument = this),newChild;
3642
3947
  },
3643
3948
  removeChild : function(oldChild){
@@ -3663,28 +3968,58 @@ Document.prototype = {
3663
3968
  });
3664
3969
  return rtv;
3665
3970
  },
3666
-
3667
- getElementsByClassName: function(className) {
3668
- var pattern = new RegExp("(^|\\s)" + className + "(\\s|$)");
3971
+
3972
+ /**
3973
+ * The `getElementsByClassName` method of `Document` interface returns an array-like object
3974
+ * of all child elements which have **all** of the given class name(s).
3975
+ *
3976
+ * Returns an empty list if `classeNames` is an empty string or only contains HTML white space characters.
3977
+ *
3978
+ *
3979
+ * Warning: This is a live LiveNodeList.
3980
+ * Changes in the DOM will reflect in the array as the changes occur.
3981
+ * If an element selected by this array no longer qualifies for the selector,
3982
+ * it will automatically be removed. Be aware of this for iteration purposes.
3983
+ *
3984
+ * @param {string} classNames is a string representing the class name(s) to match; multiple class names are separated by (ASCII-)whitespace
3985
+ *
3986
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementsByClassName
3987
+ * @see https://dom.spec.whatwg.org/#concept-getelementsbyclassname
3988
+ */
3989
+ getElementsByClassName: function(classNames) {
3990
+ var classNamesSet = toOrderedSet(classNames);
3669
3991
  return new LiveNodeList(this, function(base) {
3670
3992
  var ls = [];
3671
- _visitNode(base.documentElement, function(node) {
3672
- if(node !== base && node.nodeType == ELEMENT_NODE) {
3673
- if(pattern.test(node.getAttribute('class'))) {
3674
- ls.push(node);
3993
+ if (classNamesSet.length > 0) {
3994
+ _visitNode(base.documentElement, function(node) {
3995
+ if(node !== base && node.nodeType === ELEMENT_NODE) {
3996
+ var nodeClassNames = node.getAttribute('class');
3997
+ // can be null if the attribute does not exist
3998
+ if (nodeClassNames) {
3999
+ // before splitting and iterating just compare them for the most common case
4000
+ var matches = classNames === nodeClassNames;
4001
+ if (!matches) {
4002
+ var nodeClassNamesSet = toOrderedSet(nodeClassNames);
4003
+ matches = classNamesSet.every(arrayIncludes(nodeClassNamesSet));
4004
+ }
4005
+ if(matches) {
4006
+ ls.push(node);
4007
+ }
4008
+ }
3675
4009
  }
3676
- }
3677
- });
4010
+ });
4011
+ }
3678
4012
  return ls;
3679
4013
  });
3680
4014
  },
3681
-
4015
+
3682
4016
  //document factory method:
3683
4017
  createElement : function(tagName){
3684
4018
  var node = new Element();
3685
4019
  node.ownerDocument = this;
3686
4020
  node.nodeName = tagName;
3687
4021
  node.tagName = tagName;
4022
+ node.localName = tagName;
3688
4023
  node.childNodes = new NodeList();
3689
4024
  var attrs = node.attributes = new NamedNodeMap();
3690
4025
  attrs._ownerElement = node;
@@ -3991,36 +4326,49 @@ function nodeSerializeToString(isHtml,nodeFilter){
3991
4326
  //console.log('###',this.nodeType,uri,prefix,buf.join(''))
3992
4327
  return buf.join('');
3993
4328
  }
3994
- function needNamespaceDefine(node,isHTML, visibleNamespaces) {
3995
- var prefix = node.prefix||'';
4329
+
4330
+ function needNamespaceDefine(node, isHTML, visibleNamespaces) {
4331
+ var prefix = node.prefix || '';
3996
4332
  var uri = node.namespaceURI;
3997
- if (!prefix && !uri){
4333
+ // According to [Namespaces in XML 1.0](https://www.w3.org/TR/REC-xml-names/#ns-using) ,
4334
+ // and more specifically https://www.w3.org/TR/REC-xml-names/#nsc-NoPrefixUndecl :
4335
+ // > In a namespace declaration for a prefix [...], the attribute value MUST NOT be empty.
4336
+ // in a similar manner [Namespaces in XML 1.1](https://www.w3.org/TR/xml-names11/#ns-using)
4337
+ // and more specifically https://www.w3.org/TR/xml-names11/#nsc-NSDeclared :
4338
+ // > [...] Furthermore, the attribute value [...] must not be an empty string.
4339
+ // so serializing empty namespace value like xmlns:ds="" would produce an invalid XML document.
4340
+ if (!uri) {
3998
4341
  return false;
3999
4342
  }
4000
- if (prefix === "xml" && uri === "http://www.w3.org/XML/1998/namespace"
4001
- || uri == 'http://www.w3.org/2000/xmlns/'){
4343
+ if (prefix === "xml" && uri === NAMESPACE$1.XML || uri === NAMESPACE$1.XMLNS) {
4002
4344
  return false;
4003
4345
  }
4004
4346
 
4005
4347
  var i = visibleNamespaces.length;
4006
- //console.log('@@@@',node.tagName,prefix,uri,visibleNamespaces)
4007
4348
  while (i--) {
4008
4349
  var ns = visibleNamespaces[i];
4009
4350
  // get namespace prefix
4010
- //console.log(node.nodeType,node.tagName,ns.prefix,prefix)
4011
- if (ns.prefix == prefix){
4012
- return ns.namespace != uri;
4351
+ if (ns.prefix === prefix) {
4352
+ return ns.namespace !== uri;
4013
4353
  }
4014
4354
  }
4015
- //console.log(isHTML,uri,prefix=='')
4016
- //if(isHTML && prefix ==null && uri == 'http://www.w3.org/1999/xhtml'){
4017
- // return false;
4018
- //}
4019
- //node.flag = '11111'
4020
- //console.error(3,true,node.flag,node.prefix,node.namespaceURI)
4021
4355
  return true;
4022
4356
  }
4357
+ /**
4358
+ * Well-formed constraint: No < in Attribute Values
4359
+ * The replacement text of any entity referred to directly or indirectly in an attribute value must not contain a <.
4360
+ * @see https://www.w3.org/TR/xml/#CleanAttrVals
4361
+ * @see https://www.w3.org/TR/xml/#NT-AttValue
4362
+ */
4363
+ function addSerializedAttribute(buf, qualifiedName, value) {
4364
+ buf.push(' ', qualifiedName, '="', value.replace(/[<&"]/g,_xmlEncoder), '"');
4365
+ }
4366
+
4023
4367
  function serializeToString(node,buf,isHTML,nodeFilter,visibleNamespaces){
4368
+ if (!visibleNamespaces) {
4369
+ visibleNamespaces = [];
4370
+ }
4371
+
4024
4372
  if(nodeFilter){
4025
4373
  node = nodeFilter(node);
4026
4374
  if(node){
@@ -4033,20 +4381,40 @@ function serializeToString(node,buf,isHTML,nodeFilter,visibleNamespaces){
4033
4381
  }
4034
4382
  //buf.sort.apply(attrs, attributeSorter);
4035
4383
  }
4384
+
4036
4385
  switch(node.nodeType){
4037
4386
  case ELEMENT_NODE:
4038
- if (!visibleNamespaces) visibleNamespaces = [];
4039
- visibleNamespaces.length;
4040
4387
  var attrs = node.attributes;
4041
4388
  var len = attrs.length;
4042
4389
  var child = node.firstChild;
4043
4390
  var nodeName = node.tagName;
4044
4391
 
4045
- isHTML = (htmlns === node.namespaceURI) ||isHTML;
4046
- buf.push('<',nodeName);
4047
-
4048
-
4049
-
4392
+ isHTML = NAMESPACE$1.isHTML(node.namespaceURI) || isHTML;
4393
+
4394
+ var prefixedNodeName = nodeName;
4395
+ if (!isHTML && !node.prefix && node.namespaceURI) {
4396
+ var defaultNS;
4397
+ for (var ai = 0; ai < attrs.length; ai++) {
4398
+ if (attrs.item(ai).name === 'xmlns') {
4399
+ defaultNS = attrs.item(ai).value;
4400
+ break
4401
+ }
4402
+ }
4403
+ if (defaultNS !== node.namespaceURI) {
4404
+ for (var nsi = visibleNamespaces.length - 1; nsi >= 0; nsi--) {
4405
+ var namespace = visibleNamespaces[nsi];
4406
+ if (namespace.namespace === node.namespaceURI) {
4407
+ if (namespace.prefix) {
4408
+ prefixedNodeName = namespace.prefix + ':' + nodeName;
4409
+ }
4410
+ break
4411
+ }
4412
+ }
4413
+ }
4414
+ }
4415
+
4416
+ buf.push('<', prefixedNodeName);
4417
+
4050
4418
  for(var i=0;i<len;i++){
4051
4419
  // add namespaces for attributes
4052
4420
  var attr = attrs.item(i);
@@ -4056,28 +4424,24 @@ function serializeToString(node,buf,isHTML,nodeFilter,visibleNamespaces){
4056
4424
  visibleNamespaces.push({ prefix: '', namespace: attr.value });
4057
4425
  }
4058
4426
  }
4427
+
4059
4428
  for(var i=0;i<len;i++){
4060
4429
  var attr = attrs.item(i);
4061
4430
  if (needNamespaceDefine(attr,isHTML, visibleNamespaces)) {
4062
4431
  var prefix = attr.prefix||'';
4063
4432
  var uri = attr.namespaceURI;
4064
- var ns = prefix ? ' xmlns:' + prefix : " xmlns";
4065
- buf.push(ns, '="' , uri , '"');
4433
+ addSerializedAttribute(buf, prefix ? 'xmlns:' + prefix : "xmlns", uri);
4066
4434
  visibleNamespaces.push({ prefix: prefix, namespace:uri });
4067
4435
  }
4068
4436
  serializeToString(attr,buf,isHTML,nodeFilter,visibleNamespaces);
4069
4437
  }
4438
+
4070
4439
  // add namespace for current node
4071
- if (needNamespaceDefine(node,isHTML, visibleNamespaces)) {
4440
+ if (nodeName === prefixedNodeName && needNamespaceDefine(node, isHTML, visibleNamespaces)) {
4072
4441
  var prefix = node.prefix||'';
4073
4442
  var uri = node.namespaceURI;
4074
- if (uri) {
4075
- // Avoid empty namespace value like xmlns:ds=""
4076
- // Empty namespace URL will we produce an invalid XML document
4077
- var ns = prefix ? ' xmlns:' + prefix : " xmlns";
4078
- buf.push(ns, '="' , uri , '"');
4079
- visibleNamespaces.push({ prefix: prefix, namespace:uri });
4080
- }
4443
+ addSerializedAttribute(buf, prefix ? 'xmlns:' + prefix : "xmlns", uri);
4444
+ visibleNamespaces.push({ prefix: prefix, namespace:uri });
4081
4445
  }
4082
4446
 
4083
4447
  if(child || isHTML && !/^(?:meta|link|img|br|hr|input)$/i.test(nodeName)){
@@ -4088,18 +4452,18 @@ function serializeToString(node,buf,isHTML,nodeFilter,visibleNamespaces){
4088
4452
  if(child.data){
4089
4453
  buf.push(child.data);
4090
4454
  }else {
4091
- serializeToString(child,buf,isHTML,nodeFilter,visibleNamespaces);
4455
+ serializeToString(child, buf, isHTML, nodeFilter, visibleNamespaces.slice());
4092
4456
  }
4093
4457
  child = child.nextSibling;
4094
4458
  }
4095
4459
  }else
4096
4460
  {
4097
4461
  while(child){
4098
- serializeToString(child,buf,isHTML,nodeFilter,visibleNamespaces);
4462
+ serializeToString(child, buf, isHTML, nodeFilter, visibleNamespaces.slice());
4099
4463
  child = child.nextSibling;
4100
4464
  }
4101
4465
  }
4102
- buf.push('</',nodeName,'>');
4466
+ buf.push('</',prefixedNodeName,'>');
4103
4467
  }else {
4104
4468
  buf.push('/>');
4105
4469
  }
@@ -4110,18 +4474,12 @@ function serializeToString(node,buf,isHTML,nodeFilter,visibleNamespaces){
4110
4474
  case DOCUMENT_FRAGMENT_NODE:
4111
4475
  var child = node.firstChild;
4112
4476
  while(child){
4113
- serializeToString(child,buf,isHTML,nodeFilter,visibleNamespaces);
4477
+ serializeToString(child, buf, isHTML, nodeFilter, visibleNamespaces.slice());
4114
4478
  child = child.nextSibling;
4115
4479
  }
4116
4480
  return;
4117
4481
  case ATTRIBUTE_NODE:
4118
- /**
4119
- * Well-formedness constraint: No < in Attribute Values
4120
- * The replacement text of any entity referred to directly or indirectly in an attribute value must not contain a <.
4121
- * @see https://www.w3.org/TR/xml/#CleanAttrVals
4122
- * @see https://www.w3.org/TR/xml/#NT-AttValue
4123
- */
4124
- return buf.push(' ', node.name, '="', node.value.replace(/[<&"]/g,_xmlEncoder), '"');
4482
+ return addSerializedAttribute(buf, node.name, node.value);
4125
4483
  case TEXT_NODE:
4126
4484
  /**
4127
4485
  * The ampersand character (&) and the left angle bracket (<) must not appear in their literal form,
@@ -4272,10 +4630,12 @@ try{
4272
4630
  return this.$$length;
4273
4631
  }
4274
4632
  });
4633
+
4275
4634
  Object.defineProperty(Node.prototype,'textContent',{
4276
4635
  get:function(){
4277
4636
  return getTextContent(this);
4278
4637
  },
4638
+
4279
4639
  set:function(data){
4280
4640
  switch(this.nodeType){
4281
4641
  case ELEMENT_NODE:
@@ -4287,8 +4647,8 @@ try{
4287
4647
  this.appendChild(this.ownerDocument.createTextNode(data));
4288
4648
  }
4289
4649
  break;
4650
+
4290
4651
  default:
4291
- //TODO:
4292
4652
  this.data = data;
4293
4653
  this.value = data;
4294
4654
  this.nodeValue = data;
@@ -4313,6 +4673,7 @@ try{
4313
4673
  return node.nodeValue;
4314
4674
  }
4315
4675
  }
4676
+
4316
4677
  __set__ = function(object,key,value){
4317
4678
  //console.log(value)
4318
4679
  object['$$'+key] = value;
@@ -4322,11 +4683,19 @@ try{
4322
4683
  }
4323
4684
 
4324
4685
  //if(typeof require == 'function'){
4325
- dom.Node = Node;
4686
+ dom.DocumentType = DocumentType;
4326
4687
  dom.DOMException = DOMException;
4327
4688
  dom.DOMImplementation = DOMImplementation$1;
4689
+ dom.Element = Element;
4690
+ dom.Node = Node;
4691
+ dom.NodeList = NodeList;
4328
4692
  dom.XMLSerializer = XMLSerializer;
4329
4693
 
4694
+ var conventions = conventions$2;
4695
+ var entities = entities$1;
4696
+
4697
+ var NAMESPACE = conventions.NAMESPACE;
4698
+
4330
4699
  function DOMParser(options){
4331
4700
  this.options = options ||{locator:{}};
4332
4701
  }
@@ -4339,7 +4708,7 @@ DOMParser.prototype.parseFromString = function(source,mimeType){
4339
4708
  var locator = options.locator;
4340
4709
  var defaultNSMap = options.xmlns||{};
4341
4710
  var isHTML = /\/x?html?$/.test(mimeType);//mimeType.toLowerCase().indexOf('html') > -1;
4342
- var entityMap = isHTML?htmlEntity.entityMap:{'lt':'<','gt':'>','amp':'&','quot':'"','apos':"'"};
4711
+ var entityMap = isHTML ? entities.HTML_ENTITIES : entities.XML_ENTITIES;
4343
4712
  if(locator){
4344
4713
  domBuilder.setDocumentLocator(locator);
4345
4714
  }
@@ -4347,9 +4716,9 @@ DOMParser.prototype.parseFromString = function(source,mimeType){
4347
4716
  sax.errorHandler = buildErrorHandler(errorHandler,domBuilder,locator);
4348
4717
  sax.domBuilder = options.domBuilder || domBuilder;
4349
4718
  if(isHTML){
4350
- defaultNSMap['']= 'http://www.w3.org/1999/xhtml';
4719
+ defaultNSMap[''] = NAMESPACE.HTML;
4351
4720
  }
4352
- defaultNSMap.xml = defaultNSMap.xml || 'http://www.w3.org/XML/1998/namespace';
4721
+ defaultNSMap.xml = defaultNSMap.xml || NAMESPACE.XML;
4353
4722
  if(source && typeof source === 'string'){
4354
4723
  sax.parse(source,defaultNSMap,entityMap);
4355
4724
  }else {
@@ -4571,7 +4940,6 @@ function appendElement (hander,node) {
4571
4940
  }//appendChild and setAttributeNS are preformance key
4572
4941
 
4573
4942
  //if(typeof require == 'function'){
4574
- var htmlEntity = entities;
4575
4943
  var sax = sax$1;
4576
4944
  var XMLReader = sax.XMLReader;
4577
4945
  var ParseError = sax.ParseError;
@@ -5318,6 +5686,23 @@ function createFallbackStop(context) {
5318
5686
  };
5319
5687
  }
5320
5688
 
5689
+ /**
5690
+ * Pipes all emitted events from one emitter to another.
5691
+ */
5692
+ function pipeEvents(source, destination) {
5693
+ const rawEmit = source.emit;
5694
+ // @ts-ignore
5695
+ if (rawEmit._isPiped) {
5696
+ return;
5697
+ }
5698
+ source.emit = function (event, ...data) {
5699
+ destination.emit(event, ...data);
5700
+ return rawEmit.call(this, event, ...data);
5701
+ };
5702
+ // @ts-ignore
5703
+ source.emit._isPiped = true;
5704
+ }
5705
+
5321
5706
  // Declare the list of event handlers on the module's scope
5322
5707
  // so it persists between Fash refreshes of the application's code.
5323
5708
  let listeners = [];
@@ -5336,12 +5721,15 @@ function setupWorker(...requestHandlers) {
5336
5721
  if (lib$6.exports.isNodeProcess()) {
5337
5722
  throw new Error(devUtils.formatMessage('Failed to execute `setupWorker` in a non-browser environment. Consider using `setupServer` for Node.js environment instead.'));
5338
5723
  }
5724
+ const emitter = new lib$3.StrictEventEmitter();
5725
+ const publicEmitter = new lib$3.StrictEventEmitter();
5726
+ pipeEvents(emitter, publicEmitter);
5339
5727
  const context = {
5340
5728
  startOptions: undefined,
5341
5729
  worker: null,
5342
5730
  registration: null,
5343
5731
  requestHandlers: [...requestHandlers],
5344
- emitter: new lib$3.StrictEventEmitter(),
5732
+ emitter,
5345
5733
  workerChannel: {
5346
5734
  on(eventType, callback) {
5347
5735
  context.events.addListener(navigator.serviceWorker, 'message', (event) => {
@@ -5407,7 +5795,12 @@ function setupWorker(...requestHandlers) {
5407
5795
  : createStop(context);
5408
5796
  return {
5409
5797
  start: prepareStartHandler(startHandler, context),
5410
- stop: stopHandler,
5798
+ stop() {
5799
+ context.events.removeAllListeners();
5800
+ context.emitter.removeAllListeners();
5801
+ publicEmitter.removeAllListeners();
5802
+ stopHandler();
5803
+ },
5411
5804
  use(...handlers) {
5412
5805
  use(context.requestHandlers, ...handlers);
5413
5806
  },
@@ -5434,8 +5827,16 @@ function setupWorker(...requestHandlers) {
5434
5827
  console.groupEnd();
5435
5828
  });
5436
5829
  },
5437
- on(eventType, listener) {
5438
- context.emitter.addListener(eventType, listener);
5830
+ events: {
5831
+ on(...args) {
5832
+ return publicEmitter.on(...args);
5833
+ },
5834
+ removeListener(...args) {
5835
+ return publicEmitter.removeListener(...args);
5836
+ },
5837
+ removeAllListeners(...args) {
5838
+ return publicEmitter.removeAllListeners(...args);
5839
+ },
5439
5840
  },
5440
5841
  };
5441
5842
  }