aboutsummaryrefslogtreecommitdiff
path: root/src/context.ts
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2023-01-11 16:02:26 +0530
committerAkshay Nair <phenax5@gmail.com>2023-01-11 16:02:26 +0530
commit49d6379c3d40b684b28f4a957ff1ffb81a2560ee (patch)
treefac62b2de1670ecfea6496949b028fa8fe0fe444 /src/context.ts
parenta6ff70d09e1e5f161e401a3665bfe44b2abfc44e (diff)
downloadts-types-lang-49d6379c3d40b684b28f4a957ff1ffb81a2560ee.tar.gz
ts-types-lang-49d6379c3d40b684b28f4a957ff1ffb81a2560ee.zip
refactor: minor refactor all around
Diffstat (limited to 'src/context.ts')
-rw-r--r--src/context.ts15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/context.ts b/src/context.ts
index 196c85d..14b5115 100644
--- a/src/context.ts
+++ b/src/context.ts
@@ -51,13 +51,20 @@ export const createContext = (options: CtxOptions): Ctx => {
return [resultKey, node]
}
- const customEffects: Record<string, (...args: Type[]) => any> = {}
+ const customEffects: Record<string, (args: Type[], ctx: Ctx) => any> = {}
- return {
+ const getTypeValue = (ty: Type | undefined): any => {
+ try {
+ return JSON.parse(typeToString(ty))
+ } catch(_) { return }
+ }
+
+ const ctx: Ctx = {
sourceFile,
typeChecker,
entryPoint,
typeToString,
+ getTypeValue,
createResult,
getResultExpr,
@@ -68,7 +75,7 @@ export const createContext = (options: CtxOptions): Ctx => {
Object.assign(customEffects, { [name]: func })
},
runCustomEffect: async (name, args) => {
- const output = await customEffects[name]?.(...args)
+ const output = await customEffects[name]?.(args, ctx)
if (output) {
const [resultKey, _] = createResult(`${JSON.stringify(output)}`)
return [resultKey]
@@ -77,4 +84,6 @@ export const createContext = (options: CtxOptions): Ctx => {
},
hasCustomEffect: (name) => customEffects[name] !== undefined,
}
+
+ return ctx
}