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/umd/index.js CHANGED
@@ -22514,7 +22514,10 @@ Invalid value has been removed from localStorage to prevent subsequent failed pa
22514
22514
  // Resolve a relative request URL against a given custom "baseUrl"
22515
22515
  // or the current location (in the case of browser/browser-like environments).
22516
22516
  const origin = baseUrl || (typeof location !== 'undefined' && location.origin);
22517
- return origin ? new URL(path, origin).href : path;
22517
+ return origin
22518
+ ? // Encode and decode the path to preserve escaped characters.
22519
+ decodeURI(new URL(encodeURI(path), origin).href)
22520
+ : path;
22518
22521
  }
22519
22522
 
22520
22523
  /**
@@ -22998,8 +23001,10 @@ Read more: https://mswjs.io/docs/getting-started/mocks\
22998
23001
  const message = messageTemplate.join('\n\n');
22999
23002
  switch (strategy) {
23000
23003
  case 'error': {
23004
+ // Print a developer-friendly error.
23001
23005
  devUtils.error('Error: %s', message);
23002
- break;
23006
+ // Throw an exception to halt request processing and not perform the original request.
23007
+ throw new Error('Cannot bypass a request when using the "error" strategy for the "onUnhandledRequest" option.');
23003
23008
  }
23004
23009
  case 'warn': {
23005
23010
  devUtils.warn('Warning: %s', message);
@@ -23279,16 +23284,14 @@ If this message still persists after updating, please report an issue: https://g
23279
23284
  }
23280
23285
 
23281
23286
  const createStop = (context) => {
23282
- /**
23283
- * Signal the Service Worker to disable mocking for this client.
23284
- * Use this an an explicit way to stop the mocking, while preserving
23285
- * the worker-client relation. Does not affect the worker's lifecycle.
23286
- */
23287
23287
  return function stop() {
23288
23288
  var _a;
23289
+ /**
23290
+ * Signal the Service Worker to disable mocking for this client.
23291
+ * Use this an an explicit way to stop the mocking, while preserving
23292
+ * the worker-client relation. Does not affect the worker's lifecycle.
23293
+ */
23289
23294
  context.workerChannel.send('MOCK_DEACTIVATE');
23290
- context.events.removeAllListeners();
23291
- context.emitter.removeAllListeners();
23292
23295
  window.clearInterval(context.keepAliveInterval);
23293
23296
  printStopMessage({ quiet: (_a = context.startOptions) === null || _a === void 0 ? void 0 : _a.quiet });
23294
23297
  };
@@ -24450,9 +24453,179 @@ If this message still persists after updating, please report an issue: https://g
24450
24453
 
24451
24454
  var domParser = {};
24452
24455
 
24453
- var entities = {};
24456
+ var conventions$2 = {};
24457
+
24458
+ /**
24459
+ * "Shallow freezes" an object to render it immutable.
24460
+ * Uses `Object.freeze` if available,
24461
+ * otherwise the immutability is only in the type.
24462
+ *
24463
+ * Is used to create "enum like" objects.
24464
+ *
24465
+ * @template T
24466
+ * @param {T} object the object to freeze
24467
+ * @param {Pick<ObjectConstructor, 'freeze'> = Object} oc `Object` by default,
24468
+ * allows to inject custom object constructor for tests
24469
+ * @returns {Readonly<T>}
24470
+ *
24471
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze
24472
+ */
24473
+ function freeze(object, oc) {
24474
+ if (oc === undefined) {
24475
+ oc = Object;
24476
+ }
24477
+ return oc && typeof oc.freeze === 'function' ? oc.freeze(object) : object
24478
+ }
24479
+
24480
+ /**
24481
+ * All mime types that are allowed as input to `DOMParser.parseFromString`
24482
+ *
24483
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/DOMParser/parseFromString#Argument02 MDN
24484
+ * @see https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#domparsersupportedtype WHATWG HTML Spec
24485
+ * @see DOMParser.prototype.parseFromString
24486
+ */
24487
+ var MIME_TYPE = freeze({
24488
+ /**
24489
+ * `text/html`, the only mime type that triggers treating an XML document as HTML.
24490
+ *
24491
+ * @see DOMParser.SupportedType.isHTML
24492
+ * @see https://www.iana.org/assignments/media-types/text/html IANA MimeType registration
24493
+ * @see https://en.wikipedia.org/wiki/HTML Wikipedia
24494
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/DOMParser/parseFromString MDN
24495
+ * @see https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-domparser-parsefromstring WHATWG HTML Spec
24496
+ */
24497
+ HTML: 'text/html',
24498
+
24499
+ /**
24500
+ * Helper method to check a mime type if it indicates an HTML document
24501
+ *
24502
+ * @param {string} [value]
24503
+ * @returns {boolean}
24504
+ *
24505
+ * @see https://www.iana.org/assignments/media-types/text/html IANA MimeType registration
24506
+ * @see https://en.wikipedia.org/wiki/HTML Wikipedia
24507
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/DOMParser/parseFromString MDN
24508
+ * @see https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-domparser-parsefromstring */
24509
+ isHTML: function (value) {
24510
+ return value === MIME_TYPE.HTML
24511
+ },
24512
+
24513
+ /**
24514
+ * `application/xml`, the standard mime type for XML documents.
24515
+ *
24516
+ * @see https://www.iana.org/assignments/media-types/application/xml IANA MimeType registration
24517
+ * @see https://tools.ietf.org/html/rfc7303#section-9.1 RFC 7303
24518
+ * @see https://en.wikipedia.org/wiki/XML_and_MIME Wikipedia
24519
+ */
24520
+ XML_APPLICATION: 'application/xml',
24454
24521
 
24455
- entities.entityMap = {
24522
+ /**
24523
+ * `text/html`, an alias for `application/xml`.
24524
+ *
24525
+ * @see https://tools.ietf.org/html/rfc7303#section-9.2 RFC 7303
24526
+ * @see https://www.iana.org/assignments/media-types/text/xml IANA MimeType registration
24527
+ * @see https://en.wikipedia.org/wiki/XML_and_MIME Wikipedia
24528
+ */
24529
+ XML_TEXT: 'text/xml',
24530
+
24531
+ /**
24532
+ * `application/xhtml+xml`, indicates an XML document that has the default HTML namespace,
24533
+ * but is parsed as an XML document.
24534
+ *
24535
+ * @see https://www.iana.org/assignments/media-types/application/xhtml+xml IANA MimeType registration
24536
+ * @see https://dom.spec.whatwg.org/#dom-domimplementation-createdocument WHATWG DOM Spec
24537
+ * @see https://en.wikipedia.org/wiki/XHTML Wikipedia
24538
+ */
24539
+ XML_XHTML_APPLICATION: 'application/xhtml+xml',
24540
+
24541
+ /**
24542
+ * `image/svg+xml`,
24543
+ *
24544
+ * @see https://www.iana.org/assignments/media-types/image/svg+xml IANA MimeType registration
24545
+ * @see https://www.w3.org/TR/SVG11/ W3C SVG 1.1
24546
+ * @see https://en.wikipedia.org/wiki/Scalable_Vector_Graphics Wikipedia
24547
+ */
24548
+ XML_SVG_IMAGE: 'image/svg+xml',
24549
+ });
24550
+
24551
+ /**
24552
+ * Namespaces that are used in this code base.
24553
+ *
24554
+ * @see http://www.w3.org/TR/REC-xml-names
24555
+ */
24556
+ var NAMESPACE$3 = freeze({
24557
+ /**
24558
+ * The XHTML namespace.
24559
+ *
24560
+ * @see http://www.w3.org/1999/xhtml
24561
+ */
24562
+ HTML: 'http://www.w3.org/1999/xhtml',
24563
+
24564
+ /**
24565
+ * Checks if `uri` equals `NAMESPACE.HTML`.
24566
+ *
24567
+ * @param {string} [uri]
24568
+ *
24569
+ * @see NAMESPACE.HTML
24570
+ */
24571
+ isHTML: function (uri) {
24572
+ return uri === NAMESPACE$3.HTML
24573
+ },
24574
+
24575
+ /**
24576
+ * The SVG namespace.
24577
+ *
24578
+ * @see http://www.w3.org/2000/svg
24579
+ */
24580
+ SVG: 'http://www.w3.org/2000/svg',
24581
+
24582
+ /**
24583
+ * The `xml:` namespace.
24584
+ *
24585
+ * @see http://www.w3.org/XML/1998/namespace
24586
+ */
24587
+ XML: 'http://www.w3.org/XML/1998/namespace',
24588
+
24589
+ /**
24590
+ * The `xmlns:` namespace
24591
+ *
24592
+ * @see https://www.w3.org/2000/xmlns/
24593
+ */
24594
+ XMLNS: 'http://www.w3.org/2000/xmlns/',
24595
+ });
24596
+
24597
+ conventions$2.freeze = freeze;
24598
+ conventions$2.MIME_TYPE = MIME_TYPE;
24599
+ conventions$2.NAMESPACE = NAMESPACE$3;
24600
+
24601
+ var entities$1 = {};
24602
+
24603
+ (function (exports) {
24604
+ var freeze = conventions$2.freeze;
24605
+
24606
+ /**
24607
+ * The entities that are predefined in every XML document.
24608
+ *
24609
+ * @see https://www.w3.org/TR/2006/REC-xml11-20060816/#sec-predefined-ent W3C XML 1.1
24610
+ * @see https://www.w3.org/TR/2008/REC-xml-20081126/#sec-predefined-ent W3C XML 1.0
24611
+ * @see https://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references#Predefined_entities_in_XML Wikipedia
24612
+ */
24613
+ exports.XML_ENTITIES = freeze({amp:'&', apos:"'", gt:'>', lt:'<', quot:'"'});
24614
+
24615
+ /**
24616
+ * A map of currently 241 entities that are detected in an HTML document.
24617
+ * They contain all entries from `XML_ENTITIES`.
24618
+ *
24619
+ * @see XML_ENTITIES
24620
+ * @see DOMParser.parseFromString
24621
+ * @see DOMImplementation.prototype.createHTMLDocument
24622
+ * @see https://html.spec.whatwg.org/#named-character-references WHATWG HTML(5) Spec
24623
+ * @see https://www.w3.org/TR/xml-entity-names/ W3C XML Entity Names
24624
+ * @see https://www.w3.org/TR/html4/sgml/entities.html W3C HTML4/SGML
24625
+ * @see https://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references#Character_entity_references_in_HTML Wikipedia (HTML)
24626
+ * @see https://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references#Entities_representing_special_characters_in_XHTML Wikpedia (XHTML)
24627
+ */
24628
+ exports.HTML_ENTITIES = freeze({
24456
24629
  lt: '<',
24457
24630
  gt: '>',
24458
24631
  amp: '&',
@@ -24694,10 +24867,19 @@ If this message still persists after updating, please report an issue: https://g
24694
24867
  clubs: "♣",
24695
24868
  hearts: "♥",
24696
24869
  diams: "♦"
24697
- };
24870
+ });
24871
+
24872
+ /**
24873
+ * @deprecated use `HTML_ENTITIES` instead
24874
+ * @see HTML_ENTITIES
24875
+ */
24876
+ exports.entityMap = exports.HTML_ENTITIES;
24877
+ }(entities$1));
24698
24878
 
24699
24879
  var sax$1 = {};
24700
24880
 
24881
+ var NAMESPACE$2 = conventions$2.NAMESPACE;
24882
+
24701
24883
  //[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]
24702
24884
  //[4a] NameChar ::= NameStartChar | "-" | "." | [0-9] | #xB7 | [#x0300-#x036F] | [#x203F-#x2040]
24703
24885
  //[5] Name ::= NameStartChar (NameChar)*
@@ -24815,7 +24997,7 @@ If this message still persists after updating, please report an issue: https://g
24815
24997
  switch(source.charAt(tagStart+1)){
24816
24998
  case '/':
24817
24999
  var end = source.indexOf('>',tagStart+3);
24818
- var tagName = source.substring(tagStart+2,end);
25000
+ var tagName = source.substring(tagStart + 2, end).replace(/[ \t\n\r]+$/g, '');
24819
25001
  var config = parseStack.pop();
24820
25002
  if(end<0){
24821
25003
 
@@ -24888,12 +25070,10 @@ If this message still persists after updating, please report an issue: https://g
24888
25070
  parseStack.push(el);
24889
25071
  }
24890
25072
  }
24891
-
24892
-
24893
-
24894
- if(el.uri === 'http://www.w3.org/1999/xhtml' && !el.closed){
25073
+
25074
+ if (NAMESPACE$2.isHTML(el.uri) && !el.closed) {
24895
25075
  end = parseHtmlSpecialContent(source,end,el.tagName,entityReplacer,domBuilder);
24896
- }else {
25076
+ } else {
24897
25077
  end++;
24898
25078
  }
24899
25079
  }
@@ -25029,7 +25209,7 @@ If this message still persists after updating, please report an issue: https://g
25029
25209
  errorHandler.warning('attribute "'+value+'" missed quot(")!');
25030
25210
  addAttribute(attrName, value.replace(/&#?\w+;/g,entityReplacer), start);
25031
25211
  }else {
25032
- if(currentNSMap[''] !== 'http://www.w3.org/1999/xhtml' || !value.match(/^(?:disabled|checked|selected)$/i)){
25212
+ if(!NAMESPACE$2.isHTML(currentNSMap['']) || !value.match(/^(?:disabled|checked|selected)$/i)){
25033
25213
  errorHandler.warning('attribute "'+value+'" missed value!! "'+value+'" instead!!');
25034
25214
  }
25035
25215
  addAttribute(value, value, start);
@@ -25077,7 +25257,7 @@ If this message still persists after updating, please report an issue: https://g
25077
25257
  //case S_ATTR_NOQUOT_VALUE:void();break;
25078
25258
  case S_ATTR_SPACE:
25079
25259
  el.tagName;
25080
- if(currentNSMap[''] !== 'http://www.w3.org/1999/xhtml' || !attrName.match(/^(?:disabled|checked|selected)$/i)){
25260
+ if (!NAMESPACE$2.isHTML(currentNSMap['']) || !attrName.match(/^(?:disabled|checked|selected)$/i)) {
25081
25261
  errorHandler.warning('attribute "'+attrName+'" missed value!! "'+attrName+'" instead2!!');
25082
25262
  }
25083
25263
  addAttribute(attrName, attrName, start);
@@ -25136,7 +25316,7 @@ If this message still persists after updating, please report an issue: https://g
25136
25316
  //console.log(currentNSMap,1)
25137
25317
  }
25138
25318
  currentNSMap[nsPrefix] = localNSMap[nsPrefix] = value;
25139
- a.uri = 'http://www.w3.org/2000/xmlns/';
25319
+ a.uri = NAMESPACE$2.XMLNS;
25140
25320
  domBuilder.startPrefixMapping(nsPrefix, value);
25141
25321
  }
25142
25322
  }
@@ -25146,7 +25326,7 @@ If this message still persists after updating, please report an issue: https://g
25146
25326
  var prefix = a.prefix;
25147
25327
  if(prefix){//no prefix attribute has no namespace
25148
25328
  if(prefix === 'xml'){
25149
- a.uri = 'http://www.w3.org/XML/1998/namespace';
25329
+ a.uri = NAMESPACE$2.XML;
25150
25330
  }if(prefix !== 'xmlns'){
25151
25331
  a.uri = currentNSMap[prefix || ''];
25152
25332
 
@@ -25343,11 +25523,74 @@ If this message still persists after updating, please report an issue: https://g
25343
25523
 
25344
25524
  var dom = {};
25345
25525
 
25526
+ var conventions$1 = conventions$2;
25527
+
25528
+ var NAMESPACE$1 = conventions$1.NAMESPACE;
25529
+
25530
+ /**
25531
+ * A prerequisite for `[].filter`, to drop elements that are empty
25532
+ * @param {string} input
25533
+ * @returns {boolean}
25534
+ */
25535
+ function notEmptyString (input) {
25536
+ return input !== ''
25537
+ }
25538
+ /**
25539
+ * @see https://infra.spec.whatwg.org/#split-on-ascii-whitespace
25540
+ * @see https://infra.spec.whatwg.org/#ascii-whitespace
25541
+ *
25542
+ * @param {string} input
25543
+ * @returns {string[]} (can be empty)
25544
+ */
25545
+ function splitOnASCIIWhitespace(input) {
25546
+ // U+0009 TAB, U+000A LF, U+000C FF, U+000D CR, U+0020 SPACE
25547
+ return input ? input.split(/[\t\n\f\r ]+/).filter(notEmptyString) : []
25548
+ }
25549
+
25550
+ /**
25551
+ * Adds element as a key to current if it is not already present.
25552
+ *
25553
+ * @param {Record<string, boolean | undefined>} current
25554
+ * @param {string} element
25555
+ * @returns {Record<string, boolean | undefined>}
25556
+ */
25557
+ function orderedSetReducer (current, element) {
25558
+ if (!current.hasOwnProperty(element)) {
25559
+ current[element] = true;
25560
+ }
25561
+ return current;
25562
+ }
25563
+
25564
+ /**
25565
+ * @see https://infra.spec.whatwg.org/#ordered-set
25566
+ * @param {string} input
25567
+ * @returns {string[]}
25568
+ */
25569
+ function toOrderedSet(input) {
25570
+ if (!input) return [];
25571
+ var list = splitOnASCIIWhitespace(input);
25572
+ return Object.keys(list.reduce(orderedSetReducer, {}))
25573
+ }
25574
+
25575
+ /**
25576
+ * Uses `list.indexOf` to implement something like `Array.prototype.includes`,
25577
+ * which we can not rely on being available.
25578
+ *
25579
+ * @param {any[]} list
25580
+ * @returns {function(any): boolean}
25581
+ */
25582
+ function arrayIncludes (list) {
25583
+ return function(element) {
25584
+ return list && list.indexOf(element) !== -1;
25585
+ }
25586
+ }
25587
+
25346
25588
  function copy(src,dest){
25347
25589
  for(var p in src){
25348
25590
  dest[p] = src[p];
25349
25591
  }
25350
25592
  }
25593
+
25351
25594
  /**
25352
25595
  ^\w+\.prototype\.([_\w]+)\s*=\s*((?:.*\{\s*?[\r\n][\s\S]*?^})|\S.*?(?=[;\r\n]));?
25353
25596
  ^\w+\.prototype\.([_\w]+)\s*=\s*(\S.*?(?=[;\r\n]));?
@@ -25367,7 +25610,7 @@ If this message still persists after updating, please report an issue: https://g
25367
25610
  pt.constructor = Class;
25368
25611
  }
25369
25612
  }
25370
- var htmlns = 'http://www.w3.org/1999/xhtml' ;
25613
+
25371
25614
  // Node Types
25372
25615
  var NodeType = {};
25373
25616
  var ELEMENT_NODE = NodeType.ELEMENT_NODE = 1;
@@ -25423,6 +25666,7 @@ If this message still persists after updating, please report an issue: https://g
25423
25666
  return error;
25424
25667
  }DOMException.prototype = Error.prototype;
25425
25668
  copy(ExceptionCode,DOMException);
25669
+
25426
25670
  /**
25427
25671
  * @see http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-536297177
25428
25672
  * 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.
@@ -25453,6 +25697,7 @@ If this message still persists after updating, please report an issue: https://g
25453
25697
  return buf.join('');
25454
25698
  }
25455
25699
  };
25700
+
25456
25701
  function LiveNodeList(node,refresh){
25457
25702
  this._node = node;
25458
25703
  this._refresh = refresh;
@@ -25474,9 +25719,15 @@ If this message still persists after updating, please report an issue: https://g
25474
25719
  };
25475
25720
 
25476
25721
  _extends(LiveNodeList,NodeList);
25722
+
25477
25723
  /**
25478
- *
25479
- * 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.
25724
+ * Objects implementing the NamedNodeMap interface are used
25725
+ * to represent collections of nodes that can be accessed by name.
25726
+ * Note that NamedNodeMap does not inherit from NodeList;
25727
+ * NamedNodeMaps are not maintained in any particular order.
25728
+ * Objects contained in an object implementing NamedNodeMap may also be accessed by an ordinal index,
25729
+ * but this is simply to allow convenient enumeration of the contents of a NamedNodeMap,
25730
+ * and does not imply that the DOM specifies an order to these Nodes.
25480
25731
  * NamedNodeMap objects in the DOM are live.
25481
25732
  * used for attributes or DocumentType entities
25482
25733
  */
@@ -25587,54 +25838,108 @@ If this message still persists after updating, please report an issue: https://g
25587
25838
  return null;
25588
25839
  }
25589
25840
  };
25841
+
25590
25842
  /**
25591
- * @see http://www.w3.org/TR/REC-DOM-Level-1/level-one-core.html#ID-102161490
25843
+ * The DOMImplementation interface represents an object providing methods
25844
+ * which are not dependent on any particular document.
25845
+ * Such an object is returned by the `Document.implementation` property.
25846
+ *
25847
+ * __The individual methods describe the differences compared to the specs.__
25848
+ *
25849
+ * @constructor
25850
+ *
25851
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/DOMImplementation MDN
25852
+ * @see https://www.w3.org/TR/REC-DOM-Level-1/level-one-core.html#ID-102161490 DOM Level 1 Core (Initial)
25853
+ * @see https://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-102161490 DOM Level 2 Core
25854
+ * @see https://www.w3.org/TR/DOM-Level-3-Core/core.html#ID-102161490 DOM Level 3 Core
25855
+ * @see https://dom.spec.whatwg.org/#domimplementation DOM Living Standard
25592
25856
  */
25593
- function DOMImplementation$1(/* Object */ features) {
25594
- this._features = {};
25595
- if (features) {
25596
- for (var feature in features) {
25597
- this._features = features[feature];
25598
- }
25599
- }
25857
+ function DOMImplementation$1() {
25600
25858
  }
25859
+
25601
25860
  DOMImplementation$1.prototype = {
25602
- hasFeature: function(/* string */ feature, /* string */ version) {
25603
- var versions = this._features[feature.toLowerCase()];
25604
- if (versions && (!version || version in versions)) {
25861
+ /**
25862
+ * The DOMImplementation.hasFeature() method returns a Boolean flag indicating if a given feature is supported.
25863
+ * The different implementations fairly diverged in what kind of features were reported.
25864
+ * The latest version of the spec settled to force this method to always return true, where the functionality was accurate and in use.
25865
+ *
25866
+ * @deprecated It is deprecated and modern browsers return true in all cases.
25867
+ *
25868
+ * @param {string} feature
25869
+ * @param {string} [version]
25870
+ * @returns {boolean} always true
25871
+ *
25872
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/DOMImplementation/hasFeature MDN
25873
+ * @see https://www.w3.org/TR/REC-DOM-Level-1/level-one-core.html#ID-5CED94D7 DOM Level 1 Core
25874
+ * @see https://dom.spec.whatwg.org/#dom-domimplementation-hasfeature DOM Living Standard
25875
+ */
25876
+ hasFeature: function(feature, version) {
25605
25877
  return true;
25606
- } else {
25607
- return false;
25608
- }
25609
25878
  },
25610
- // Introduced in DOM Level 2:
25611
- createDocument:function(namespaceURI, qualifiedName, doctype){// raises:INVALID_CHARACTER_ERR,NAMESPACE_ERR,WRONG_DOCUMENT_ERR
25879
+ /**
25880
+ * Creates an XML Document object of the specified type with its document element.
25881
+ *
25882
+ * __It behaves slightly different from the description in the living standard__:
25883
+ * - There is no interface/class `XMLDocument`, it returns a `Document` instance.
25884
+ * - `contentType`, `encoding`, `mode`, `origin`, `url` fields are currently not declared.
25885
+ * - this implementation is not validating names or qualified names
25886
+ * (when parsing XML strings, the SAX parser takes care of that)
25887
+ *
25888
+ * @param {string|null} namespaceURI
25889
+ * @param {string} qualifiedName
25890
+ * @param {DocumentType=null} doctype
25891
+ * @returns {Document}
25892
+ *
25893
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/DOMImplementation/createDocument MDN
25894
+ * @see https://www.w3.org/TR/DOM-Level-2-Core/core.html#Level-2-Core-DOM-createDocument DOM Level 2 Core (initial)
25895
+ * @see https://dom.spec.whatwg.org/#dom-domimplementation-createdocument DOM Level 2 Core
25896
+ *
25897
+ * @see https://dom.spec.whatwg.org/#validate-and-extract DOM: Validate and extract
25898
+ * @see https://www.w3.org/TR/xml/#NT-NameStartChar XML Spec: Names
25899
+ * @see https://www.w3.org/TR/xml-names/#ns-qualnames XML Namespaces: Qualified names
25900
+ */
25901
+ createDocument: function(namespaceURI, qualifiedName, doctype){
25612
25902
  var doc = new Document();
25613
25903
  doc.implementation = this;
25614
25904
  doc.childNodes = new NodeList();
25615
- doc.doctype = doctype;
25616
- if(doctype){
25905
+ doc.doctype = doctype || null;
25906
+ if (doctype){
25617
25907
  doc.appendChild(doctype);
25618
25908
  }
25619
- if(qualifiedName){
25620
- var root = doc.createElementNS(namespaceURI,qualifiedName);
25909
+ if (qualifiedName){
25910
+ var root = doc.createElementNS(namespaceURI, qualifiedName);
25621
25911
  doc.appendChild(root);
25622
25912
  }
25623
25913
  return doc;
25624
25914
  },
25625
- // Introduced in DOM Level 2:
25626
- createDocumentType:function(qualifiedName, publicId, systemId){// raises:INVALID_CHARACTER_ERR,NAMESPACE_ERR
25915
+ /**
25916
+ * Returns a doctype, with the given `qualifiedName`, `publicId`, and `systemId`.
25917
+ *
25918
+ * __This behavior is slightly different from the in the specs__:
25919
+ * - this implementation is not validating names or qualified names
25920
+ * (when parsing XML strings, the SAX parser takes care of that)
25921
+ *
25922
+ * @param {string} qualifiedName
25923
+ * @param {string} [publicId]
25924
+ * @param {string} [systemId]
25925
+ * @returns {DocumentType} which can either be used with `DOMImplementation.createDocument` upon document creation
25926
+ * or can be put into the document via methods like `Node.insertBefore()` or `Node.replaceChild()`
25927
+ *
25928
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/DOMImplementation/createDocumentType MDN
25929
+ * @see https://www.w3.org/TR/DOM-Level-2-Core/core.html#Level-2-Core-DOM-createDocType DOM Level 2 Core
25930
+ * @see https://dom.spec.whatwg.org/#dom-domimplementation-createdocumenttype DOM Living Standard
25931
+ *
25932
+ * @see https://dom.spec.whatwg.org/#validate-and-extract DOM: Validate and extract
25933
+ * @see https://www.w3.org/TR/xml/#NT-NameStartChar XML Spec: Names
25934
+ * @see https://www.w3.org/TR/xml-names/#ns-qualnames XML Namespaces: Qualified names
25935
+ */
25936
+ createDocumentType: function(qualifiedName, publicId, systemId){
25627
25937
  var node = new DocumentType();
25628
25938
  node.name = qualifiedName;
25629
25939
  node.nodeName = qualifiedName;
25630
- node.publicId = publicId;
25631
- node.systemId = systemId;
25632
- // Introduced in DOM Level 2:
25633
- //readonly attribute DOMString internalSubset;
25634
-
25635
- //TODO:..
25636
- // readonly attribute NamedNodeMap entities;
25637
- // readonly attribute NamedNodeMap notations;
25940
+ node.publicId = publicId || '';
25941
+ node.systemId = systemId || '';
25942
+
25638
25943
  return node;
25639
25944
  }
25640
25945
  };
@@ -25773,22 +26078,25 @@ If this message still persists after updating, please report an issue: https://g
25773
26078
 
25774
26079
  function Document(){
25775
26080
  }
26081
+
25776
26082
  function _onAddAttribute(doc,el,newAttr){
25777
26083
  doc && doc._inc++;
25778
26084
  var ns = newAttr.namespaceURI ;
25779
- if(ns == 'http://www.w3.org/2000/xmlns/'){
26085
+ if(ns === NAMESPACE$1.XMLNS){
25780
26086
  //update namespace
25781
26087
  el._nsMap[newAttr.prefix?newAttr.localName:''] = newAttr.value;
25782
26088
  }
25783
26089
  }
26090
+
25784
26091
  function _onRemoveAttribute(doc,el,newAttr,remove){
25785
26092
  doc && doc._inc++;
25786
26093
  var ns = newAttr.namespaceURI ;
25787
- if(ns == 'http://www.w3.org/2000/xmlns/'){
26094
+ if(ns === NAMESPACE$1.XMLNS){
25788
26095
  //update namespace
25789
26096
  delete el._nsMap[newAttr.prefix?newAttr.localName:''];
25790
26097
  }
25791
26098
  }
26099
+
25792
26100
  function _onUpdateChild(doc,el,newChild){
25793
26101
  if(doc && doc._inc){
25794
26102
  doc._inc++;
@@ -25904,8 +26212,8 @@ If this message still persists after updating, please report an issue: https://g
25904
26212
  doctype : null,
25905
26213
  documentElement : null,
25906
26214
  _inc : 1,
25907
-
25908
- insertBefore : function(newChild, refChild){//raises
26215
+
26216
+ insertBefore : function(newChild, refChild){//raises
25909
26217
  if(newChild.nodeType == DOCUMENT_FRAGMENT_NODE){
25910
26218
  var child = newChild.firstChild;
25911
26219
  while(child){
@@ -25918,7 +26226,7 @@ If this message still persists after updating, please report an issue: https://g
25918
26226
  if(this.documentElement == null && newChild.nodeType == ELEMENT_NODE){
25919
26227
  this.documentElement = newChild;
25920
26228
  }
25921
-
26229
+
25922
26230
  return _insertBefore(this,newChild,refChild),(newChild.ownerDocument = this),newChild;
25923
26231
  },
25924
26232
  removeChild : function(oldChild){
@@ -25944,28 +26252,58 @@ If this message still persists after updating, please report an issue: https://g
25944
26252
  });
25945
26253
  return rtv;
25946
26254
  },
25947
-
25948
- getElementsByClassName: function(className) {
25949
- var pattern = new RegExp("(^|\\s)" + className + "(\\s|$)");
26255
+
26256
+ /**
26257
+ * The `getElementsByClassName` method of `Document` interface returns an array-like object
26258
+ * of all child elements which have **all** of the given class name(s).
26259
+ *
26260
+ * Returns an empty list if `classeNames` is an empty string or only contains HTML white space characters.
26261
+ *
26262
+ *
26263
+ * Warning: This is a live LiveNodeList.
26264
+ * Changes in the DOM will reflect in the array as the changes occur.
26265
+ * If an element selected by this array no longer qualifies for the selector,
26266
+ * it will automatically be removed. Be aware of this for iteration purposes.
26267
+ *
26268
+ * @param {string} classNames is a string representing the class name(s) to match; multiple class names are separated by (ASCII-)whitespace
26269
+ *
26270
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementsByClassName
26271
+ * @see https://dom.spec.whatwg.org/#concept-getelementsbyclassname
26272
+ */
26273
+ getElementsByClassName: function(classNames) {
26274
+ var classNamesSet = toOrderedSet(classNames);
25950
26275
  return new LiveNodeList(this, function(base) {
25951
26276
  var ls = [];
25952
- _visitNode(base.documentElement, function(node) {
25953
- if(node !== base && node.nodeType == ELEMENT_NODE) {
25954
- if(pattern.test(node.getAttribute('class'))) {
25955
- ls.push(node);
26277
+ if (classNamesSet.length > 0) {
26278
+ _visitNode(base.documentElement, function(node) {
26279
+ if(node !== base && node.nodeType === ELEMENT_NODE) {
26280
+ var nodeClassNames = node.getAttribute('class');
26281
+ // can be null if the attribute does not exist
26282
+ if (nodeClassNames) {
26283
+ // before splitting and iterating just compare them for the most common case
26284
+ var matches = classNames === nodeClassNames;
26285
+ if (!matches) {
26286
+ var nodeClassNamesSet = toOrderedSet(nodeClassNames);
26287
+ matches = classNamesSet.every(arrayIncludes(nodeClassNamesSet));
26288
+ }
26289
+ if(matches) {
26290
+ ls.push(node);
26291
+ }
26292
+ }
25956
26293
  }
25957
- }
25958
- });
26294
+ });
26295
+ }
25959
26296
  return ls;
25960
26297
  });
25961
26298
  },
25962
-
26299
+
25963
26300
  //document factory method:
25964
26301
  createElement : function(tagName){
25965
26302
  var node = new Element();
25966
26303
  node.ownerDocument = this;
25967
26304
  node.nodeName = tagName;
25968
26305
  node.tagName = tagName;
26306
+ node.localName = tagName;
25969
26307
  node.childNodes = new NodeList();
25970
26308
  var attrs = node.attributes = new NamedNodeMap();
25971
26309
  attrs._ownerElement = node;
@@ -26272,36 +26610,49 @@ If this message still persists after updating, please report an issue: https://g
26272
26610
  //console.log('###',this.nodeType,uri,prefix,buf.join(''))
26273
26611
  return buf.join('');
26274
26612
  }
26275
- function needNamespaceDefine(node,isHTML, visibleNamespaces) {
26276
- var prefix = node.prefix||'';
26613
+
26614
+ function needNamespaceDefine(node, isHTML, visibleNamespaces) {
26615
+ var prefix = node.prefix || '';
26277
26616
  var uri = node.namespaceURI;
26278
- if (!prefix && !uri){
26617
+ // According to [Namespaces in XML 1.0](https://www.w3.org/TR/REC-xml-names/#ns-using) ,
26618
+ // and more specifically https://www.w3.org/TR/REC-xml-names/#nsc-NoPrefixUndecl :
26619
+ // > In a namespace declaration for a prefix [...], the attribute value MUST NOT be empty.
26620
+ // in a similar manner [Namespaces in XML 1.1](https://www.w3.org/TR/xml-names11/#ns-using)
26621
+ // and more specifically https://www.w3.org/TR/xml-names11/#nsc-NSDeclared :
26622
+ // > [...] Furthermore, the attribute value [...] must not be an empty string.
26623
+ // so serializing empty namespace value like xmlns:ds="" would produce an invalid XML document.
26624
+ if (!uri) {
26279
26625
  return false;
26280
26626
  }
26281
- if (prefix === "xml" && uri === "http://www.w3.org/XML/1998/namespace"
26282
- || uri == 'http://www.w3.org/2000/xmlns/'){
26627
+ if (prefix === "xml" && uri === NAMESPACE$1.XML || uri === NAMESPACE$1.XMLNS) {
26283
26628
  return false;
26284
26629
  }
26285
26630
 
26286
26631
  var i = visibleNamespaces.length;
26287
- //console.log('@@@@',node.tagName,prefix,uri,visibleNamespaces)
26288
26632
  while (i--) {
26289
26633
  var ns = visibleNamespaces[i];
26290
26634
  // get namespace prefix
26291
- //console.log(node.nodeType,node.tagName,ns.prefix,prefix)
26292
- if (ns.prefix == prefix){
26293
- return ns.namespace != uri;
26635
+ if (ns.prefix === prefix) {
26636
+ return ns.namespace !== uri;
26294
26637
  }
26295
26638
  }
26296
- //console.log(isHTML,uri,prefix=='')
26297
- //if(isHTML && prefix ==null && uri == 'http://www.w3.org/1999/xhtml'){
26298
- // return false;
26299
- //}
26300
- //node.flag = '11111'
26301
- //console.error(3,true,node.flag,node.prefix,node.namespaceURI)
26302
26639
  return true;
26303
26640
  }
26641
+ /**
26642
+ * Well-formed constraint: No < in Attribute Values
26643
+ * The replacement text of any entity referred to directly or indirectly in an attribute value must not contain a <.
26644
+ * @see https://www.w3.org/TR/xml/#CleanAttrVals
26645
+ * @see https://www.w3.org/TR/xml/#NT-AttValue
26646
+ */
26647
+ function addSerializedAttribute(buf, qualifiedName, value) {
26648
+ buf.push(' ', qualifiedName, '="', value.replace(/[<&"]/g,_xmlEncoder), '"');
26649
+ }
26650
+
26304
26651
  function serializeToString(node,buf,isHTML,nodeFilter,visibleNamespaces){
26652
+ if (!visibleNamespaces) {
26653
+ visibleNamespaces = [];
26654
+ }
26655
+
26305
26656
  if(nodeFilter){
26306
26657
  node = nodeFilter(node);
26307
26658
  if(node){
@@ -26314,20 +26665,40 @@ If this message still persists after updating, please report an issue: https://g
26314
26665
  }
26315
26666
  //buf.sort.apply(attrs, attributeSorter);
26316
26667
  }
26668
+
26317
26669
  switch(node.nodeType){
26318
26670
  case ELEMENT_NODE:
26319
- if (!visibleNamespaces) visibleNamespaces = [];
26320
- visibleNamespaces.length;
26321
26671
  var attrs = node.attributes;
26322
26672
  var len = attrs.length;
26323
26673
  var child = node.firstChild;
26324
26674
  var nodeName = node.tagName;
26325
26675
 
26326
- isHTML = (htmlns === node.namespaceURI) ||isHTML;
26327
- buf.push('<',nodeName);
26328
-
26329
-
26330
-
26676
+ isHTML = NAMESPACE$1.isHTML(node.namespaceURI) || isHTML;
26677
+
26678
+ var prefixedNodeName = nodeName;
26679
+ if (!isHTML && !node.prefix && node.namespaceURI) {
26680
+ var defaultNS;
26681
+ for (var ai = 0; ai < attrs.length; ai++) {
26682
+ if (attrs.item(ai).name === 'xmlns') {
26683
+ defaultNS = attrs.item(ai).value;
26684
+ break
26685
+ }
26686
+ }
26687
+ if (defaultNS !== node.namespaceURI) {
26688
+ for (var nsi = visibleNamespaces.length - 1; nsi >= 0; nsi--) {
26689
+ var namespace = visibleNamespaces[nsi];
26690
+ if (namespace.namespace === node.namespaceURI) {
26691
+ if (namespace.prefix) {
26692
+ prefixedNodeName = namespace.prefix + ':' + nodeName;
26693
+ }
26694
+ break
26695
+ }
26696
+ }
26697
+ }
26698
+ }
26699
+
26700
+ buf.push('<', prefixedNodeName);
26701
+
26331
26702
  for(var i=0;i<len;i++){
26332
26703
  // add namespaces for attributes
26333
26704
  var attr = attrs.item(i);
@@ -26337,28 +26708,24 @@ If this message still persists after updating, please report an issue: https://g
26337
26708
  visibleNamespaces.push({ prefix: '', namespace: attr.value });
26338
26709
  }
26339
26710
  }
26711
+
26340
26712
  for(var i=0;i<len;i++){
26341
26713
  var attr = attrs.item(i);
26342
26714
  if (needNamespaceDefine(attr,isHTML, visibleNamespaces)) {
26343
26715
  var prefix = attr.prefix||'';
26344
26716
  var uri = attr.namespaceURI;
26345
- var ns = prefix ? ' xmlns:' + prefix : " xmlns";
26346
- buf.push(ns, '="' , uri , '"');
26717
+ addSerializedAttribute(buf, prefix ? 'xmlns:' + prefix : "xmlns", uri);
26347
26718
  visibleNamespaces.push({ prefix: prefix, namespace:uri });
26348
26719
  }
26349
26720
  serializeToString(attr,buf,isHTML,nodeFilter,visibleNamespaces);
26350
26721
  }
26722
+
26351
26723
  // add namespace for current node
26352
- if (needNamespaceDefine(node,isHTML, visibleNamespaces)) {
26724
+ if (nodeName === prefixedNodeName && needNamespaceDefine(node, isHTML, visibleNamespaces)) {
26353
26725
  var prefix = node.prefix||'';
26354
26726
  var uri = node.namespaceURI;
26355
- if (uri) {
26356
- // Avoid empty namespace value like xmlns:ds=""
26357
- // Empty namespace URL will we produce an invalid XML document
26358
- var ns = prefix ? ' xmlns:' + prefix : " xmlns";
26359
- buf.push(ns, '="' , uri , '"');
26360
- visibleNamespaces.push({ prefix: prefix, namespace:uri });
26361
- }
26727
+ addSerializedAttribute(buf, prefix ? 'xmlns:' + prefix : "xmlns", uri);
26728
+ visibleNamespaces.push({ prefix: prefix, namespace:uri });
26362
26729
  }
26363
26730
 
26364
26731
  if(child || isHTML && !/^(?:meta|link|img|br|hr|input)$/i.test(nodeName)){
@@ -26369,18 +26736,18 @@ If this message still persists after updating, please report an issue: https://g
26369
26736
  if(child.data){
26370
26737
  buf.push(child.data);
26371
26738
  }else {
26372
- serializeToString(child,buf,isHTML,nodeFilter,visibleNamespaces);
26739
+ serializeToString(child, buf, isHTML, nodeFilter, visibleNamespaces.slice());
26373
26740
  }
26374
26741
  child = child.nextSibling;
26375
26742
  }
26376
26743
  }else
26377
26744
  {
26378
26745
  while(child){
26379
- serializeToString(child,buf,isHTML,nodeFilter,visibleNamespaces);
26746
+ serializeToString(child, buf, isHTML, nodeFilter, visibleNamespaces.slice());
26380
26747
  child = child.nextSibling;
26381
26748
  }
26382
26749
  }
26383
- buf.push('</',nodeName,'>');
26750
+ buf.push('</',prefixedNodeName,'>');
26384
26751
  }else {
26385
26752
  buf.push('/>');
26386
26753
  }
@@ -26391,18 +26758,12 @@ If this message still persists after updating, please report an issue: https://g
26391
26758
  case DOCUMENT_FRAGMENT_NODE:
26392
26759
  var child = node.firstChild;
26393
26760
  while(child){
26394
- serializeToString(child,buf,isHTML,nodeFilter,visibleNamespaces);
26761
+ serializeToString(child, buf, isHTML, nodeFilter, visibleNamespaces.slice());
26395
26762
  child = child.nextSibling;
26396
26763
  }
26397
26764
  return;
26398
26765
  case ATTRIBUTE_NODE:
26399
- /**
26400
- * Well-formedness constraint: No < in Attribute Values
26401
- * The replacement text of any entity referred to directly or indirectly in an attribute value must not contain a <.
26402
- * @see https://www.w3.org/TR/xml/#CleanAttrVals
26403
- * @see https://www.w3.org/TR/xml/#NT-AttValue
26404
- */
26405
- return buf.push(' ', node.name, '="', node.value.replace(/[<&"]/g,_xmlEncoder), '"');
26766
+ return addSerializedAttribute(buf, node.name, node.value);
26406
26767
  case TEXT_NODE:
26407
26768
  /**
26408
26769
  * The ampersand character (&) and the left angle bracket (<) must not appear in their literal form,
@@ -26553,10 +26914,12 @@ If this message still persists after updating, please report an issue: https://g
26553
26914
  return this.$$length;
26554
26915
  }
26555
26916
  });
26917
+
26556
26918
  Object.defineProperty(Node.prototype,'textContent',{
26557
26919
  get:function(){
26558
26920
  return getTextContent(this);
26559
26921
  },
26922
+
26560
26923
  set:function(data){
26561
26924
  switch(this.nodeType){
26562
26925
  case ELEMENT_NODE:
@@ -26568,8 +26931,8 @@ If this message still persists after updating, please report an issue: https://g
26568
26931
  this.appendChild(this.ownerDocument.createTextNode(data));
26569
26932
  }
26570
26933
  break;
26934
+
26571
26935
  default:
26572
- //TODO:
26573
26936
  this.data = data;
26574
26937
  this.value = data;
26575
26938
  this.nodeValue = data;
@@ -26594,6 +26957,7 @@ If this message still persists after updating, please report an issue: https://g
26594
26957
  return node.nodeValue;
26595
26958
  }
26596
26959
  }
26960
+
26597
26961
  __set__ = function(object,key,value){
26598
26962
  //console.log(value)
26599
26963
  object['$$'+key] = value;
@@ -26603,11 +26967,19 @@ If this message still persists after updating, please report an issue: https://g
26603
26967
  }
26604
26968
 
26605
26969
  //if(typeof require == 'function'){
26606
- dom.Node = Node;
26970
+ dom.DocumentType = DocumentType;
26607
26971
  dom.DOMException = DOMException;
26608
26972
  dom.DOMImplementation = DOMImplementation$1;
26973
+ dom.Element = Element;
26974
+ dom.Node = Node;
26975
+ dom.NodeList = NodeList;
26609
26976
  dom.XMLSerializer = XMLSerializer;
26610
26977
 
26978
+ var conventions = conventions$2;
26979
+ var entities = entities$1;
26980
+
26981
+ var NAMESPACE = conventions.NAMESPACE;
26982
+
26611
26983
  function DOMParser(options){
26612
26984
  this.options = options ||{locator:{}};
26613
26985
  }
@@ -26620,7 +26992,7 @@ If this message still persists after updating, please report an issue: https://g
26620
26992
  var locator = options.locator;
26621
26993
  var defaultNSMap = options.xmlns||{};
26622
26994
  var isHTML = /\/x?html?$/.test(mimeType);//mimeType.toLowerCase().indexOf('html') > -1;
26623
- var entityMap = isHTML?htmlEntity.entityMap:{'lt':'<','gt':'>','amp':'&','quot':'"','apos':"'"};
26995
+ var entityMap = isHTML ? entities.HTML_ENTITIES : entities.XML_ENTITIES;
26624
26996
  if(locator){
26625
26997
  domBuilder.setDocumentLocator(locator);
26626
26998
  }
@@ -26628,9 +27000,9 @@ If this message still persists after updating, please report an issue: https://g
26628
27000
  sax.errorHandler = buildErrorHandler(errorHandler,domBuilder,locator);
26629
27001
  sax.domBuilder = options.domBuilder || domBuilder;
26630
27002
  if(isHTML){
26631
- defaultNSMap['']= 'http://www.w3.org/1999/xhtml';
27003
+ defaultNSMap[''] = NAMESPACE.HTML;
26632
27004
  }
26633
- defaultNSMap.xml = defaultNSMap.xml || 'http://www.w3.org/XML/1998/namespace';
27005
+ defaultNSMap.xml = defaultNSMap.xml || NAMESPACE.XML;
26634
27006
  if(source && typeof source === 'string'){
26635
27007
  sax.parse(source,defaultNSMap,entityMap);
26636
27008
  }else {
@@ -26852,7 +27224,6 @@ If this message still persists after updating, please report an issue: https://g
26852
27224
  }//appendChild and setAttributeNS are preformance key
26853
27225
 
26854
27226
  //if(typeof require == 'function'){
26855
- var htmlEntity = entities;
26856
27227
  var sax = sax$1;
26857
27228
  var XMLReader = sax.XMLReader;
26858
27229
  var ParseError = sax.ParseError;
@@ -27599,6 +27970,23 @@ If this message still persists after updating, please report an issue: https://g
27599
27970
  };
27600
27971
  }
27601
27972
 
27973
+ /**
27974
+ * Pipes all emitted events from one emitter to another.
27975
+ */
27976
+ function pipeEvents(source, destination) {
27977
+ const rawEmit = source.emit;
27978
+ // @ts-ignore
27979
+ if (rawEmit._isPiped) {
27980
+ return;
27981
+ }
27982
+ source.emit = function (event, ...data) {
27983
+ destination.emit(event, ...data);
27984
+ return rawEmit.call(this, event, ...data);
27985
+ };
27986
+ // @ts-ignore
27987
+ source.emit._isPiped = true;
27988
+ }
27989
+
27602
27990
  // Declare the list of event handlers on the module's scope
27603
27991
  // so it persists between Fash refreshes of the application's code.
27604
27992
  let listeners = [];
@@ -27617,12 +28005,15 @@ If this message still persists after updating, please report an issue: https://g
27617
28005
  if (lib$5.exports.isNodeProcess()) {
27618
28006
  throw new Error(devUtils.formatMessage('Failed to execute `setupWorker` in a non-browser environment. Consider using `setupServer` for Node.js environment instead.'));
27619
28007
  }
28008
+ const emitter = new lib$4.StrictEventEmitter();
28009
+ const publicEmitter = new lib$4.StrictEventEmitter();
28010
+ pipeEvents(emitter, publicEmitter);
27620
28011
  const context = {
27621
28012
  startOptions: undefined,
27622
28013
  worker: null,
27623
28014
  registration: null,
27624
28015
  requestHandlers: [...requestHandlers],
27625
- emitter: new lib$4.StrictEventEmitter(),
28016
+ emitter,
27626
28017
  workerChannel: {
27627
28018
  on(eventType, callback) {
27628
28019
  context.events.addListener(navigator.serviceWorker, 'message', (event) => {
@@ -27688,7 +28079,12 @@ If this message still persists after updating, please report an issue: https://g
27688
28079
  : createStop(context);
27689
28080
  return {
27690
28081
  start: prepareStartHandler(startHandler, context),
27691
- stop: stopHandler,
28082
+ stop() {
28083
+ context.events.removeAllListeners();
28084
+ context.emitter.removeAllListeners();
28085
+ publicEmitter.removeAllListeners();
28086
+ stopHandler();
28087
+ },
27692
28088
  use(...handlers) {
27693
28089
  use(context.requestHandlers, ...handlers);
27694
28090
  },
@@ -27715,8 +28111,16 @@ If this message still persists after updating, please report an issue: https://g
27715
28111
  console.groupEnd();
27716
28112
  });
27717
28113
  },
27718
- on(eventType, listener) {
27719
- context.emitter.addListener(eventType, listener);
28114
+ events: {
28115
+ on(...args) {
28116
+ return publicEmitter.on(...args);
28117
+ },
28118
+ removeListener(...args) {
28119
+ return publicEmitter.removeListener(...args);
28120
+ },
28121
+ removeAllListeners(...args) {
28122
+ return publicEmitter.removeAllListeners(...args);
28123
+ },
27720
28124
  },
27721
28125
  };
27722
28126
  }