Skip to content

Commit 99f7ca6

Browse files
WIP: Return type
1 parent aca76a4 commit 99f7ca6

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { CancellationToken } from '@idl/cancellation-tokens';
2+
import { IParsed } from '@idl/parsing/syntax-tree';
3+
import {
4+
GLOBAL_TOKEN_TYPES,
5+
GlobalFunctionMethodToken,
6+
GlobalFunctionToken,
7+
IDLTypeHelper,
8+
IGlobalIndexedToken,
9+
} from '@idl/types/core';
10+
11+
import { IDLIndex } from '../../../idl-index.class';
12+
13+
/**
14+
* What global tokens do we try and get return types for
15+
*/
16+
const RETURN_TYPES_FOR: { [key: string]: undefined } = {};
17+
RETURN_TYPES_FOR[GLOBAL_TOKEN_TYPES.FUNCTION] = undefined;
18+
RETURN_TYPES_FOR[GLOBAL_TOKEN_TYPES.FUNCTION_METHOD] = undefined;
19+
20+
/**
21+
* Populates the return type for functions
22+
*/
23+
export function PopulateReturnType(
24+
index: IDLIndex,
25+
parsed: IParsed,
26+
cancel: CancellationToken
27+
) {
28+
/**
29+
* Find functions to process
30+
*/
31+
const functions = (
32+
parsed.global.filter(
33+
(global) =>
34+
global.type in RETURN_TYPES_FOR && !global.name.endsWith('::init')
35+
) as IGlobalIndexedToken<GlobalFunctionToken | GlobalFunctionMethodToken>[]
36+
).filter((global) => !IDLTypeHelper.isAnyType(global.meta.returns));
37+
38+
/**
39+
* Do nothing if we have no matches
40+
*/
41+
if (functions.length === 0) {
42+
return;
43+
}
44+
}

0 commit comments

Comments
 (0)