File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -232,6 +232,14 @@ export class JsdocParserUtil {
232232 result . push (
233233 ..._ . filter ( doc . tags , ( tag ) => tag . kind === kind ) ,
234234 ) ;
235+ } else if ( ( doc as any ) && ( doc as any ) . kind === kind ) {
236+ result . push ( doc as ts . JSDocTag ) ;
237+ } else if (
238+ ( doc as any ) &&
239+ typeof ( doc as any ) . kind === "number"
240+ ) {
241+ // Ignore other JSDoc node kinds to avoid hard crashes on TS AST variations.
242+ continue ;
235243 } else {
236244 throw new Error ( "Unexpected type" ) ;
237245 }
Original file line number Diff line number Diff line change @@ -312,6 +312,31 @@ const SECOND = 2;`);
312312 } ) ;
313313 } ) ;
314314
315+ describe ( 'getJSDocTags()' , ( ) => {
316+ it ( 'should support direct JSDocTag entries in cache without throwing' , ( ) => {
317+ const sourceFile = project . createSourceFile ( 'test.ts' , `class Test {
318+ /**
319+ * @deprecated This method has been replaced by AppStripeService:getPrice
320+ */
321+ test() {}
322+ }` ) ;
323+
324+ const method = sourceFile . getClass ( 'Test' ) ! . getMethod ( 'test' ) ! ;
325+ const deprecatedTag = ( method . compilerNode as any ) . jsDoc [ 0 ] . tags [ 0 ] ;
326+ const utilWithMockedCache = jsdocParserUtil as any ;
327+
328+ utilWithMockedCache . getJSDocs = ( ) => [ deprecatedTag ] ;
329+
330+ const result = utilWithMockedCache . getJSDocTags (
331+ method . compilerNode ,
332+ SyntaxKind . JSDocDeprecatedTag
333+ ) ;
334+
335+ expect ( result ) . to . have . length ( 1 ) ;
336+ expect ( result [ 0 ] ) . to . equal ( deprecatedTag ) ;
337+ } ) ;
338+ } ) ;
339+
315340 describe ( 'parseJSDocNode()' , ( ) => {
316341 it ( 'should parse JSDoc node with string comment' , ( ) => {
317342 const sourceFile = project . createSourceFile ( 'test.ts' , '/** Simple comment */ function test() {}' ) ;
You can’t perform that action at this time.
0 commit comments