diff options
| author | Akshay Nair <phenax5@gmail.com> | 2023-01-05 19:04:51 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2023-01-05 19:04:51 +0530 |
| commit | a32741ec698473e9575679c145806fb96dc7ccf5 (patch) | |
| tree | d6eb6c57093a95c90fc6cdced381fd534a585bda /src | |
| parent | 84d8c34ed6fc77848d250b18ea0a1757942681b6 (diff) | |
| download | ts-types-lang-a32741ec698473e9575679c145806fb96dc7ccf5.tar.gz ts-types-lang-a32741ec698473e9575679c145806fb96dc7ccf5.zip | |
fix: fixes js expr eval
Diffstat (limited to 'src')
| -rw-r--r-- | src/runtime.ts | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/runtime.ts b/src/runtime.ts index 11a7e61..8620add 100644 --- a/src/runtime.ts +++ b/src/runtime.ts @@ -39,11 +39,11 @@ const typeRefNode = entryPoint?.getLastChild() const RESULT_TYPE_NAME = '__$result' -const [statement] = sourceFile.addStatements(`type ${RESULT_TYPE_NAME} = {}`) +const [resultTypeNode] = sourceFile.addStatements(`type ${RESULT_TYPE_NAME} = {}`) const addResult = (name: string, ty: string) => { - if (statement.isKind(SyntaxKind.TypeAliasDeclaration)) { - const value = statement.getChildAtIndex(3) + if (resultTypeNode.isKind(SyntaxKind.TypeAliasDeclaration)) { + const value = resultTypeNode.getChildAtIndex(3) if (value.isKind(SyntaxKind.TypeLiteral)) { value.addProperty({ name: JSON.stringify(name), @@ -96,9 +96,9 @@ const accumulateResults = async (effTyp: Type, node: Node): Promise<string[]> => JsExpr: async () => { const [exprTyp] = effTyp.getTypeArguments() const exprStr = JSON.parse(typeToString(exprTyp)) - const result = eval(exprStr) + const result = eval(`JSON.stringify(${exprStr})`) const hash = createHash() - addResult(hash, `${JSON.stringify(result)}`) + addResult(hash, `${result}`) return [hash] }, @@ -121,7 +121,7 @@ const evalAccumulator = async (effNode: Node, node: Node) => { Debug: async () => { const [labelTyp, valueTyp] = effTyp.getTypeArguments() const label = JSON.parse(typeToString(labelTyp)) - const value = JSON.parse(typeToString(valueTyp)) + const value = typeToString(valueTyp) console.log(label, value) }, @@ -187,7 +187,7 @@ const main = async () => { main() .then(() => { // console.log(entryPoint?.print()) - // console.log(statement?.print()) + // console.log(resultTypeNode?.print()) process.exit(0) }) .catch(e => (console.error(e), process.exit(1))) |
