@@ -348,19 +348,25 @@ export function getCustomDecorators(type: ts.Type, checker: ts.TypeChecker): Map
348348 return decMap ;
349349}
350350
351+ export function getCustomNodeDirectives ( node : ts . Node ) : Map < DecoratorKind , Decorator > {
352+ const directivesMap = new Map < DecoratorKind , Decorator > ( ) ;
353+
354+ ts . getJSDocTags ( node ) . forEach ( tag => {
355+ const tagName = tag . tagName . escapedText as string ;
356+ if ( Decorator . isValid ( tagName ) ) {
357+ const dec = new Decorator ( tagName , tag . comment ? tag . comment . split ( " " ) : [ ] ) ;
358+ directivesMap . set ( dec . kind , dec ) ;
359+ }
360+ } ) ;
361+
362+ return directivesMap ;
363+ }
364+
351365export function getCustomFileDirectives ( file : ts . SourceFile ) : Map < DecoratorKind , Decorator > {
352- const decMap = new Map < DecoratorKind , Decorator > ( ) ;
353366 if ( file . statements . length > 0 ) {
354- const tags = ts . getJSDocTags ( file . statements [ 0 ] ) ;
355- for ( const tag of tags ) {
356- const tagName = tag . tagName . escapedText as string ;
357- if ( Decorator . isValid ( tagName ) ) {
358- const dec = new Decorator ( tagName , tag . comment ? tag . comment . split ( " " ) : [ ] ) ;
359- decMap . set ( dec . kind , dec ) ;
360- }
361- }
367+ return getCustomNodeDirectives ( file . statements [ 0 ] ) ;
362368 }
363- return decMap ;
369+ return new Map ( ) ;
364370}
365371
366372export function getCustomSignatureDirectives (
@@ -607,8 +613,7 @@ export function hasNoSelfAncestor(declaration: ts.Declaration, checker: ts.TypeC
607613 if ( ts . isSourceFile ( scopeDeclaration ) ) {
608614 return getCustomFileDirectives ( scopeDeclaration ) . has ( DecoratorKind . NoSelfInFile ) ;
609615 }
610- const scopeType = checker . getTypeAtLocation ( scopeDeclaration ) ;
611- if ( scopeType && getCustomDecorators ( scopeType , checker ) . has ( DecoratorKind . NoSelf ) ) {
616+ if ( getCustomNodeDirectives ( scopeDeclaration ) . has ( DecoratorKind . NoSelf ) ) {
612617 return true ;
613618 }
614619 return hasNoSelfAncestor ( scopeDeclaration , checker ) ;
@@ -645,8 +650,7 @@ export function getDeclarationContextType(
645650 return ContextType . NonVoid ;
646651 }
647652
648- const scopeType = checker . getTypeAtLocation ( scopeDeclaration ) ;
649- if ( scopeType && getCustomDecorators ( scopeType , checker ) . has ( DecoratorKind . NoSelf ) ) {
653+ if ( getCustomNodeDirectives ( scopeDeclaration ) . has ( DecoratorKind . NoSelf ) ) {
650654 return ContextType . Void ;
651655 }
652656 return ContextType . NonVoid ;
0 commit comments