aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2023-01-08 23:07:41 +0530
committerAkshay Nair <phenax5@gmail.com>2023-01-08 23:07:41 +0530
commit580ef150778326262d04018460f672bda53d5696 (patch)
tree53b93a2e381e6c15ed4e959f766fc88afc234a0f /src
parenta41d70afe7692e4ef344bc3c599115009f2dad15 (diff)
downloadts-types-lang-580ef150778326262d04018460f672bda53d5696.tar.gz
ts-types-lang-580ef150778326262d04018460f672bda53d5696.zip
chore: adds prettier
Diffstat (limited to 'src')
-rw-r--r--src/context.ts12
-rw-r--r--src/eval.ts59
-rw-r--r--src/index.ts11
-rw-r--r--src/types.ts9
-rw-r--r--src/util.ts8
5 files changed, 65 insertions, 34 deletions
diff --git a/src/context.ts b/src/context.ts
index 35fa1ae..7759215 100644
--- a/src/context.ts
+++ b/src/context.ts
@@ -1,7 +1,7 @@
import { Project, ScriptTarget, Type, Node, SyntaxKind } from 'ts-morph'
import path from 'path'
-import { v4 as uuid } from 'uuid';
-import { Ctx } from './types';
+import { v4 as uuid } from 'uuid'
+import { Ctx } from './types'
const RESULT_TYPE_NAME = '__$result'
@@ -31,9 +31,12 @@ export const createContext = (): Ctx => {
const typeToString = (ty: Type | undefined): string =>
ty ? typeChecker.compilerObject.typeToString(ty.compilerType) : ''
- const [resultTypeNode] = sourceFile.addStatements(`type ${RESULT_TYPE_NAME} = {}`)
+ const [resultTypeNode] = sourceFile.addStatements(
+ `type ${RESULT_TYPE_NAME} = {}`
+ )
- const getResultExpr = (resultKey?: string) => `${RESULT_TYPE_NAME}[${JSON.stringify(resultKey)}`
+ const getResultExpr = (resultKey?: string) =>
+ `${RESULT_TYPE_NAME}[${JSON.stringify(resultKey)}`
const addResult = (name: string, ty: string): Node | undefined =>
resultTypeNode
@@ -77,4 +80,3 @@ export const createContext = (): Ctx => {
hasCustomEffect: (name) => customEffects[name] !== undefined,
}
}
-
diff --git a/src/eval.ts b/src/eval.ts
index 4ba7033..9829194 100644
--- a/src/eval.ts
+++ b/src/eval.ts
@@ -1,20 +1,23 @@
import { Type } from 'ts-morph'
import { promises as fs } from 'fs'
-import readline from 'readline';
+import readline from 'readline'
-import { match } from './util';
-import { Ctx } from './types';
+import { match } from './util'
+import { Ctx } from './types'
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
- terminal: false
-});
+ terminal: false,
+})
-const readLineFromStdin = (): Promise<string> => new Promise((res) =>
- rl.on('line', res))
+const readLineFromStdin = (): Promise<string> =>
+ new Promise((res) => rl.on('line', res))
-export const evaluateType = async (ctx: Ctx, effTyp: Type): Promise<string[]> => {
+export const evaluateType = async (
+ ctx: Ctx,
+ effTyp: Type
+): Promise<string[]> => {
const name = effTyp.getSymbol()?.getName()
return match(name, {
@@ -28,15 +31,17 @@ export const evaluateType = async (ctx: Ctx, effTyp: Type): Promise<string[]> =>
},
Print: async () => {
- console.log(...effTyp.getTypeArguments().map(ctx.typeToString));
+ console.log(...effTyp.getTypeArguments().map(ctx.typeToString))
return []
},
PutString: async () => {
const [strinTyp] = effTyp.getTypeArguments()
const typString = ctx.typeToString(strinTyp)
- const string = JSON.parse(!typString.startsWith('"') ? `"${typString}"` : typString)
- process.stdout.write(string);
+ const string = JSON.parse(
+ !typString.startsWith('"') ? `"${typString}"` : typString
+ )
+ process.stdout.write(string)
return []
},
@@ -70,9 +75,15 @@ export const evaluateType = async (ctx: Ctx, effTyp: Type): Promise<string[]> =>
const [resultKey] = inputTyp ? await evaluateType(ctx, inputTyp) : []
const [_, compNode] = ctx.createResult(
- `(${ctx.typeToString(chainToKind)} & { input: (${ctx.getResultExpr(resultKey)})['output'] })['return']`)
+ `(${ctx.typeToString(chainToKind)} & { input: (${ctx.getResultExpr(
+ resultKey
+ )})['output'] })['return']`
+ )
// TODO: Avoid using getTypeAtLocation?
- const compTyp = compNode?.getType().getProperty('output')?.getTypeAtLocation(ctx.entryPoint)
+ const compTyp = compNode
+ ?.getType()
+ .getProperty('output')
+ ?.getTypeAtLocation(ctx.entryPoint)
return compTyp ? await evaluateType(ctx, compTyp) : []
},
@@ -80,12 +91,16 @@ export const evaluateType = async (ctx: Ctx, effTyp: Type): Promise<string[]> =>
GetEnv: async () => {
const [envTyp] = effTyp.getTypeArguments()
const envName = JSON.parse(ctx.typeToString(envTyp))
- const [resultKey, _] = ctx.createResult(`${JSON.stringify(process.env[envName] ?? '')}`)
+ const [resultKey, _] = ctx.createResult(
+ `${JSON.stringify(process.env[envName] ?? '')}`
+ )
return [resultKey]
},
GetArgs: async () => {
- const [resultKey, _] = ctx.createResult(`${JSON.stringify(process.argv.slice(2))}`)
+ const [resultKey, _] = ctx.createResult(
+ `${JSON.stringify(process.argv.slice(2))}`
+ )
return [resultKey]
},
@@ -105,7 +120,10 @@ export const evaluateType = async (ctx: Ctx, effTyp: Type): Promise<string[]> =>
Seq: async () => {
const [effectTyps] = effTyp.getTypeArguments()
- const effectResults = await evalList(ctx, effectTyps?.getTupleElements() ?? [])
+ const effectResults = await evalList(
+ ctx,
+ effectTyps?.getTupleElements() ?? []
+ )
const [resultKey, _] = ctx.createResult(`[
${effectResults.map(ctx.getResultExpr).join(', ')}
]`)
@@ -114,9 +132,14 @@ export const evaluateType = async (ctx: Ctx, effTyp: Type): Promise<string[]> =>
Do: async () => {
const [effectTyps] = effTyp.getTypeArguments()
- const effectResults = await evalList(ctx, effectTyps?.getTupleElements() ?? [])
+ const effectResults = await evalList(
+ ctx,
+ effectTyps?.getTupleElements() ?? []
+ )
const lastResKey = effectResults[effectResults.length - 1]
- const [resultKey, _] = ctx.createResult(`${ctx.getResultExpr(lastResKey)}['output']`)
+ const [resultKey, _] = ctx.createResult(
+ `${ctx.getResultExpr(lastResKey)}['output']`
+ )
return [resultKey]
},
diff --git a/src/index.ts b/src/index.ts
index 2fa1f96..65349fc 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -1,14 +1,15 @@
-import { createContext } from './context';
-import { evalList } from './eval';
+import { createContext } from './context'
+import { evalList } from './eval'
const main = async () => {
const ctx = createContext()
const resultType = ctx.entryPoint.getType()
- const effects = resultType.isTuple() ? resultType.getTupleElements() : [resultType]
+ const effects = resultType.isTuple()
+ ? resultType.getTupleElements()
+ : [resultType]
await evalList(ctx, effects)
}
main()
.then(() => process.exit(0))
- .catch(e => (console.error(e), process.exit(1)))
-
+ .catch((e) => (console.error(e), process.exit(1)))
diff --git a/src/types.ts b/src/types.ts
index a3cf3bb..3ffd416 100644
--- a/src/types.ts
+++ b/src/types.ts
@@ -1,4 +1,10 @@
-import { ExportedDeclarations, Node, SourceFile, Type, TypeChecker } from "ts-morph"
+import {
+ ExportedDeclarations,
+ Node,
+ SourceFile,
+ Type,
+ TypeChecker,
+} from 'ts-morph'
export interface Ctx {
sourceFile: SourceFile
@@ -14,4 +20,3 @@ export interface Ctx {
runCustomEffect: (name: string, args: Type[]) => Promise<string[]>
hasCustomEffect: (name: string) => boolean
}
-
diff --git a/src/util.ts b/src/util.ts
index 0b60bb1..136815e 100644
--- a/src/util.ts
+++ b/src/util.ts
@@ -1,4 +1,4 @@
-
-export const match = <K extends string, R>(k: K | undefined, pattern: { [key in K | '_']: () => R }) =>
- k && pattern[k] ? pattern[k]() : pattern._()
-
+export const match = <K extends string, R>(
+ k: K | undefined,
+ pattern: { [key in K | '_']: () => R }
+) => (k && pattern[k] ? pattern[k]() : pattern._())