@@ -95,7 +95,7 @@ import {
9595 serializeEntityNameAsExpression ,
9696} from './reflection-ast.js' ;
9797import { SourceFile } from './ts-types.js' ;
98- import { MappedModifier , ReflectionOp , TypeNumberBrand } from '@deepkit/type-spec' ;
98+ import { MappedModifier , ReflectionOp , TypeIntrinsic , TypeNumberBrand } from '@deepkit/type-spec' ;
9999import { Resolver } from './resolver.js' ;
100100import { knownLibFilesForCompilerOptions } from '@typescript/vfs' ;
101101import { debug , debug2 } from './debug.js' ;
@@ -1992,6 +1992,34 @@ export class ReflectionTransformer implements CustomTransformer {
19921992 }
19931993 break ;
19941994 }
1995+ case SyntaxKind . IntrinsicKeyword : {
1996+ if ( node . parent ?. kind !== SyntaxKind . TypeAliasDeclaration ) {
1997+ program . pushOp ( ReflectionOp . never ) ;
1998+ break ;
1999+ }
2000+ const parent = node . parent as TypeAliasDeclaration ;
2001+ const T = parent . typeParameters ?. [ 0 ] ;
2002+ // All intrinsics require one type parameter
2003+ if ( ! T ) {
2004+ program . pushOp ( ReflectionOp . never ) ;
2005+ break ;
2006+ }
2007+ const name = getNameAsString ( parent . name ) ;
2008+ const mapping : Record < string , TypeIntrinsic > = {
2009+ 'Capitalize' : TypeIntrinsic . Capitalize ,
2010+ 'Uppercase' : TypeIntrinsic . Uppercase ,
2011+ 'Lowercase' : TypeIntrinsic . Lowercase ,
2012+ 'Uncapitalize' : TypeIntrinsic . Uncapitalize ,
2013+ } ;
2014+ const intrinsic = mapping [ name ] ;
2015+ if ( intrinsic === undefined ) {
2016+ program . pushOp ( ReflectionOp . never ) ;
2017+ break ;
2018+ }
2019+ this . extractPackStructOfTypeReference ( T . name , program ) ;
2020+ program . pushOp ( ReflectionOp . intrinsic , Number ( intrinsic ) ) ;
2021+ break ;
2022+ }
19952023 default : {
19962024 program . pushOp ( ReflectionOp . never ) ;
19972025 }
@@ -2147,15 +2175,21 @@ export class ReflectionTransformer implements CustomTransformer {
21472175 return res === 'never' ;
21482176 }
21492177
2150- protected extractPackStructOfTypeReference ( type : TypeReferenceNode | ExpressionWithTypeArguments , program : CompilerProgram ) : void {
2151- const typeName : EntityName | undefined = isTypeReferenceNode ( type ) ? type . typeName : ( isIdentifier ( type . expression ) ? type . expression : undefined ) ;
2178+ protected extractPackStructOfTypeReference ( type : Identifier | TypeReferenceNode | ExpressionWithTypeArguments , program : CompilerProgram ) : void {
2179+ const typeName : EntityName | undefined = isIdentifier ( type )
2180+ ? type
2181+ : isTypeReferenceNode ( type )
2182+ ? type . typeName
2183+ : ( isIdentifier ( type . expression ) ? type . expression : undefined ) ;
2184+ const typeArguments : readonly TypeNode [ ] | undefined = isTypeReferenceNode ( type ) || isExpressionWithTypeArguments ( type ) ? type . typeArguments : [ ] ;
2185+
21522186 if ( ! typeName ) {
21532187 program . pushOp ( ReflectionOp . any ) ;
21542188 return ;
21552189 }
21562190
2157- if ( isIdentifier ( typeName ) && getIdentifierName ( typeName ) === 'InlineRuntimeType' && type . typeArguments && type . typeArguments [ 0 ] && isTypeQueryNode ( type . typeArguments [ 0 ] ) ) {
2158- const expression = serializeEntityNameAsExpression ( this . f , type . typeArguments [ 0 ] . exprName ) ;
2191+ if ( isIdentifier ( typeName ) && getIdentifierName ( typeName ) === 'InlineRuntimeType' && typeArguments && typeArguments [ 0 ] && isTypeQueryNode ( typeArguments [ 0 ] ) ) {
2192+ const expression = serializeEntityNameAsExpression ( this . f , typeArguments [ 0 ] . exprName ) ;
21592193 program . pushOp ( ReflectionOp . arg , program . pushStack ( expression ) ) ;
21602194 return ;
21612195 }
@@ -2166,8 +2200,8 @@ export class ReflectionTransformer implements CustomTransformer {
21662200 program . pushOp ( op ) ;
21672201 } else if ( isIdentifier ( typeName ) && getIdentifierName ( typeName ) === 'Promise' ) {
21682202 //promise has always one sub type
2169- if ( type . typeArguments && type . typeArguments [ 0 ] ) {
2170- this . extractPackStructOfType ( type . typeArguments [ 0 ] , program ) ;
2203+ if ( typeArguments && typeArguments [ 0 ] ) {
2204+ this . extractPackStructOfType ( typeArguments [ 0 ] , program ) ;
21712205 } else {
21722206 program . pushOp ( ReflectionOp . any ) ;
21732207 }
@@ -2263,8 +2297,8 @@ export class ReflectionTransformer implements CustomTransformer {
22632297 //Set/Map are interface declarations
22642298 const name = getNameAsString ( typeName ) ;
22652299 if ( name === 'Array' ) {
2266- if ( type . typeArguments && type . typeArguments [ 0 ] ) {
2267- this . extractPackStructOfType ( type . typeArguments [ 0 ] , program ) ;
2300+ if ( typeArguments && typeArguments [ 0 ] ) {
2301+ this . extractPackStructOfType ( typeArguments [ 0 ] , program ) ;
22682302 } else {
22692303 program . pushOp ( ReflectionOp . any ) ;
22702304 }
@@ -2278,21 +2312,21 @@ export class ReflectionTransformer implements CustomTransformer {
22782312 program . popFrameImplicit ( ) ;
22792313 return ;
22802314 } else if ( name === 'Set' ) {
2281- if ( type . typeArguments && type . typeArguments [ 0 ] ) {
2282- this . extractPackStructOfType ( type . typeArguments [ 0 ] , program ) ;
2315+ if ( typeArguments && typeArguments [ 0 ] ) {
2316+ this . extractPackStructOfType ( typeArguments [ 0 ] , program ) ;
22832317 } else {
22842318 program . pushOp ( ReflectionOp . any ) ;
22852319 }
22862320 program . pushOp ( ReflectionOp . set ) ;
22872321 return ;
22882322 } else if ( name === 'Map' ) {
2289- if ( type . typeArguments && type . typeArguments [ 0 ] ) {
2290- this . extractPackStructOfType ( type . typeArguments [ 0 ] , program ) ;
2323+ if ( typeArguments && typeArguments [ 0 ] ) {
2324+ this . extractPackStructOfType ( typeArguments [ 0 ] , program ) ;
22912325 } else {
22922326 program . pushOp ( ReflectionOp . any ) ;
22932327 }
2294- if ( type . typeArguments && type . typeArguments [ 1 ] ) {
2295- this . extractPackStructOfType ( type . typeArguments [ 1 ] , program ) ;
2328+ if ( typeArguments && typeArguments [ 1 ] ) {
2329+ this . extractPackStructOfType ( typeArguments [ 1 ] , program ) ;
22962330 } else {
22972331 program . pushOp ( ReflectionOp . any ) ;
22982332 }
@@ -2386,20 +2420,20 @@ export class ReflectionTransformer implements CustomTransformer {
23862420 const index = program . pushStack (
23872421 program . forNode === declaration ? 0 : this . f . createArrowFunction ( undefined , undefined , [ ] , undefined , undefined , runtimeTypeName ) ,
23882422 ) ;
2389- if ( type . typeArguments ) {
2390- for ( const argument of type . typeArguments ) {
2423+ if ( typeArguments ) {
2424+ for ( const argument of typeArguments ) {
23912425 this . extractPackStructOfType ( argument , program ) ;
23922426 }
2393- program . pushOp ( ReflectionOp . inlineCall , index , type . typeArguments . length ) ;
2427+ program . pushOp ( ReflectionOp . inlineCall , index , typeArguments . length ) ;
23942428 } else {
23952429 program . pushOp ( ReflectionOp . inline , index ) ;
23962430 }
23972431
2398- // if (type. typeArguments) {
2399- // for (const argument of type. typeArguments) {
2432+ // if (typeArguments) {
2433+ // for (const argument of typeArguments) {
24002434 // this.extractPackStructOfType(argument, program);
24012435 // }
2402- // program.pushOp(ReflectionOp.inlineCall, index, type. typeArguments.length);
2436+ // program.pushOp(ReflectionOp.inlineCall, index, typeArguments.length);
24032437 // } else {
24042438 // program.pushOp(ReflectionOp.inline, index);
24052439 // }
@@ -2430,8 +2464,8 @@ export class ReflectionTransformer implements CustomTransformer {
24302464
24312465 if ( resolved . importDeclaration && isIdentifier ( typeName ) ) ensureImportIsEmitted ( resolved . importDeclaration , typeName ) ;
24322466 program . pushFrame ( ) ;
2433- if ( type . typeArguments ) {
2434- for ( const typeArgument of type . typeArguments ) {
2467+ if ( typeArguments ) {
2468+ for ( const typeArgument of typeArguments ) {
24352469 this . extractPackStructOfType ( typeArgument , program ) ;
24362470 }
24372471 }
@@ -2519,7 +2553,7 @@ export class ReflectionTransformer implements CustomTransformer {
25192553 * }
25202554 * ```
25212555 */
2522- protected needsToBeInferred ( declaration : TypeParameterDeclaration , type : TypeReferenceNode | ExpressionWithTypeArguments ) : boolean {
2556+ protected needsToBeInferred ( declaration : TypeParameterDeclaration , type : Identifier | TypeReferenceNode | ExpressionWithTypeArguments ) : boolean {
25232557 const declarationUser = this . getTypeUser ( declaration ) ;
25242558 const typeUser = this . getTypeUser ( type ) ;
25252559
@@ -2539,7 +2573,7 @@ export class ReflectionTransformer implements CustomTransformer {
25392573 program . pushOp ( ReflectionOp . typeName , program . findOrAddStackEntry ( typeName ) ) ;
25402574 }
25412575
2542- protected resolveTypeParameter ( declaration : TypeParameterDeclaration , type : TypeReferenceNode | ExpressionWithTypeArguments , program : CompilerProgram ) {
2576+ protected resolveTypeParameter ( declaration : TypeParameterDeclaration , type : Identifier | TypeReferenceNode | ExpressionWithTypeArguments , program : CompilerProgram ) {
25432577 //check if `type` was used in an expression. if so, we need to resolve it from runtime, otherwise we mark it as T
25442578 const isUsedInFunction = isFunctionLike ( declaration . parent ) ;
25452579 const resolveRuntimeTypeParameter = ( isUsedInFunction && program . isResolveFunctionParameters ( declaration . parent ) ) || ( this . needsToBeInferred ( declaration , type ) ) ;
0 commit comments