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 '')
| -rw-r--r-- | src/index.ts (renamed from src/runtime.ts) | 15 | ||||
| -rw-r--r-- | stdlib/fs.ts (renamed from src/stdlib/fs.ts) | 0 | ||||
| -rw-r--r-- | stdlib/index.ts (renamed from src/stdlib/index.ts) | 0 | ||||
| -rw-r--r-- | stdlib/io.ts (renamed from src/stdlib/io.ts) | 0 | ||||
| -rw-r--r-- | stdlib/stdio.ts (renamed from src/stdlib/stdio.ts) | 0 | ||||
| -rw-r--r-- | stdlib/sys.ts (renamed from src/stdlib/sys.ts) | 0 |
6 files changed, 10 insertions, 5 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/stdlib/fs.ts index 1374da5..1374da5 100644 --- a/src/stdlib/fs.ts +++ b/stdlib/fs.ts diff --git a/src/stdlib/index.ts b/stdlib/index.ts index 45197d9..45197d9 100644 --- a/src/stdlib/index.ts +++ b/stdlib/index.ts diff --git a/src/stdlib/io.ts b/stdlib/io.ts index c78204f..c78204f 100644 --- a/src/stdlib/io.ts +++ b/stdlib/io.ts diff --git a/src/stdlib/stdio.ts b/stdlib/stdio.ts index 365aead..365aead 100644 --- a/src/stdlib/stdio.ts +++ b/stdlib/stdio.ts diff --git a/src/stdlib/sys.ts b/stdlib/sys.ts index 03541be..03541be 100644 --- a/src/stdlib/sys.ts +++ b/stdlib/sys.ts |
