-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathParserState.ts
More file actions
35 lines (32 loc) · 1001 Bytes
/
Copy pathParserState.ts
File metadata and controls
35 lines (32 loc) · 1001 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import ts from "typescript";
import { Ts2PyConfig } from "./config";
export type ParserState = {
statements: string[];
typechecker: ts.TypeChecker;
knownTypes: Map<ts.Type | string, string>;
helperTypeNames: Map<string, ts.Type>;
canonicalTypeNames: Map<ts.Type, string>;
imports: Set<string>;
config: Ts2PyConfig;
};
export const createNewParserState = (
typechecker: ts.TypeChecker,
config: Ts2PyConfig,
): ParserState => {
const knownTypes = new Map<ts.Type, string>();
knownTypes.set(typechecker.getVoidType(), "None");
knownTypes.set(typechecker.getNullType(), "None");
knownTypes.set(typechecker.getUndefinedType(), "None");
knownTypes.set(typechecker.getStringType(), "str");
knownTypes.set(typechecker.getBooleanType(), "bool");
knownTypes.set(typechecker.getNumberType(), "float");
return {
statements: [],
typechecker,
knownTypes,
imports: new Set(),
helperTypeNames: new Map(),
canonicalTypeNames: new Map(),
config,
};
};