@@ -11,20 +11,21 @@ import type { CollectedMetadata, SlangAstNode } from '../types.d.ts';
1111
1212type Constructor < T = StrictAstNode > = new ( ...args : any ) => T ;
1313type ConstructorsFromInstances < U > = U extends any ? Constructor < U > : never ;
14- type TypeofFromInstances < U > = U extends any
14+ type GenericFunction < U > = U extends any
1515 ? { prototype : unknown ; name : string }
1616 : never ;
17+ type SlangPolymorphicNode = Extract < SlangAstNode , { variant : unknown } > ;
1718
1819export function createNonterminalVariantCreator <
1920 T extends StrictPolymorphicNode ,
20- U extends Extract < SlangAstNode , { variant : unknown } >
21+ U extends SlangPolymorphicNode
2122> (
2223 constructors : [
23- TypeofFromInstances < U > ,
24+ GenericFunction < U [ 'variant' ] > ,
2425 ConstructorsFromInstances < T [ 'variant' ] >
2526 ] [ ] ,
2627 constructorsWithVariants ?: [
27- TypeofFromInstances < Extract < SlangAstNode , { variant : unknown } > > ,
28+ GenericFunction < SlangPolymorphicNode > ,
2829 ConstructorsFromInstances < StrictPolymorphicNode >
2930 ] [ ]
3031) {
@@ -47,7 +48,7 @@ export function createNonterminalVariantCreator<
4748 const variantWithVariantsConstructors = new Map ( constructorsWithVariants ) ;
4849
4950 return (
50- variant : U [ 'variant' ] | StrictPolymorphicNode ,
51+ variant : U [ 'variant' ] | SlangPolymorphicNode ,
5152 collected : CollectedMetadata ,
5253 options ?: ParserOptions < AstNode >
5354 ) : T [ 'variant' ] => {
0 commit comments