From 078534f7c849b6bbf002a41b1648c1b2b6429cf1 Mon Sep 17 00:00:00 2001 From: Ozzie Gooen Date: Wed, 20 Jul 2022 08:27:57 -0700 Subject: [PATCH] Fixed typescript build --- packages/squiggle-lang/src/js/index.ts | 151 ++++++++++-------- .../squiggle-lang/src/js/rescript_interop.ts | 3 +- 2 files changed, 82 insertions(+), 72 deletions(-) diff --git a/packages/squiggle-lang/src/js/index.ts b/packages/squiggle-lang/src/js/index.ts index 5e4cf2c1..acee005c 100644 --- a/packages/squiggle-lang/src/js/index.ts +++ b/packages/squiggle-lang/src/js/index.ts @@ -120,77 +120,86 @@ function createTsExport( x: expressionValue, environment: environment ): squiggleExpression { - switch (x.tag) { - case "EvArray": - // genType doesn't convert anything more than 2 layers down into {tag: x, value: x} - // format, leaving it as the raw values. This converts the raw values - // directly into typescript values. - // - // The casting here is because genType is about the types of the returned - // values, claiming they are fully recursive when that's not actually the - // case - return tag( - "array", - x.value.map( - (arrayItem): squiggleExpression => - convertRawToTypescript( - arrayItem as unknown as rescriptExport, - environment + switch (x) { + case "EvVoid": + return tag("void", ""); + default: { + switch (x.tag) { + case "EvArray": + // genType doesn't convert anything more than 2 layers down into {tag: x, value: x} + // format, leaving it as the raw values. This converts the raw values + // directly into typescript values. + // + // The casting here is because genType is about the types of the returned + // values, claiming they are fully recursive when that's not actually the + // case + return tag( + "array", + x.value.map( + (arrayItem): squiggleExpression => + convertRawToTypescript( + arrayItem as unknown as rescriptExport, + environment + ) ) - ) - ); - case "EvArrayString": - return tag("arraystring", x.value); - case "EvBool": - return tag("boolean", x.value); - case "EvCall": - return tag("call", x.value); - case "EvLambda": - return tag("lambda", x.value); - case "EvDistribution": - return tag("distribution", new Distribution(x.value, environment)); - case "EvNumber": - return tag("number", x.value); - case "EvRecord": - // genType doesn't support records, so we have to do the raw conversion ourself - let result: tagged<"record", { [key: string]: squiggleExpression }> = tag( - "record", - _.mapValues(x.value, (x: unknown) => - convertRawToTypescript(x as rescriptExport, environment) - ) - ); - return result; - case "EvString": - return tag("string", x.value); - case "EvSymbol": - return tag("symbol", x.value); - case "EvDate": - return tag("date", x.value); - case "EvTimeDuration": - return tag("timeDuration", x.value); - case "EvDeclaration": - return tag("lambdaDeclaration", x.value); - case "EvTypeIdentifier": - return tag("typeIdentifier", x.value); - case "EvType": - let typeResult: tagged<"type", { [key: string]: squiggleExpression }> = - tag( - "type", - _.mapValues(x.value, (x: unknown) => - convertRawToTypescript(x as rescriptExport, environment) - ) - ); - return typeResult; - case "EvModule": - let moduleResult: tagged< - "module", - { [key: string]: squiggleExpression } - > = tag( - "module", - _.mapValues(x.value, (x: unknown) => - convertRawToTypescript(x as rescriptExport, environment) - ) - ); - return moduleResult; + ); + case "EvArrayString": + return tag("arraystring", x.value); + case "EvBool": + return tag("boolean", x.value); + case "EvCall": + return tag("call", x.value); + case "EvLambda": + return tag("lambda", x.value); + case "EvDistribution": + return tag("distribution", new Distribution(x.value, environment)); + case "EvNumber": + return tag("number", x.value); + case "EvRecord": + // genType doesn't support records, so we have to do the raw conversion ourself + let result: tagged<"record", { [key: string]: squiggleExpression }> = + tag( + "record", + _.mapValues(x.value, (x: unknown) => + convertRawToTypescript(x as rescriptExport, environment) + ) + ); + return result; + case "EvString": + return tag("string", x.value); + case "EvSymbol": + return tag("symbol", x.value); + case "EvDate": + return tag("date", x.value); + case "EvTimeDuration": + return tag("timeDuration", x.value); + case "EvDeclaration": + return tag("lambdaDeclaration", x.value); + case "EvTypeIdentifier": + return tag("typeIdentifier", x.value); + case "EvType": + let typeResult: tagged< + "type", + { [key: string]: squiggleExpression } + > = tag( + "type", + _.mapValues(x.value, (x: unknown) => + convertRawToTypescript(x as rescriptExport, environment) + ) + ); + return typeResult; + case "EvModule": + let moduleResult: tagged< + "module", + { [key: string]: squiggleExpression } + > = tag( + "module", + _.mapValues(x.value, (x: unknown) => + convertRawToTypescript(x as rescriptExport, environment) + ) + ); + return moduleResult; + } + } } } diff --git a/packages/squiggle-lang/src/js/rescript_interop.ts b/packages/squiggle-lang/src/js/rescript_interop.ts index dcba24e6..80548a7f 100644 --- a/packages/squiggle-lang/src/js/rescript_interop.ts +++ b/packages/squiggle-lang/src/js/rescript_interop.ts @@ -131,7 +131,8 @@ export type squiggleExpression = | tagged<"record", { [key: string]: squiggleExpression }> | tagged<"type", { [key: string]: squiggleExpression }> | tagged<"typeIdentifier", string> - | tagged<"module", { [key: string]: squiggleExpression }>; + | tagged<"module", { [key: string]: squiggleExpression }> + | tagged<"void", string>; export { lambdaValue };