11const RuntimeOverloads = new Map < string , ( string | Replacement ) [ ] > ( ) ;
22const commentsReg = / \/ \* (?: [ ^ * ] | \* [ ^ / ] ) * \* \/ / gm;
33const replaceTokensReg =
4- / \b a b s t r a c t \s + ( \w + ) | M a r k o \. ( T e m p l a t e I n p u t (?: < [ ^ > ] + > ) ? | C o m p o n e n t ) / gm;
4+ / \b a b s t r a c t \s + ( \w + ) | M a r k o \. ( T e m p l a t e I n p u t (?: < [ ^ > ] + > ) ? | C o m p o n e n t ) | \b ( R e t u r n ) \b / gm;
55const overrideBlockReg =
66 / \/ \* [ * \s ] * @ m a r k o - o v e r l o a d - s t a r t [ * \s ] * \* \/ ( [ \s \S ] + ) \/ \* [ * \s ] * @ m a r k o - o v e r l o a d - e n d [ * \s ] * \* \/ / g;
77
88enum Replacement {
99 Generics ,
1010 Input ,
11+ Return ,
1112 Component ,
1213}
1314
1415export function getRuntimeOverrides (
1516 runtimeTypes : string ,
1617 generics : string ,
1718 applyGenerics : string ,
19+ returnType : string ,
1820) {
1921 let overloads = RuntimeOverloads . get ( runtimeTypes ) ;
2022
@@ -29,12 +31,14 @@ export function getRuntimeOverrides(
2931 content = content . replace ( commentsReg , "" ) ; // remove all comments within the overloads.
3032
3133 while ( ( replaceMatch = replaceTokensReg . exec ( content ) ) ) {
32- const [ , methodName , propertyName ] = replaceMatch ;
34+ const [ , methodName , propertyName , returnName ] = replaceMatch ;
3335 const curText = content . slice ( lastIndex , replaceMatch . index ) ;
3436 lastIndex = replaceTokensReg . lastIndex ;
3537
3638 if ( methodName ) {
3739 overloads . push ( curText + methodName , Replacement . Generics ) ;
40+ } else if ( returnName ) {
41+ overloads . push ( curText , Replacement . Return ) ;
3842 } else {
3943 overloads . push (
4044 curText ,
@@ -61,6 +65,9 @@ export function getRuntimeOverrides(
6165 case Replacement . Input :
6266 result += appliedInput ;
6367 break ;
68+ case Replacement . Return :
69+ result += returnType ;
70+ break ;
6471 case Replacement . Component :
6572 result += appliedComponent ;
6673 break ;
0 commit comments