diff --git a/CHANGELOG_NEXT.md b/CHANGELOG_NEXT.md index 9b49d478..7bb2cd4b 100644 --- a/CHANGELOG_NEXT.md +++ b/CHANGELOG_NEXT.md @@ -26,3 +26,5 @@ - Release 7.0.2 with type check fix for recursive schema - Test GenType compatibility with d.ts - Clean up error tags +- Set 8.0.x for rescript-schema in ppx deps +- Update github ci to run on "v*.*.\*-patch" diff --git a/packages/tests/src/benchmark/Benchmark.bs.mjs b/packages/tests/src/benchmark/Benchmark.bs.mjs index d391e5b3..4c624412 100644 --- a/packages/tests/src/benchmark/Benchmark.bs.mjs +++ b/packages/tests/src/benchmark/Benchmark.bs.mjs @@ -1,6 +1,7 @@ // Generated by ReScript, PLEASE EDIT WITH CARE import * as Benchmark from "benchmark"; +import * as Core__Array from "@rescript/core/src/Core__Array.bs.mjs"; import * as S$RescriptSchema from "rescript-schema/src/S.bs.mjs"; function addWithPrepare(suite, name, fn) { @@ -74,47 +75,129 @@ S$RescriptSchema.setGlobalConfig({ disableNanNumberCheck: true }); +var schema = S$RescriptSchema.recursive(function (schema) { + return S$RescriptSchema.union([ + S$RescriptSchema.object(function (s) { + s.tag("type", "A"); + return { + TAG: "A", + _0: s.f("nested", S$RescriptSchema.array(schema)) + }; + }), + S$RescriptSchema.literal("B"), + S$RescriptSchema.literal("C"), + S$RescriptSchema.literal("D"), + S$RescriptSchema.literal("E"), + S$RescriptSchema.literal("F"), + S$RescriptSchema.literal("G"), + S$RescriptSchema.literal("H"), + S$RescriptSchema.literal("I"), + S$RescriptSchema.literal("J"), + S$RescriptSchema.literal("K"), + S$RescriptSchema.literal("L"), + S$RescriptSchema.literal("M"), + S$RescriptSchema.literal("N"), + S$RescriptSchema.literal("O"), + S$RescriptSchema.literal("P"), + S$RescriptSchema.literal("Q"), + S$RescriptSchema.literal("R"), + S$RescriptSchema.literal("S"), + S$RescriptSchema.literal("T"), + S$RescriptSchema.literal("U"), + S$RescriptSchema.literal("V"), + S$RescriptSchema.literal("W"), + S$RescriptSchema.literal("X"), + S$RescriptSchema.literal("Y"), + S$RescriptSchema.object(function (s) { + s.tag("type", "Z"); + return { + TAG: "Z", + _0: s.f("nested", S$RescriptSchema.array(schema)) + }; + }) + ]); + }); + +var testData1 = { + TAG: "Z", + _0: Core__Array.make(25, { + TAG: "Z", + _0: Core__Array.make(25, { + TAG: "Z", + _0: Core__Array.make(25, "Y") + }) + }) +}; + +var testData2 = { + TAG: "A", + _0: Core__Array.make(25, { + TAG: "A", + _0: Core__Array.make(25, { + TAG: "A", + _0: Core__Array.make(25, "B") + }) + }) +}; + +function test() { + console.time("testData1 serialize"); + var json = S$RescriptSchema.serializeOrRaiseWith(testData1, schema); + console.timeEnd("testData1 serialize"); + console.time("testData1 parse"); + S$RescriptSchema.parseOrRaiseWith(json, schema); + console.timeEnd("testData1 parse"); + console.time("testData2 serialize"); + var json$1 = S$RescriptSchema.serializeOrRaiseWith(testData2, schema); + console.timeEnd("testData2 serialize"); + console.time("testData2 parse"); + S$RescriptSchema.parseOrRaiseWith(json$1, schema); + console.timeEnd("testData2 parse"); +} + +test(); + var data = makeTestObject(); console.time("makeAdvancedObjectSchema"); -var schema = makeAdvancedObjectSchema(); +var schema$1 = makeAdvancedObjectSchema(); console.timeEnd("makeAdvancedObjectSchema"); console.time("parseAnyWith: 1"); -S$RescriptSchema.parseAnyWith(data, schema); +S$RescriptSchema.parseAnyWith(data, schema$1); console.timeEnd("parseAnyWith: 1"); console.time("parseAnyWith: 2"); -S$RescriptSchema.parseAnyWith(data, schema); +S$RescriptSchema.parseAnyWith(data, schema$1); console.timeEnd("parseAnyWith: 2"); console.time("parseAnyWith: 3"); -S$RescriptSchema.parseAnyWith(data, schema); +S$RescriptSchema.parseAnyWith(data, schema$1); console.timeEnd("parseAnyWith: 3"); console.time("serializeWith: 1"); -S$RescriptSchema.serializeWith(data, schema); +S$RescriptSchema.serializeWith(data, schema$1); console.timeEnd("serializeWith: 1"); console.time("serializeWith: 2"); -S$RescriptSchema.serializeWith(data, schema); +S$RescriptSchema.serializeWith(data, schema$1); console.timeEnd("serializeWith: 2"); console.time("serializeWith: 3"); -S$RescriptSchema.serializeWith(data, schema); +S$RescriptSchema.serializeWith(data, schema$1); console.timeEnd("serializeWith: 3"); diff --git a/packages/tests/src/benchmark/Benchmark.res b/packages/tests/src/benchmark/Benchmark.res index 4a8fe6f2..1735ae7e 100644 --- a/packages/tests/src/benchmark/Benchmark.res +++ b/packages/tests/src/benchmark/Benchmark.res @@ -103,6 +103,116 @@ S.setGlobalConfig({ disableNanNumberCheck: true, }) +// Reported in https://gist.github.com/cknitt/4ac6813a3f3bc907187105e01a4324ca +module CrazyUnion = { + type rec test = + | A(array) + | B + | C + | D + | E + | F + | G + | H + | I + | J + | K + | L + | M + | N + | O + | P + | Q + | R + | S + | T + | U + | V + | W + | X + | Y + | Z(array) + + let schema = S.recursive(schema => + S.union([ + S.object(s => { + s.tag("type", "A") + A(s.field("nested", S.array(schema))) + }), + S.literal(B), + S.literal(C), + S.literal(D), + S.literal(E), + S.literal(F), + S.literal(G), + S.literal(H), + S.literal(I), + S.literal(J), + S.literal(K), + S.literal(L), + S.literal(M), + S.literal(N), + S.literal(O), + S.literal(P), + S.literal(Q), + S.literal(R), + S.literal(S), + S.literal(T), + S.literal(U), + S.literal(V), + S.literal(W), + S.literal(X), + S.literal(Y), + S.object(s => { + s.tag("type", "Z") + Z(s.field("nested", S.array(schema))) + }), + ]) + ) + + let testData1 = Z(Array.make(~length=25, Z(Array.make(~length=25, Z(Array.make(~length=25, Y)))))) + + let testData2 = A(Array.make(~length=25, A(Array.make(~length=25, A(Array.make(~length=25, B)))))) + + let test = () => { + Console.time("testData1 serialize") + let json = S.serializeOrRaiseWith(testData1, schema) + Console.timeEnd("testData1 serialize") + + Console.time("testData1 parse") + let _ = S.parseOrRaiseWith(json, schema) + Console.timeEnd("testData1 parse") + + Console.time("testData2 serialize") + let json = S.serializeOrRaiseWith(testData2, schema) + Console.timeEnd("testData2 serialize") + + Console.time("testData2 parse") + let _ = S.parseOrRaiseWith(json, schema) + Console.timeEnd("testData2 parse") + + // Js.log((schema->Obj.magic)["parseOrThrow"]["toString"]()) + } +} + +// Full +// testData1 serialize: 5.414s +// testData1 parse: 5.519s +// testData2 serialize: 70.864ms +// testData2 parse: 70.967ms + +// Wip +// testData1 serialize: 5.398s +// testData1 parse: 6.171ms +// testData2 serialize: 69.621ms +// testData2 parse: 0.878ms + +// Partial +// testData1 serialize: 1.802ms +// testData1 parse: 1.411ms +// 734 Error.make +CrazyUnion.test() + let data = makeTestObject() Console.time("makeAdvancedObjectSchema") let schema = makeAdvancedObjectSchema() diff --git a/packages/tests/src/core/Example_test.res b/packages/tests/src/core/Example_test.res index 29ea5e5a..803e5f65 100644 --- a/packages/tests/src/core/Example_test.res +++ b/packages/tests/src/core/Example_test.res @@ -69,7 +69,7 @@ test("Compiled parse code snapshot", t => { t->U.assertCompiledCode( ~schema=filmSchema, ~op=#Parse, - `i=>{if(!i||i.constructor!==Object){e[11](i)}let v0=i["Id"],v1=i["Title"],v2=i["Tags"],v6=i["Rating"],v7,v8=i["Age"];if(typeof v0!=="number"||Number.isNaN(v0)){e[0](v0)}if(typeof v1!=="string"){e[1](v1)}if(v2!==void 0&&(!Array.isArray(v2))){e[2](v2)}if(v2!==void 0){for(let v3=0;v32147483647||v8<-2147483648||v8%1!==0)){e[10](v8)}return {"id":v0,"title":v1,"tags":v2===void 0?e[4]:v2,"rating":v7,"deprecatedAgeRestriction":v8,}}`, + `i=>{if(!i||i.constructor!==Object){e[11](i)}let v0=i["Id"],v1=i["Title"],v2=i["Tags"],v6=i["Rating"],v7,v8=i["Age"];if(typeof v0!=="number"||Number.isNaN(v0)){e[0](v0)}if(typeof v1!=="string"){e[1](v1)}if(v2!==void 0&&(!Array.isArray(v2))){e[2](v2)}if(v2!==void 0){for(let v3=0;v32147483647||v8<-2147483648||v8%1!==0)){e[10](v8)}return {"id":v0,"title":v1,"tags":v2===void 0?e[4]:v2,"rating":v7,"deprecatedAgeRestriction":v8,}}`, ) }) diff --git a/packages/tests/src/core/S_parseAnyAsyncInStepsWith_deprecatedTest.bs.mjs b/packages/tests/src/core/S_parseAnyAsyncInStepsWith_deprecatedTest.bs.mjs new file mode 100644 index 00000000..d856702b --- /dev/null +++ b/packages/tests/src/core/S_parseAnyAsyncInStepsWith_deprecatedTest.bs.mjs @@ -0,0 +1,2 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE +/* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */ diff --git a/packages/tests/src/core/S_union_test.res b/packages/tests/src/core/S_union_test.res index 3150d808..01e161ca 100644 --- a/packages/tests/src/core/S_union_test.res +++ b/packages/tests/src/core/S_union_test.res @@ -25,14 +25,26 @@ test("Successfully parses polymorphic variants", t => { t->Assert.deepEqual(%raw(`"apple"`)->S.parseAnyWith(schema), Ok(#apple), ()) }) -test("Parses when both schemas misses parser", t => { +test("Parses when both schemas misses parser and have the same type", t => { let schema = S.union([ - S.literal(#apple)->S.transform(_ => {serializer: _ => #apple}), + S.string->S.transform(_ => {serializer: _ => "apple"}), S.string->S.transform(_ => {serializer: _ => "apple"}), ]) t->U.assertErrorResult( %raw(`null`)->S.parseAnyWith(schema), + { + code: InvalidType({ + expected: schema->S.toUnknown, + received: %raw(`null`), + }), + operation: Parse, + path: S.Path.empty, + }, + ) + + t->U.assertErrorResult( + %raw(`"foo"`)->S.parseAnyWith(schema), { code: InvalidUnion([ U.error({ @@ -51,7 +63,45 @@ test("Parses when both schemas misses parser", t => { }, ) - t->U.assertCompiledCode(~schema, ~op=#Parse, `i=>{e[4]([e[1],e[3],]);return i}`) + t->U.assertCompiledCode( + ~schema, + ~op=#Parse, + `i=>{if(typeof i!=="string"){e[0](i)}else{e[5]([e[2],e[4],]);}return undefined}`, + ) +}) + +test("Parses when both schemas misses parser and have different types", t => { + let schema = S.union([ + S.literal(#apple)->S.transform(_ => {serializer: _ => #apple}), + S.string->S.transform(_ => {serializer: _ => "apple"}), + ]) + + t->U.assertErrorResult( + %raw(`null`)->S.parseAnyWith(schema), + { + code: InvalidType({ + expected: schema->S.toUnknown, + received: %raw(`null`), + }), + operation: Parse, + path: S.Path.empty, + }, + ) + + t->U.assertErrorResult( + %raw(`"abc"`)->S.parseAnyWith(schema), + { + code: InvalidOperation({description: "The S.transform parser is missing"}), + operation: Parse, + path: S.Path.empty, + }, + ) + + t->U.assertCompiledCode( + ~schema, + ~op=#Parse, + `i=>{if(!(i==="apple")){if(typeof i!=="string"){e[0](i)}else{throw e[1]}}else{throw e[3]}return undefined}`, + ) }) test("Serializes when both schemas misses serializer", t => { @@ -91,7 +141,7 @@ test("Parses when second struct misses parser", t => { t->U.assertCompiledCode( ~schema, ~op=#Parse, - `i=>{let v0;try{i==="apple"||e[0](i);v0=i}catch(e0){e[3]([e0,e[2],])}return v0}`, + `i=>{let v0;if(!(i==="apple")){if(typeof i!=="string"){e[0](i)}else{throw e[1]}}else{v0=i}return v0}`, ) }) @@ -258,32 +308,10 @@ module Advanced = { t->U.assertErrorResult( %raw(`"Hello world!"`)->S.parseAnyWith(shapeSchema), { - code: InvalidUnion([ - U.error({ - code: InvalidType({ - expected: circleSchema->S.toUnknown, - received: %raw(`"Hello world!"`), - }), - operation: Parse, - path: S.Path.empty, - }), - U.error({ - code: InvalidType({ - expected: squareSchema->S.toUnknown, - received: %raw(`"Hello world!"`), - }), - operation: Parse, - path: S.Path.empty, - }), - U.error({ - code: InvalidType({ - expected: triangleSchema->S.toUnknown, - received: %raw(`"Hello world!"`), - }), - operation: Parse, - path: S.Path.empty, - }), - ]), + code: InvalidType({ + expected: shapeSchema->S.toUnknown, + received: %raw(`"Hello world!"`), + }), operation: Parse, path: S.Path.empty, }, @@ -377,7 +405,7 @@ module Advanced = { t->U.assertCompiledCode( ~schema=shapeSchema, ~op=#Parse, - `i=>{let v2;try{if(!i||i.constructor!==Object){e[0](i)}let v0=i["kind"],v1=i["radius"];v0==="circle"||e[1](v0);if(typeof v1!=="number"||Number.isNaN(v1)){e[2](v1)}v2={"TAG":e[3],"radius":v1,}}catch(e0){try{if(!i||i.constructor!==Object){e[4](i)}let v3=i["kind"],v4=i["x"];v3==="square"||e[5](v3);if(typeof v4!=="number"||Number.isNaN(v4)){e[6](v4)}v2={"TAG":e[7],"x":v4,}}catch(e1){try{if(!i||i.constructor!==Object){e[8](i)}let v5=i["kind"],v6=i["x"],v7=i["y"];v5==="triangle"||e[9](v5);if(typeof v6!=="number"||Number.isNaN(v6)){e[10](v6)}if(typeof v7!=="number"||Number.isNaN(v7)){e[11](v7)}v2={"TAG":e[12],"x":v6,"y":v7,}}catch(e2){e[13]([e0,e1,e2,])}}}return v2}`, + `i=>{let v2;if(!i||i.constructor!==Object){e[0](i)}else{try{if(!i||i.constructor!==Object){e[1](i)}let v0=i["kind"],v1=i["radius"];v0==="circle"||e[2](v0);if(typeof v1!=="number"||Number.isNaN(v1)){e[3](v1)}v2={"TAG":e[4],"radius":v1,}}catch(e0){try{if(!i||i.constructor!==Object){e[5](i)}let v3=i["kind"],v4=i["x"];v3==="square"||e[6](v3);if(typeof v4!=="number"||Number.isNaN(v4)){e[7](v4)}v2={"TAG":e[8],"x":v4,}}catch(e1){try{if(!i||i.constructor!==Object){e[9](i)}let v5=i["kind"],v6=i["x"],v7=i["y"];v5==="triangle"||e[10](v5);if(typeof v6!=="number"||Number.isNaN(v6)){e[11](v6)}if(typeof v7!=="number"||Number.isNaN(v7)){e[12](v7)}v2={"TAG":e[13],"x":v6,"y":v7,}}catch(e2){e[14]([e0,e1,e2,])}}}}return v2}`, ) }) @@ -413,7 +441,7 @@ test("Compiled parse code snapshot", t => { t->U.assertCompiledCode( ~schema, ~op=#Parse, - `i=>{let v0;try{i===0||e[0](i);v0=i}catch(e0){try{i===1||e[1](i);v0=i}catch(e1){e[2]([e0,e1,])}}return v0}`, + `i=>{let v0;if(!(i===0)){if(!(i===1)){e[0](i)}else{v0=i}}else{v0=i}return v0}`, ) }) @@ -500,3 +528,86 @@ module CknittelBugReport = { ) }) } + +// Reported in https://gist.github.com/cknitt/4ac6813a3f3bc907187105e01a4324ca +module CrazyUnion = { + type rec test = + | A(array) + | B + | C + | D + | E + | F + | G + | H + | I + | J + | K + | L + | M + | N + | O + | P + | Q + | R + | S + | T + | U + | V + | W + | X + | Y + | Z(array) + + let schema = S.recursive(schema => + S.union([ + S.object(s => { + s.tag("type", "A") + A(s.field("nested", S.array(schema))) + }), + S.literal(B), + S.literal(C), + S.literal(D), + S.literal(E), + S.literal(F), + S.literal(G), + S.literal(H), + S.literal(I), + S.literal(J), + S.literal(K), + S.literal(L), + S.literal(M), + S.literal(N), + S.literal(O), + S.literal(P), + S.literal(Q), + S.literal(R), + S.literal(S), + S.literal(T), + S.literal(U), + S.literal(V), + S.literal(W), + S.literal(X), + S.literal(Y), + S.object(s => { + s.tag("type", "Z") + Z(s.field("nested", S.array(schema))) + }), + ]) + ) + + // test("Compiled code snapshot of crazy union", t => { + // S.setGlobalConfig({}) + // t->U.assertCompiledCode( + // ~schema, + // ~op=#Parse, + // `i=>{let r0=i=>{let v6;try{if(!i||i.constructor!==Object){e[0](i)}let v0=i["type"],v1=i["nested"],v5=[];v0==="A"||e[1](v0);if(!Array.isArray(v1)){e[2](v1)}for(let v2=0;v2U.assertCompiledCode( + // ~schema, + // ~op=#Serialize, + // `i=>{let r0=i=>{let v5,v6,v12;try{let v0=i["_0"],v4=[];if(i["TAG"]!==e[0]){e[1](i["TAG"])}for(let v1=0;v1): jsResult<'value> => { module InternalError = { %%raw(` + // let index = 0; class RescriptSchemaError extends Error { constructor(code, operation, path) { + // console.log(index) + // index = index + 1; super(); this.operation = operation; this.code = code; @@ -2838,6 +2841,58 @@ module Tuple = { } module Union = { + let genericParse = (b, ~schemas, ~input, ~output, ~path) => { + let codeEndRef = ref("") + let errorCodeRef = ref("") + let isAsync = ref(false) + + // TODO: Add support for async + for idx in 0 to schemas->Js.Array2.length - 1 { + let prevCode = b.code + try { + let schema = schemas->Js.Array2.unsafe_get(idx) + let errorVar = `e` ++ idx->Stdlib.Int.unsafeToString + b.code = b.code ++ `try{` + let itemOutput = b->B.parseWithTypeCheck(~schema, ~input, ~path=Path.empty) + if itemOutput.isAsync { + isAsync := true + } + + b.code = b.code ++ `${b->B.Val.set(output, itemOutput)}}catch(${errorVar}){` + codeEndRef := codeEndRef.contents ++ "}" + + errorCodeRef := errorCodeRef.contents ++ errorVar ++ "," + } catch { + | exn => + errorCodeRef := errorCodeRef.contents ++ b->B.embed(exn->InternalError.getOrRethrow) ++ "," + b.code = prevCode + } + } + + if isAsync.contents { + b->B.invalidOperation( + ~path, + ~description="S.union doesn't support async items. Please create an issue to rescript-schema if you nead the feature", + ) + } + + b.code = + b.code ++ + b->B.failWithArg( + ~path, + internalErrors => { + InvalidUnion(internalErrors) + }, + `[${errorCodeRef.contents}]`, + ) ++ + codeEndRef.contents + + let isAllSchemasBuilderFailed = codeEndRef.contents === "" + if isAllSchemasBuilderFailed { + b.code = b.code ++ ";" + } + } + let factory = schemas => { let schemas: array> = schemas->Obj.magic @@ -2851,61 +2906,68 @@ module Union = { ~rawTagged=Union(schemas), ~parseOperationBuilder=Builder.make((b, ~input, ~selfSchema, ~path) => { let schemas = selfSchema->classify->unsafeGetVariantPayload + let inputVar = b->B.Val.var(input) - let output = b->B.allocateVal - let codeEndRef = ref("") - let errorCodeRef = ref("") - let isAsync = ref(false) - - // TODO: Add support for async + let groupsByTypeFilter = Js.Dict.empty() + let typeFilters = [] for idx in 0 to schemas->Js.Array2.length - 1 { - let prevCode = b.code - try { - let schema = schemas->Js.Array2.unsafe_get(idx) - let errorVar = `e` ++ idx->Stdlib.Int.unsafeToString - b.code = b.code ++ `try{` - let itemOutput = b->B.parseWithTypeCheck(~schema, ~input, ~path=Path.empty) - if itemOutput.isAsync { - isAsync := true + let schema = schemas->Js.Array2.unsafe_get(idx) + let typeFilterCode = switch schema.maybeTypeFilter { + | Some(typeFilter) => typeFilter(~inputVar) + | None => + switch schema.rawTagged { + | Literal(literal) => + `!(${b->(literal->Literal.toInternal).checkBuilder(~inputVar, ~literal)})` + | _ => "false" + } + } + switch groupsByTypeFilter->Js.Dict.get(typeFilterCode) { + | Some(schemas) => schemas->Js.Array2.push(schema)->ignore + | None => { + typeFilters->Js.Array2.push(typeFilterCode)->ignore + groupsByTypeFilter->Js.Dict.set(typeFilterCode, [schema]) } - - b.code = b.code ++ `${b->B.Val.set(output, itemOutput)}}catch(${errorVar}){` - codeEndRef := codeEndRef.contents ++ "}" - - errorCodeRef := errorCodeRef.contents ++ errorVar ++ "," - } catch { - | exn => - errorCodeRef := - errorCodeRef.contents ++ b->B.embed(exn->InternalError.getOrRethrow) ++ "," - b.code = prevCode } } - if isAsync.contents { - b->B.invalidOperation( - ~path, - ~description="S.union doesn't support async items. Please create an issue to rescript-schema if you nead the feature", - ) - } + let output = b->B.allocateVal - b.code = - b.code ++ - b->B.failWithArg( - ~path, - internalErrors => { - InvalidUnion(internalErrors) - }, - `[${errorCodeRef.contents}]`, - ) ++ - codeEndRef.contents + let rec loopTypeFilters = idx => { + let isLastItem = idx === typeFilters->Js.Array2.length - 1 + let typeFilterCode = typeFilters->Js.Array2.unsafe_get(idx) + let schemas = groupsByTypeFilter->Js.Dict.unsafeGet(typeFilterCode) - let isAllSchemasBuilderFailed = codeEndRef.contents === "" - if isAllSchemasBuilderFailed { - b.code = b.code ++ ";" - input - } else { - output + b.code = b.code ++ `if(${typeFilterCode}){` + if isLastItem { + b.code = + b.code ++ + b->B.failWithArg( + ~path, + received => InvalidType({ + expected: selfSchema, + received, + }), + inputVar, + ) + } else { + loopTypeFilters(idx + 1) + } + b.code = b.code ++ `}else{` + switch schemas { + | [schema] => + let prevCode = b.code + try { + b.code = b.code ++ b->B.Val.set(output, b->B.parse(~schema, ~input, ~path)) + } catch { + | exn => b.code = prevCode ++ "throw " ++ b->B.embed(exn->InternalError.getOrRethrow) + } + | _ => genericParse(b, ~schemas, ~input, ~output, ~path) + } + b.code = b.code ++ `}` } + loopTypeFilters(0) + + output }), ~serializeOperationBuilder=Builder.make((b, ~input, ~selfSchema, ~path) => { let schemas = selfSchema->classify->unsafeGetVariantPayload diff --git a/test.js b/test.js index 952a7610..1a2f24ef 100644 --- a/test.js +++ b/test.js @@ -1,14 +1,226 @@ (i) => { - return e[0](i).then((v0) => { - return e[1](v0) - .then((v1) => { - if (typeof v1 !== "string") { - e[2](v1); + let r0 = (i) => { + let v5, v6, v12; + try { + let v0 = i["_0"], + v4 = []; + if (i["TAG"] !== e[0]) { + e[1](i["TAG"]); + } + for (let v1 = 0; v1 < v0.length; ++v1) { + let v3; + try { + v3 = r0(v0[v1]); + } catch (v2) { + if (v2 && v2.s === s) { + v2.path = '["_0"]' + '["' + v1 + '"]' + v2.path; + } + throw v2; } - return v1; - }) - .then((v2) => { - return e[3](v2); - }); - }); + v4.push(v3); + } + v5 = { type: e[2], nested: v4 }; + if (!v5 || v5.constructor !== Object) { + e[3](v5); + } + v6 = v5; + } catch (e0) { + try { + i === "B" || e[4](i); + v6 = i; + } catch (e1) { + try { + i === "C" || e[5](i); + v6 = i; + } catch (e2) { + try { + i === "D" || e[6](i); + v6 = i; + } catch (e3) { + try { + i === "E" || e[7](i); + v6 = i; + } catch (e4) { + try { + i === "F" || e[8](i); + v6 = i; + } catch (e5) { + try { + i === "G" || e[9](i); + v6 = i; + } catch (e6) { + try { + i === "H" || e[10](i); + v6 = i; + } catch (e7) { + try { + i === "I" || e[11](i); + v6 = i; + } catch (e8) { + try { + i === "J" || e[12](i); + v6 = i; + } catch (e9) { + try { + i === "K" || e[13](i); + v6 = i; + } catch (e10) { + try { + i === "L" || e[14](i); + v6 = i; + } catch (e11) { + try { + i === "M" || e[15](i); + v6 = i; + } catch (e12) { + try { + i === "N" || e[16](i); + v6 = i; + } catch (e13) { + try { + i === "O" || e[17](i); + v6 = i; + } catch (e14) { + try { + i === "P" || e[18](i); + v6 = i; + } catch (e15) { + try { + i === "Q" || e[19](i); + v6 = i; + } catch (e16) { + try { + i === "R" || e[20](i); + v6 = i; + } catch (e17) { + try { + i === "S" || e[21](i); + v6 = i; + } catch (e18) { + try { + i === "T" || e[22](i); + v6 = i; + } catch (e19) { + try { + i === "U" || e[23](i); + v6 = i; + } catch (e20) { + try { + i === "V" || e[24](i); + v6 = i; + } catch (e21) { + try { + i === "W" || e[25](i); + v6 = i; + } catch (e22) { + try { + i === "X" || e[26](i); + v6 = i; + } catch (e23) { + try { + i === "Y" || e[27](i); + v6 = i; + } catch (e24) { + try { + let v7 = i["_0"], + v11 = []; + if ( + i["TAG"] !== e[28] + ) { + e[29](i["TAG"]); + } + for ( + let v8 = 0; + v8 < v7.length; + ++v8 + ) { + let v10; + try { + v10 = r0(v7[v8]); + } catch (v9) { + if ( + v9 && + v9.s === s + ) { + v9.path = + '["_0"]' + + '["' + + v8 + + '"]' + + v9.path; + } + throw v9; + } + v11.push(v10); + } + v12 = { + type: e[30], + nested: v11, + }; + if ( + !v12 || + v12.constructor !== + Object + ) { + e[31](v12); + } + v6 = v12; + } catch (e25) { + e[32]([ + e0, + e1, + e2, + e3, + e4, + e5, + e6, + e7, + e8, + e9, + e10, + e11, + e12, + e13, + e14, + e15, + e16, + e17, + e18, + e19, + e20, + e21, + e22, + e23, + e24, + e25, + ]); + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + return v6; + }; + return r0(i); };