1
1
import { z } from "zod" ;
2
2
3
+ // eslint-disable-next-line func-names, @typescript-eslint/no-empty-function
4
+ export const AsyncFunction = async function ( ) { } . constructor as ( ...args : any [ ] ) => Promise < any > ;
5
+
6
+ // eslint-disable-next-line func-names, @typescript-eslint/no-empty-function
7
+ export const AsyncGeneratorFunction = async function * ( ) { } . constructor as AsyncGeneratorFunction ;
8
+
9
+ // eslint-disable-next-line func-names, @typescript-eslint/no-empty-function
10
+ export const GeneratorFunction = function * ( ) { } . constructor as GeneratorFunction ;
11
+
3
12
/* prettier-ignore */
4
13
/** @see {@link CONTROL_ABSTRACTION_BUILT_IN_OBJECTS } */
5
14
export const CONTROL_ABSTRACTION_BUILT_IN_OBJECTS_NAMES = [
15
+ "AsyncFunction" ,
16
+ "AsyncGeneratorFunction" ,
17
+ "GeneratorFunction" ,
6
18
"Promise" ,
7
19
// NOTE: Those are not defined.
8
- // "GeneratorFunction",
9
- // "AsyncGeneratorFunction",
10
- // "Generator",
11
20
// "AsyncGenerator",
12
- // "AsyncFunction ",
21
+ // "Generator ",
13
22
] as const ;
14
23
15
24
/** @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects#control_abstractions_objects } */
16
25
export const CONTROL_ABSTRACTION_BUILT_IN_OBJECTS = {
26
+ AsyncFunction : AsyncFunction ,
27
+ AsyncGeneratorFunction : AsyncGeneratorFunction ,
28
+ GeneratorFunction : GeneratorFunction ,
17
29
Promise : Promise ,
18
30
// NOTE: Those are not defined, unlike what MDN says
19
- // GeneratorFunction: GeneratorFunction,
20
- // AsyncGeneratorFunction: AsyncGeneratorFunction,
21
- // Generator: Generator,
22
31
// AsyncGenerator: AsyncGenerator,
23
- // AsyncFunction: AsyncFunction ,
32
+ // Generator: Generator ,
24
33
} as const ;
25
34
26
35
export type ControlAbstractionBuiltInObjectName = keyof typeof CONTROL_ABSTRACTION_BUILT_IN_OBJECTS ;
@@ -30,11 +39,11 @@ export type ControlAbstractionBuiltInObject =
30
39
export const CONTROL_ABSTRACTION_BUILT_IN_OBJECT_NAME_SCHEMA = z . enum ( CONTROL_ABSTRACTION_BUILT_IN_OBJECTS_NAMES ) ;
31
40
32
41
export const CONTROL_ABSTRACTION_BUILT_IN_OBJECTS_SCHEMAS = {
33
- Promise : z . instanceof ( Promise ) ,
42
+ AsyncFunction : z . function ( ) . returns ( z . promise ( z . any ( ) ) ) ,
43
+ AsyncGeneratorFunction : z . instanceof ( AsyncGeneratorFunction ) ,
44
+ GeneratorFunction : z . instanceof ( GeneratorFunction ) ,
45
+ Promise : z . promise ( z . any ( ) ) ,
34
46
// NOTE: Those are not defined, unlike what MDN says
35
- // GeneratorFunction: z.instanceof(GeneratorFunction),
36
- // AsyncGeneratorFunction: z.instanceof(AsyncGeneratorFunction),
37
- // Generator: z.instanceof(Generator),
38
47
// AsyncGenerator: z.instanceof(AsyncGenerator),
39
- // AsyncFunction : z.instanceof(AsyncFunction ),
48
+ // Generator : z.instanceof(Generator ),
40
49
} as const ;
0 commit comments