Skip to content

Commit

Permalink
chore: improve error range for mismatched tag names
Browse files Browse the repository at this point in the history
  • Loading branch information
suneettipirneni committed Aug 5, 2022
1 parent dcc0536 commit af36851
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
1 change: 0 additions & 1 deletion tsdoc/src/emitters/TSDocEmitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ export class TSDocEmitter {
this._writeContent('</');
this._writeContent(docXmlElement.name);
this._writeContent('>');
console.log(docXmlElement.spacingAfterEndTag);
this._writeContent(docXmlElement.spacingAfterEndTag);

break;
Expand Down
15 changes: 11 additions & 4 deletions tsdoc/src/parser/NodeParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1936,17 +1936,21 @@ export class NodeParser {
return childNode;
}

// Parse out all of the child nodes
// Add the child node to the list of child nodes.
childNodes.push(childNode);
continue;
}

// Begin parsing text nodes.
// We've hit an XML text node.

while (tokenReader.peekTokenKind() !== TokenKind.LessThan) {
// Technically any non-conflicting tokens are valid as XML text nodes.
// This means we could end up consuming all available input if we're erroneously
// given *only* a start tag (ie <tag> ...) .

// In other words, an unterminated XML element has a good chance of hitting EOI;
// Let's handle that case here.

if (tokenReader.peekTokenAfterKind() === TokenKind.EndOfInput) {
return this._backtrackAndCreateErrorRange(
tokenReader,
Expand Down Expand Up @@ -2008,7 +2012,9 @@ export class NodeParser {

const endTagOpeningDelimiterExcerpt: TokenSequence = tokenReader.extractAccumulatedSequence();

const endTagNameStartMarker: number = tokenReader.createMarker();
const endTagNameExcerpt: ResultOrFailure<TokenSequence> = this._parseXmlName(tokenReader);
const endTagnameEndMarker: number = tokenReader.createMarker();
if (isFailure(endTagNameExcerpt)) {
return this._backtrackAndCreateErrorForFailure(
tokenReader,
Expand All @@ -2020,9 +2026,10 @@ export class NodeParser {

// Verify that the tag names are matching, if they aren't create a failure.
if (endTagNameExcerpt.toString() !== startTagNameExcerpt.toString()) {
return this._backtrackAndCreateError(
return this._backtrackAndCreateErrorRange(
tokenReader,
endMarker,
endTagNameStartMarker,
endTagnameEndMarker,
TSDocMessageId.XmlTagNameMismatch,
`Expecting closing tag name to match opening tag name, got "${endTagNameExcerpt.toString()}" but expected "${startTagNameExcerpt.toString()}"`
);
Expand Down

0 comments on commit af36851

Please sign in to comment.