diff options
| author | Akshay Nair <phenax5@gmail.com> | 2023-01-07 00:53:23 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2023-01-07 00:53:23 +0530 |
| commit | 2a0815eeb378b0140ef2885514715fb00db7a11e (patch) | |
| tree | 6e1c2e2e86269bae4a36f8ffac32d58ca5c6507c /src | |
| parent | d5d685253568f8c6855dd873ac3623e0af642d54 (diff) | |
| download | ts-types-lang-2a0815eeb378b0140ef2885514715fb00db7a11e.tar.gz ts-types-lang-2a0815eeb378b0140ef2885514715fb00db7a11e.zip | |
refactor: moves stdlib around + package stuff
Diffstat (limited to 'src')
| -rw-r--r-- | src/index.ts (renamed from src/runtime.ts) | 15 | ||||
| -rw-r--r-- | src/stdlib/fs.ts | 6 | ||||
| -rw-r--r-- | src/stdlib/index.ts | 4 | ||||
| -rw-r--r-- | src/stdlib/io.ts | 15 | ||||
| -rw-r--r-- | src/stdlib/stdio.ts | 12 | ||||
| -rw-r--r-- | src/stdlib/sys.ts | 8 |
6 files changed, 10 insertions, 50 deletions
diff --git a/src/runtime.ts b/src/index.ts index 0a65bf3..34038bf 100644 --- a/src/runtime.ts +++ b/src/index.ts @@ -1,4 +1,4 @@ -import { Project, ScriptTarget, Type, Node, StringLiteral, TypeFormatFlags, SyntaxKind } from 'ts-morph' +import { Project, ScriptTarget, Type, Node, SyntaxKind } from 'ts-morph' import path from 'path' import { promises as fs } from 'fs' import readline from 'readline'; @@ -25,6 +25,10 @@ const typeChecker = project.getTypeChecker() const [filePath] = process.argv.slice(2) +if (!filePath) { + throw new Error('Must specify runtime file') +} + const sourceFile = project.addSourceFileAtPath(path.resolve(filePath)) const entryPoint = sourceFile.getExportedDeclarations().get('main')?.[0] @@ -39,7 +43,7 @@ const RESULT_TYPE_NAME = '__$result' const [resultTypeNode] = sourceFile.addStatements(`type ${RESULT_TYPE_NAME} = {}`) const addResult = (name: string, ty: string): Node | undefined => { - if (resultTypeNode.isKind(SyntaxKind.TypeAliasDeclaration)) { + if (resultTypeNode?.isKind(SyntaxKind.TypeAliasDeclaration)) { const value = resultTypeNode.getChildAtIndex(3) if (value.isKind(SyntaxKind.TypeLiteral)) { return value.addProperty({ @@ -48,6 +52,7 @@ const addResult = (name: string, ty: string): Node | undefined => { }) } } + return } const customEffects: Record<string, (...args: Type[]) => any> = {} @@ -59,8 +64,8 @@ const evaluateType = async (effTyp: Type, node: Node): Promise<string[]> => { return match(name, { DefineEffect: async () => { const [nameTyp, exprTyp] = effTyp.getTypeArguments() - const name = nameTyp.getLiteralValue() as string - const exprStr = exprTyp.getLiteralValue() as string + const name = nameTyp?.getLiteralValue() as string + const exprStr = exprTyp?.getLiteralValue() as string const func = eval(exprStr) Object.assign(customEffects, { [name]: func }) @@ -169,7 +174,7 @@ const evaluateType = async (effTyp: Type, node: Node): Promise<string[]> => { _: async () => { if (name && customEffects[name]) { - const out = await customEffects[name](...effTyp.getTypeArguments()) + const out = await customEffects[name]?.(...effTyp.getTypeArguments()) if (out) { const hash = uuid() addResult(hash, `${JSON.stringify(out)}`) diff --git a/src/stdlib/fs.ts b/src/stdlib/fs.ts deleted file mode 100644 index 1374da5..0000000 --- a/src/stdlib/fs.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { Effect } from './io' - -export interface WriteFile<_Path extends string, _Content extends string> extends Effect { } - -export interface ReadFile<_Path extends string> extends Effect<string> { } - diff --git a/src/stdlib/index.ts b/src/stdlib/index.ts deleted file mode 100644 index 45197d9..0000000 --- a/src/stdlib/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -export * from './io' -export * from './fs' -export * from './stdio' -export * from './sys' diff --git a/src/stdlib/io.ts b/src/stdlib/io.ts deleted file mode 100644 index c78204f..0000000 --- a/src/stdlib/io.ts +++ /dev/null @@ -1,15 +0,0 @@ -export interface Effect<T = unknown> { output: T } - -export interface Kind1<Inp = unknown, Out = unknown> { - input: Inp - return: Out -} - -export interface Bind<_Eff extends Effect, _Fn extends Kind1> extends Effect { } - -export interface Seq<_Effs extends Effect[]> extends Effect { } - -export interface Do<_Effs extends Effect[]> extends Effect { } - -export interface DefineEffect<_Name extends string, _Func extends string> extends Effect { } - diff --git a/src/stdlib/stdio.ts b/src/stdlib/stdio.ts deleted file mode 100644 index 365aead..0000000 --- a/src/stdlib/stdio.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { Effect } from './io' - -export interface PutString<_ extends string> extends Effect { } - -export interface Print<_ extends any> extends Effect { } - -export interface Debug<_ extends string, T> extends Effect<T> { } - -export interface ReadLine extends Effect<string> { } - -export type PutStringLn<S extends string> = PutString<`${S}\n`> - diff --git a/src/stdlib/sys.ts b/src/stdlib/sys.ts deleted file mode 100644 index 03541be..0000000 --- a/src/stdlib/sys.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { Effect } from './io' - -export interface GetEnv<_Name extends string> extends Effect<string> { } - -export interface GetArgs extends Effect<string[]> { } - -export interface JsExpr<_Expr extends string> extends Effect<any> { } - |
