@@ -11,14 +11,7 @@ import ts from 'typescript';
1111import { Reference } from '../../imports' ;
1212import { OwningModule } from '../../imports/src/references' ;
1313import { DependencyTracker } from '../../incremental/api' ;
14- import {
15- Declaration ,
16- DeclarationNode ,
17- FunctionDefinition ,
18- ReflectionHost ,
19- reflectTypeEntityToDeclaration ,
20- } from '../../reflection' ;
21- import { TypeEntityToDeclarationError } from '../../reflection/src/typescript' ;
14+ import { Declaration , DeclarationNode , FunctionDefinition , ReflectionHost } from '../../reflection' ;
2215import { isDeclaration } from '../../util/src/typescript' ;
2316
2417import { ArrayConcatBuiltinFn , ArraySliceBuiltinFn , StringConcatBuiltinFn } from './builtin' ;
@@ -714,7 +707,7 @@ export class StaticInterpreter {
714707 return new Reference ( node , owningModule ( context ) ) ;
715708 }
716709
717- public visitType ( node : ts . TypeNode , context : Context ) : ResolvedValue {
710+ private visitType ( node : ts . TypeNode , context : Context ) : ResolvedValue {
718711 if ( ts . isLiteralTypeNode ( node ) ) {
719712 return this . visitExpression ( node . literal , context ) ;
720713 } else if ( ts . isTupleTypeNode ( node ) ) {
@@ -725,8 +718,6 @@ export class StaticInterpreter {
725718 return this . visitType ( node . type , context ) ;
726719 } else if ( ts . isTypeQueryNode ( node ) ) {
727720 return this . visitTypeQuery ( node , context ) ;
728- } else if ( ts . isTypeReferenceNode ( node ) ) {
729- return this . visitTypeReference ( node , context ) ;
730721 }
731722
732723 return DynamicValue . fromDynamicType ( node ) ;
@@ -743,74 +734,18 @@ export class StaticInterpreter {
743734 }
744735
745736 private visitTypeQuery ( node : ts . TypeQueryNode , context : Context ) : ResolvedValue {
746- try {
747- const result = reflectTypeEntityToDeclaration ( node . exprName , this . checker ) ;
748- const declNode = result . node ;
749- const from = result . from ;
750-
751- let declContext = context ;
752- if ( from !== null && ! from . startsWith ( '.' ) ) {
753- declContext = {
754- ...context ,
755- absoluteModuleName : from ,
756- resolutionContext : node . getSourceFile ( ) . fileName ,
757- } ;
758- }
759-
760- return this . visitDeclaration ( declNode , declContext ) ;
761- } catch ( e ) {
762- if ( e instanceof TypeEntityToDeclarationError ) {
763- return DynamicValue . fromUnknown ( node ) ;
764- }
765- throw e ;
766- }
767- }
768-
769- private visitTypeReference ( node : ts . TypeReferenceNode , context : Context ) : ResolvedValue {
770- const typeName = ts . isQualifiedName ( node . typeName ) ? node . typeName . right : node . typeName ;
771- if ( ! ts . isIdentifier ( typeName ) ) {
737+ const exprName = ts . isQualifiedName ( node . exprName ) ? node . exprName . right : node . exprName ;
738+ if ( ! ts . isIdentifier ( exprName ) ) {
772739 return DynamicValue . fromUnknown ( node ) ;
773740 }
774741
775- if (
776- typeName . text === 'ReturnType' &&
777- node . typeArguments !== undefined &&
778- node . typeArguments . length === 1
779- ) {
780- const typeArg = node . typeArguments [ 0 ] ;
781- const evaluatedTypeArg = this . visitType ( typeArg , context ) ;
782-
783- if ( evaluatedTypeArg instanceof Reference ) {
784- const decl = evaluatedTypeArg . node ;
785- if ( ts . isFunctionDeclaration ( decl ) || ts . isMethodDeclaration ( decl ) ) {
786- const rawType = decl . type ;
787- if ( rawType !== undefined ) {
788- if ( ts . isTypeReferenceNode ( rawType ) ) {
789- const mwpTypeName = ts . isQualifiedName ( rawType . typeName )
790- ? rawType . typeName . right
791- : rawType . typeName ;
792- if ( ts . isIdentifier ( mwpTypeName ) && mwpTypeName . text === 'ModuleWithProviders' ) {
793- if ( rawType . typeArguments !== undefined && rawType . typeArguments . length === 1 ) {
794- const arg = rawType . typeArguments [ 0 ] ;
795- return this . visitType ( arg , context ) ;
796- }
797- }
798- }
799- }
800- }
801- }
802- }
803-
804- // Handle general type reference to a class!
805- const decl = this . host . getDeclarationOfIdentifier ( typeName ) ;
806- if ( decl !== null && this . host . isClass ( decl . node ) ) {
807- return this . getReference ( decl . node , {
808- ...context ,
809- ...joinModuleContext ( context , typeName , decl ) ,
810- } ) ;
742+ const decl = this . host . getDeclarationOfIdentifier ( exprName ) ;
743+ if ( decl === null ) {
744+ return DynamicValue . fromUnknownIdentifier ( exprName ) ;
811745 }
812746
813- return DynamicValue . fromDynamicType ( node ) ;
747+ const declContext : Context = { ...context , ...joinModuleContext ( context , node , decl ) } ;
748+ return this . visitDeclaration ( decl . node , declContext ) ;
814749 }
815750}
816751
0 commit comments