Skip to content

Commit 2a78b22

Browse files
authored
Stop tag after @callback from crashing (microsoft#48860)
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.
1 parent bab02d2 commit 2a78b22

File tree

4 files changed

+59
-1
lines changed

4 files changed

+59
-1
lines changed

Diff for: src/compiler/parser.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -8579,7 +8579,8 @@ namespace ts {
85798579
if (!comment) {
85808580
comment = parseTrailingTagComments(start, getNodePos(), indent, indentText);
85818581
}
8582-
return finishNode(factory.createJSDocCallbackTag(tagName, typeExpression, fullName, comment), start);
8582+
const end = comment !== undefined ? getNodePos() : typeExpression.end;
8583+
return finishNode(factory.createJSDocCallbackTag(tagName, typeExpression, fullName, comment), start, end);
85838584
}
85848585

85858586
function escapedTextsEqual(a: EntityName, b: EntityName): boolean {

Diff for: tests/cases/fourslash/jsTagAfterCallback1.ts

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/// <reference path='fourslash.ts' />
2+
// @Filename: foo.js
3+
// @allowJs: true
4+
// @checkJs: true
5+
//// /** @callback Listener @yeturn {ListenerBlock} */
6+
//// /**
7+
//// * The function used
8+
//// * /*1*/ settings
9+
//// */
10+
//// class /*2*/ListenerBlock {
11+
//// }
12+
13+
// Force a syntax tree to be created.
14+
verify.noMatchingBracePositionInCurrentFile(0);
15+
16+
goTo.marker('1');
17+
edit.insert('fenster');
18+
19+
verify.quickInfoAt('2', 'class ListenerBlock', 'The function used\nfenster settings')

Diff for: tests/cases/fourslash/jsTagAfterCallback2.ts

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/// <reference path='fourslash.ts' />
2+
// @Filename: foo.js
3+
// @allowJs: true
4+
// @checkJs: true
5+
//// /** @callback Listener @param x @yeturn {ListenerBlock} */
6+
//// /**
7+
//// * The function used
8+
//// * /*1*/ settings
9+
//// */
10+
//// class /*2*/ListenerBlock {
11+
//// }
12+
13+
// Force a syntax tree to be created.
14+
verify.noMatchingBracePositionInCurrentFile(0);
15+
16+
goTo.marker('1');
17+
edit.insert('fenster');
18+
19+
verify.quickInfoAt('2', 'class ListenerBlock', 'The function used\nfenster settings')

Diff for: tests/cases/fourslash/jsTagAfterTypedef1.ts

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/// <reference path='fourslash.ts' />
2+
// @Filename: foo.js
3+
// @allowJs: true
4+
// @checkJs: true
5+
//// /** @typedef Lister @property p @yeturn {ListenerBlock} */
6+
//// /**
7+
//// * The function used
8+
//// * /*1*/ settings
9+
//// */
10+
//// class /*2*/ListenerBlock {
11+
//// }
12+
13+
// Force a syntax tree to be created.
14+
verify.noMatchingBracePositionInCurrentFile(0);
15+
16+
goTo.marker('1');
17+
edit.insert('fenster');
18+
19+
verify.quickInfoAt('2', 'class ListenerBlock', 'The function used\nfenster settings')

0 commit comments

Comments
 (0)