Skip to content

Commit

Permalink
Stop tag after @callback from crashing (#48860)
Browse files Browse the repository at this point in the history
By copying the kludge in @typedef. @callback's order is simpler, so the
kludge is simpler. However, it's wrong here, and in @typedef. Parsing
tag comments is normally supposed to happen at the end of a tag, but in
@callback and @typedef happens *before* parsing the nested
@param/@Property tags.

I still need to figure out what a real fix is -- but for the beta,
copying the existing crash-avoidance kludge from @typedef is best
anyway. I added a test case for typedefs for future use as well.
  • Loading branch information
sandersn authored Apr 27, 2022
1 parent bab02d2 commit 2a78b22
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8579,7 +8579,8 @@ namespace ts {
if (!comment) {
comment = parseTrailingTagComments(start, getNodePos(), indent, indentText);
}
return finishNode(factory.createJSDocCallbackTag(tagName, typeExpression, fullName, comment), start);
const end = comment !== undefined ? getNodePos() : typeExpression.end;
return finishNode(factory.createJSDocCallbackTag(tagName, typeExpression, fullName, comment), start, end);
}

function escapedTextsEqual(a: EntityName, b: EntityName): boolean {
Expand Down
19 changes: 19 additions & 0 deletions tests/cases/fourslash/jsTagAfterCallback1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/// <reference path='fourslash.ts' />
// @Filename: foo.js
// @allowJs: true
// @checkJs: true
//// /** @callback Listener @yeturn {ListenerBlock} */
//// /**
//// * The function used
//// * /*1*/ settings
//// */
//// class /*2*/ListenerBlock {
//// }

// Force a syntax tree to be created.
verify.noMatchingBracePositionInCurrentFile(0);

goTo.marker('1');
edit.insert('fenster');

verify.quickInfoAt('2', 'class ListenerBlock', 'The function used\nfenster settings')
19 changes: 19 additions & 0 deletions tests/cases/fourslash/jsTagAfterCallback2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/// <reference path='fourslash.ts' />
// @Filename: foo.js
// @allowJs: true
// @checkJs: true
//// /** @callback Listener @param x @yeturn {ListenerBlock} */
//// /**
//// * The function used
//// * /*1*/ settings
//// */
//// class /*2*/ListenerBlock {
//// }

// Force a syntax tree to be created.
verify.noMatchingBracePositionInCurrentFile(0);

goTo.marker('1');
edit.insert('fenster');

verify.quickInfoAt('2', 'class ListenerBlock', 'The function used\nfenster settings')
19 changes: 19 additions & 0 deletions tests/cases/fourslash/jsTagAfterTypedef1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/// <reference path='fourslash.ts' />
// @Filename: foo.js
// @allowJs: true
// @checkJs: true
//// /** @typedef Lister @property p @yeturn {ListenerBlock} */
//// /**
//// * The function used
//// * /*1*/ settings
//// */
//// class /*2*/ListenerBlock {
//// }

// Force a syntax tree to be created.
verify.noMatchingBracePositionInCurrentFile(0);

goTo.marker('1');
edit.insert('fenster');

verify.quickInfoAt('2', 'class ListenerBlock', 'The function used\nfenster settings')

0 comments on commit 2a78b22

Please sign in to comment.