@xmldom/xmldom 0.9.9 → 0.9.10

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/index.d.ts CHANGED
@@ -448,7 +448,19 @@ declare module '@xmldom/xmldom' {
448
448
  * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Node/previousSibling)
449
449
  */
450
450
  readonly previousSibling: Node | null;
451
- /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Node/textContent) */
451
+ /**
452
+ * The text content of this node and its descendants.
453
+ *
454
+ * For {@link Element} and {@link DocumentFragment} nodes, returns the concatenation of the
455
+ * `nodeValue` of every descendant text node, excluding processing instruction and comment
456
+ * nodes. For all other node types, returns `nodeValue`.
457
+ *
458
+ * Setting `textContent` on an element or document fragment replaces all child nodes with a
459
+ * single text node; on other nodes it sets `data`, `value`, and `nodeValue` directly.
460
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Node/textContent)
461
+ *
462
+ * @see {@link https://dom.spec.whatwg.org/#dom-node-textcontent}
463
+ */
452
464
  textContent: string | null;
453
465
 
454
466
  /**
@@ -488,7 +500,12 @@ declare module '@xmldom/xmldom' {
488
500
  /**
489
501
  * Checks whether the given node is equal to this node.
490
502
  *
491
- * [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/Node/isEqualNode)
503
+ * Two nodes are equal when they have the same type, defining characteristics (for the type),
504
+ * and the same `childNodes`. The comparison is iterative to avoid stack overflows on deeply
505
+ * nested trees. `Attribute` nodes of each `Element` pair are also compared iteratively.
506
+ *
507
+ * @see {@link https://dom.spec.whatwg.org/#concept-node-equals}
508
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Node/isEqualNode}
492
509
  */
493
510
  isEqualNode(other: Node): boolean;
494
511
 
@@ -771,8 +788,11 @@ declare module '@xmldom/xmldom' {
771
788
  item(index: number): T | null;
772
789
  /**
773
790
  * Returns a string representation of the NodeList.
791
+ * Accepts the same options as `XMLSerializer.prototype.serializeToString`.
774
792
  */
775
- toString(nodeFilter: (node: T) => T | undefined): string;
793
+ toString(
794
+ options?: XMLSerializerOptions | ((node: T) => T | undefined)
795
+ ): string;
776
796
  /**
777
797
  * Filters the NodeList based on a predicate.
778
798
  *
@@ -1206,6 +1226,11 @@ declare module '@xmldom/xmldom' {
1206
1226
  /**
1207
1227
  * Creates a comment object with the specified data.
1208
1228
  *
1229
+ * No validation is performed at creation time. When the resulting document is serialized
1230
+ * with `requireWellFormed: true`, the serializer throws `InvalidStateError` if the comment
1231
+ * data contains `--` anywhere, ends with `-`, or contains characters outside the XML Char
1232
+ * production (W3C DOM Parsing §3.2.1.3). Without that option the data is emitted verbatim.
1233
+ *
1209
1234
  * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Document/createComment)
1210
1235
  */
1211
1236
  createComment(data: string): Comment;
@@ -1259,12 +1284,21 @@ declare module '@xmldom/xmldom' {
1259
1284
  createEntityReference(name: string): EntityReference;
1260
1285
 
1261
1286
  /**
1262
- * Returns a ProcessingInstruction node whose target is target and data is data. If target does
1263
- * not match the Name production an "InvalidCharacterError" DOMException will be thrown. If
1264
- * data contains "?>" an "InvalidCharacterError" DOMException will be thrown.
1287
+ * Returns a ProcessingInstruction node whose target is target and data is data.
1265
1288
  *
1266
- * [MDN
1267
- * Reference](https://developer.mozilla.org/docs/Web/API/Document/createProcessingInstruction)
1289
+ * __This behavior is slightly different from the in the specs__:
1290
+ * - it does not do any input validation on the arguments and doesn't throw
1291
+ * "InvalidCharacterError".
1292
+ *
1293
+ * Note: When the resulting document is serialized with `requireWellFormed: true`, the
1294
+ * serializer throws `InvalidStateError` if `.target` contains `:` or is an ASCII
1295
+ * case-insensitive match for `"xml"`, or if `.data` contains `?>` or characters outside the
1296
+ * XML Char production (W3C DOM Parsing §3.2.1.7). Without that option the data is emitted
1297
+ * verbatim.
1298
+ *
1299
+ * @see https://developer.mozilla.org/docs/Web/API/Document/createProcessingInstruction
1300
+ * @see https://dom.spec.whatwg.org/#dom-document-createprocessinginstruction
1301
+ * @see https://www.w3.org/TR/DOM-Parsing/#dfn-concept-serialize-xml §3.2.1.7
1268
1302
  */
1269
1303
  createProcessingInstruction(
1270
1304
  target: string,
@@ -1342,11 +1376,12 @@ declare module '@xmldom/xmldom' {
1342
1376
  localName: string
1343
1377
  ): LiveNodeList<Element>;
1344
1378
  /**
1345
- * Returns a copy of node. If deep is true, the copy also includes the node's descendants.
1346
- *
1347
- * If node is a document or a shadow root, throws a "NotSupportedError" DOMException.
1379
+ * Imports a node from another document into this document, creating a new copy owned by this
1380
+ * document. If `deep` is true, the copy also includes the node's descendants.
1348
1381
  *
1349
1382
  * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Document/importNode)
1383
+ *
1384
+ * @see {@link https://dom.spec.whatwg.org/#dom-document-importnode}
1350
1385
  */
1351
1386
  importNode<T extends Node>(node: T, deep?: boolean): T;
1352
1387
  }
@@ -1361,10 +1396,32 @@ declare module '@xmldom/xmldom' {
1361
1396
  interface DocumentType extends Node {
1362
1397
  /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/DocumentType/name) */
1363
1398
  readonly name: string;
1399
+ /**
1400
+ * The internal subset string (the raw content between `[` and `]`), or an empty string.
1401
+ * Declared `readonly` by the WHATWG DOM spec; xmldom does not enforce this — direct
1402
+ * property writes succeed and the written value is serialized verbatim.
1403
+ * When serialized with `requireWellFormed: true`, throws `InvalidStateError` if the value
1404
+ * contains `"]>"`.
1405
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/DocumentType/internalSubset)
1406
+ */
1364
1407
  readonly internalSubset: string;
1365
- /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/DocumentType/publicId) */
1408
+ /**
1409
+ * The external subset public identifier, stored verbatim including surrounding quotes.
1410
+ * Declared `readonly` by the WHATWG DOM spec; xmldom does not enforce this — direct
1411
+ * property writes succeed and the written value is serialized verbatim.
1412
+ * When serialized with `requireWellFormed: true`, throws `InvalidStateError` if the value
1413
+ * is non-empty and does not match the XML `PubidLiteral` production (XML 1.0 [12]).
1414
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/DocumentType/publicId)
1415
+ */
1366
1416
  readonly publicId: string;
1367
- /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/DocumentType/systemId) */
1417
+ /**
1418
+ * The external subset system identifier, stored verbatim including surrounding quotes.
1419
+ * Declared `readonly` by the WHATWG DOM spec; xmldom does not enforce this — direct
1420
+ * property writes succeed and the written value is serialized verbatim.
1421
+ * When serialized with `requireWellFormed: true`, throws `InvalidStateError` if the value
1422
+ * is non-empty and does not match the XML `SystemLiteral` production (XML 1.0 [11]).
1423
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/DocumentType/systemId)
1424
+ */
1368
1425
  readonly systemId: string;
1369
1426
  }
1370
1427
 
@@ -1429,8 +1486,21 @@ declare module '@xmldom/xmldom' {
1429
1486
  */
1430
1487
  createDocumentType(
1431
1488
  qualifiedName: string,
1489
+ /**
1490
+ * External subset public identifier. Stored verbatim including surrounding quotes.
1491
+ * No creation-time validation — deferred to a future breaking release.
1492
+ */
1432
1493
  publicId?: string,
1433
- systemId?: string
1494
+ /**
1495
+ * External subset system identifier. Stored verbatim including surrounding quotes.
1496
+ * No creation-time validation — deferred to a future breaking release.
1497
+ */
1498
+ systemId?: string,
1499
+ /**
1500
+ * Internal subset string (content between `[` and `]`). Stored verbatim.
1501
+ * No creation-time validation — deferred to a future breaking release.
1502
+ */
1503
+ internalSubset?: string
1434
1504
  ): DocumentType;
1435
1505
 
1436
1506
  /**
@@ -1463,18 +1533,73 @@ declare module '@xmldom/xmldom' {
1463
1533
  hasFeature(feature: string, version?: string): true;
1464
1534
  }
1465
1535
 
1536
+ /** Options accepted by `XMLSerializer.prototype.serializeToString` and `node.toString`. */
1537
+ interface XMLSerializerOptions {
1538
+ /**
1539
+ * When `true`, the serializer throws `InvalidStateError` for content that would produce
1540
+ * ill-formed XML: CDATASection data containing `"]]>"`; Text data with characters outside
1541
+ * the XML Char production; a Comment node whose data contains `--` anywhere or ends with
1542
+ * `-`; or a Document with no `documentElement`.
1543
+ *
1544
+ * @default false
1545
+ */
1546
+ requireWellFormed?: boolean;
1547
+ /**
1548
+ * When `true` (the default), `"]]>"` sequences in CDATASection data are split across
1549
+ * concatenated CDATA sections. **Deprecated** — this option and the underlying split
1550
+ * mechanics will be removed in the next breaking release. Callers should migrate to `{
1551
+ * requireWellFormed: true }`, which throws `InvalidStateError` instead of transforming.
1552
+ *
1553
+ * @default true
1554
+ */
1555
+ splitCDATASections?: boolean;
1556
+ /** A filter function applied to each node before serialization. */
1557
+ nodeFilter?: (node: Node) => Node | null | undefined;
1558
+ }
1559
+
1466
1560
  class XMLSerializer {
1467
1561
  /**
1468
1562
  * Returns the result of serializing `node` to XML.
1469
1563
  *
1470
- * __This implementation differs from the specification:__ - CDATASection nodes whose data
1471
- * contains `]]>` are serialized by splitting the section at each `]]>` occurrence (following
1472
- * W3C DOM Level 3 Core `split-cdata-sections`
1473
- * default behaviour). A configurable option is not yet implemented.
1564
+ * When `options.requireWellFormed` is `true`, throws `InvalidStateError` for content that
1565
+ * would produce ill-formed XML. When `options.splitCDATASections` is `false`,
1566
+ * CDATASection data is emitted verbatim. Passing a function as `options` is treated as a
1567
+ * legacy `nodeFilter` for backward compatibility.
1568
+ *
1569
+ * __This implementation differs from the specification:__ - CDATASection serialization is
1570
+ * not specified by W3C DOM Parsing or WHATWG DOM Parsing (see
1571
+ * {@link https://github.com/w3c/DOM-Parsing/issues/38 w3c/DOM-Parsing#38}).
1572
+ * When `splitCDATASections` is `true` (the default), `"]]>"` sequences are split across
1573
+ * concatenated CDATA sections — **deprecated**, will be removed in the next breaking
1574
+ * release.
1575
+ * - W3C DOM Parsing §3.2.1.1 requires well-formedness checks on Element `localName`s,
1576
+ * prefixes, and attribute serialization when `requireWellFormed` is `true`. These checks are
1577
+ * **not implemented** in this release — see the tracking issue filed against the next
1578
+ * breaking milestone.
1474
1579
  *
1580
+ * @throws {DOMException}
1581
+ * `InvalidStateError` when `requireWellFormed` is `true` and any of the following conditions
1582
+ * hold:
1583
+ * - CDATASection data contains `"]]>"`
1584
+ * - Text data contains characters outside the XML Char production
1585
+ * - a Comment node's data contains `--` anywhere or ends with `-`
1586
+ * - a ProcessingInstruction's target contains `:` or is an ASCII case-insensitive match for
1587
+ * `"xml"`, or its data contains `?>` or characters outside the XML Char production
1588
+ * - a DocumentType's `publicId` is non-empty and does not match the XML `PubidLiteral`
1589
+ * production (W3C DOM Parsing §3.2.1.3; XML 1.0 production [12])
1590
+ * - a DocumentType's `systemId` is non-empty and does not match the XML `SystemLiteral`
1591
+ * production (W3C DOM Parsing §3.2.1.3; XML 1.0 production [11])
1592
+ * - a DocumentType's `internalSubset` contains `"]>"`
1593
+ * - the Document has no `documentElement`
1594
+ * @see https://developer.mozilla.org/docs/Web/API/XMLSerializer/serializeToString
1475
1595
  * @see https://html.spec.whatwg.org/#dom-xmlserializer-serializetostring
1596
+ * @see https://github.com/w3c/DOM-Parsing/issues/84
1597
+ * @prettierignore
1476
1598
  */
1477
- serializeToString(node: Node, nodeFilter?: (node: Node) => boolean): string;
1599
+ serializeToString(
1600
+ node: Node,
1601
+ options?: XMLSerializerOptions | ((node: Node) => Node | null | undefined)
1602
+ ): string;
1478
1603
  }
1479
1604
  // END ./lib/dom.js
1480
1605