Skip to content

Commit d9fa35f

Browse files
committed
improve comments
1 parent 25f2363 commit d9fa35f

2 files changed

Lines changed: 22 additions & 4 deletions

File tree

src/Parser.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ const voidElements = new Set([
9494

9595
const foreignContextElements = new Set(["math", "svg"]);
9696

97+
/**
98+
* Elements that can be used to integrate HTML content within foreign namespaces (e.g., SVG or MathML).
99+
*
100+
* Entries must use the SVG-adjusted casing (e.g. "foreignObject" not
101+
* "foreignobject") since they are compared against adjusted tag names.
102+
*/
97103
const htmlIntegrationElements = new Set([
98104
"mi",
99105
"mo",
@@ -364,8 +370,10 @@ export class Parser implements Callbacks {
364370

365371
/*
366372
* Closing tags for SVG elements inside HTML integration points
367-
* (e.g. </foreignObject> while inside its own content) still need
368-
* case adjustment so the name matches what was pushed to the stack.
373+
* (e.g. </foreignObject> while inside its own content) need case
374+
* adjustment so the name matches what was pushed to the stack.
375+
* `foreignContext.length > 1` means a foreign ancestor exists —
376+
* the base [None] entry plus at least one pushed context.
369377
*/
370378
if (this.foreignContext.length > 1) {
371379
const adjusted = svgTagNameAdjustments.get(name);
@@ -395,7 +403,12 @@ export class Parser implements Callbacks {
395403
this.openTagStart = this.startIndex;
396404
this.tagname = name;
397405

398-
// The spec ignores a second <form> when one is already open.
406+
/*
407+
* The spec ignores a second <form> when one is already open.
408+
* Setting tagname to "" suppresses all downstream effects: attribs
409+
* stays null so endOpenTag is a no-op, and closeCurrentTag can't
410+
* match "" on the stack.
411+
*/
399412
if (this.htmlMode && name === "form" && this.stack.includes("form")) {
400413
this.tagname = "";
401414
return;

src/Tokenizer.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,10 +420,15 @@ export default class Tokenizer {
420420
!this.xmlMode &&
421421
this.currentSequence === Sequences.CommentEnd &&
422422
this.sequenceIndex <= 1 &&
423+
/*
424+
* We're still at the very start of the comment: the only
425+
* characters consumed since `<!--` are the dashes that
426+
* advanced sequenceIndex (0 for `<!-->`, 1 for `<!--->`).
427+
*/
423428
this.index === this.sectionStart + this.sequenceIndex &&
424429
c === CharCodes.Gt
425430
) {
426-
// `<!-->` and `<!--->` are valid empty HTML comments.
431+
// Abruptly closed empty HTML comment.
427432
this.emitComment(this.sequenceIndex);
428433
} else if (
429434
this.currentSequence === Sequences.CommentEnd &&

0 commit comments

Comments
 (0)