Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce val for building operations #73

Merged
merged 28 commits into from
May 18, 2024
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG_V7.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@
- Improved tree-shaking
- Can get the info from the `tagged` type: `JSON` -> `JSON({validated: bool})`
- Removed `s.failWithError`. Use `S.Error.raise` instead
- Removed async support for `S.union`. Please create an issue if you used the feature.
4 changes: 2 additions & 2 deletions packages/tests/src/core/Example_test.res
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ test("Compiled parse code snapshot", t => {
t->U.assertCompiledCode(
~schema=filmSchema,
~op=#parse,
`i=>{if(!i||i.constructor!==Object){e[11](i)}let v0,v1,v2,v3,v8,v9,v14,v15;v0=i["Id"];if(typeof v0!=="number"||Number.isNaN(v0)){e[0](v0)}v1=i["Title"];if(typeof v1!=="string"){e[1](v1)}v2=i["Tags"];if(v2!==void 0&&(!Array.isArray(v2))){e[2](v2)}if(v2!==void 0){let v5;v5=[];for(let v4=0;v4<v2.length;++v4){let v7;try{v7=v2[v4];if(typeof v7!=="string"){e[3](v7)}}catch(v6){if(v6&&v6.s===s){v6.path="[\\"Tags\\"]"+\'["\'+v4+\'"]\'+v6.path}throw v6}v5.push(v7)}v3=v5}else{v3=void 0}v8=i["Rating"];try{v8==="G"||e[5](v8);v9=v8}catch(v10){if(v10&&v10.s===s){try{v8==="PG"||e[6](v8);v9=v8}catch(v11){if(v11&&v11.s===s){try{v8==="PG13"||e[7](v8);v9=v8}catch(v12){if(v12&&v12.s===s){try{v8==="R"||e[8](v8);v9=v8}catch(v13){if(v13&&v13.s===s){e[9]([v10,v11,v12,v13])}else{throw v13}}}else{throw v12}}}else{throw v11}}}else{throw v10}}v14=i["Age"];if(v14!==void 0&&(typeof v14!=="number"||v14>2147483647||v14<-2147483648||v14%1!==0)){e[10](v14)}if(v14!==void 0){v15=v14}else{v15=void 0}return {"id":v0,"title":v1,"tags":v3===void 0?e[4]:v3,"rating":v9,"deprecatedAgeRestriction":v15,}}`,
`i=>{if(!i||i.constructor!==Object){e[11](i)}let v0=i["Id"],v1=i["Title"],v2=i["Tags"],v9=i["Rating"],v11=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)}let v8;if(v2!==void 0){let v7=[];for(let v3=0;v3<v2.length;++v3){let v6;try{let v5=v2[v3];if(typeof v5!=="string"){e[3](v5)}v6=v5}catch(v4){if(v4&&v4.s===s){v4.path="[\\"Tags\\"]"+\'["\'+v3+\'"]\'+v4.path}throw v4}v7.push(v6)}v8=v7}let v10;try{v9==="G"||e[5](v9);v10=v9}catch(e0){try{v9==="PG"||e[6](v9);v10=v9}catch(e1){try{v9==="PG13"||e[7](v9);v10=v9}catch(e2){try{v9==="R"||e[8](v9);v10=v9}catch(e3){e[9]([e0,e1,e2,e3,])}}}}if(v11!==void 0&&(typeof v11!=="number"||v11>2147483647||v11<-2147483648||v11%1!==0)){e[10](v11)}let v12;if(v11!==void 0){v12=v11}return {"id":v0,"title":v1,"tags":v8===void 0?e[4]:v8,"rating":v10,"deprecatedAgeRestriction":v12,}}`,
)
})

test("Compiled serialize code snapshot", t => {
t->U.assertCompiledCode(
~schema=filmSchema,
~op=#serialize,
`i=>{let v0,v1,v2,v3,v8,v9;v0=i["tags"];if(v0!==void 0){v1=e[0](v0)}else{v1=void 0}v2=i["rating"];try{v2==="G"||e[1](v2);v3=v2}catch(v4){if(v4&&v4.s===s){try{v2==="PG"||e[2](v2);v3=v2}catch(v5){if(v5&&v5.s===s){try{v2==="PG13"||e[3](v2);v3=v2}catch(v6){if(v6&&v6.s===s){try{v2==="R"||e[4](v2);v3=v2}catch(v7){if(v7&&v7.s===s){e[5]([v4,v5,v6,v7,])}else{throw v7}}}else{throw v6}}}else{throw v5}}}else{throw v4}}v8=i["deprecatedAgeRestriction"];if(v8!==void 0){v9=e[6](v8)}else{v9=void 0}return {"Id":i["id"],"Title":i["title"],"Tags":v1,"Rating":v3,"Age":v9,}}`,
`i=>{let v0=i["tags"],v1,v2=i["rating"],v3,v4=i["deprecatedAgeRestriction"],v5;if(v0!==void 0){v1=e[0](v0)}try{v2==="G"||e[1](v2);v3=v2}catch(e0){try{v2==="PG"||e[2](v2);v3=v2}catch(e1){try{v2==="PG13"||e[3](v2);v3=v2}catch(e2){try{v2==="R"||e[4](v2);v3=v2}catch(e3){e[5]([e0,e1,e2,e3,])}}}}if(v4!==void 0){v5=e[6](v4)}return {"Id":i["id"],"Title":i["title"],"Tags":v1,"Rating":v3,"Age":v5,}}`,
)
})
6 changes: 3 additions & 3 deletions packages/tests/src/core/S_Option_getOrWith_test.res
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ test("Compiled parse code snapshot", t => {
t->U.assertCompiledCode(
~schema,
~op=#parse,
`i=>{if(i!==void 0&&(typeof i!=="boolean")){e[1](i)}let v0;if(i!==void 0){v0=i}else{v0=void 0}return v0===void 0?e[0]():v0}`,
`i=>{if(i!==void 0&&(typeof i!=="boolean")){e[1](i)}let v0;if(i!==void 0){v0=i}return v0===void 0?e[0]():v0}`,
)
})

Expand All @@ -76,7 +76,7 @@ test("Compiled async parse code snapshot", t => {
t->U.assertCompiledCode(
~schema,
~op=#parse,
`i=>{if(i!==void 0&&(typeof i!=="boolean")){e[2](i)}let v0,v3;if(i!==void 0){let v1;v1=e[0](i);v0=v1}else{v0=()=>Promise.resolve(void 0)}v3=()=>v0().then(v2=>{return v2===void 0?e[1]():v2});return v3}`,
`i=>{if(i!==void 0&&(typeof i!=="boolean")){e[2](i)}let v0,v2=()=>v0().then(v1=>{return v1===void 0?e[1]():v1});if(i!==void 0){v0=e[0](i)}else{v0=()=>Promise.resolve(void 0)}return v2}`,
)
})

Expand All @@ -86,6 +86,6 @@ test("Compiled serialize code snapshot", t => {
t->U.assertCompiledCode(
~schema,
~op=#serialize,
`i=>{let v0;if(i!==void 0){v0=e[0](i)}else{v0=void 0}return v0}`,
`i=>{let v0;if(i!==void 0){v0=e[0](i)}return v0}`,
)
})
6 changes: 3 additions & 3 deletions packages/tests/src/core/S_Option_getOr_test.res
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ test("Compiled parse code snapshot", t => {
t->U.assertCompiledCode(
~schema,
~op=#parse,
`i=>{if(i!==void 0&&(typeof i!=="boolean")){e[1](i)}let v0;if(i!==void 0){v0=i}else{v0=void 0}return v0===void 0?e[0]:v0}`,
`i=>{if(i!==void 0&&(typeof i!=="boolean")){e[1](i)}let v0;if(i!==void 0){v0=i}return v0===void 0?e[0]:v0}`,
)
})

Expand All @@ -100,7 +100,7 @@ test("Compiled async parse code snapshot", t => {
t->U.assertCompiledCode(
~schema,
~op=#parse,
`i=>{if(i!==void 0&&(typeof i!=="boolean")){e[2](i)}let v0,v3;if(i!==void 0){let v1;v1=e[0](i);v0=v1}else{v0=()=>Promise.resolve(void 0)}v3=()=>v0().then(v2=>{return v2===void 0?e[1]:v2});return v3}`,
`i=>{if(i!==void 0&&(typeof i!=="boolean")){e[2](i)}let v0,v2=()=>v0().then(v1=>{return v1===void 0?e[1]:v1});if(i!==void 0){v0=e[0](i)}else{v0=()=>Promise.resolve(void 0)}return v2}`,
)
})

Expand All @@ -110,6 +110,6 @@ test("Compiled serialize code snapshot", t => {
t->U.assertCompiledCode(
~schema,
~op=#serialize,
`i=>{let v0;if(i!==void 0){v0=e[0](i)}else{v0=void 0}return v0}`,
`i=>{let v0;if(i!==void 0){v0=e[0](i)}return v0}`,
)
})
6 changes: 3 additions & 3 deletions packages/tests/src/core/S_array_test.res
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ module CommonWithNested = {
t->U.assertCompiledCode(
~schema,
~op=#parse,
`i=>{if(!Array.isArray(i)){e[1](i)}let v1;v1=[];for(let v0=0;v0<i.length;++v0){let v3;try{v3=i[v0];if(typeof v3!=="string"){e[0](v3)}}catch(v2){if(v2&&v2.s===s){v2.path=""+'["'+v0+'"]'+v2.path}throw v2}v1.push(v3)}return v1}`,
`i=>{if(!Array.isArray(i)){e[1](i)}let v4=[];for(let v0=0;v0<i.length;++v0){let v3;try{let v2=i[v0];if(typeof v2!=="string"){e[0](v2)}v3=v2}catch(v1){if(v1&&v1.s===s){v1.path=""+\'["\'+v0+\'"]\'+v1.path}throw v1}v4.push(v3)}return v4}`,
)
})

Expand All @@ -62,7 +62,7 @@ module CommonWithNested = {
t->U.assertCompiledCode(
~schema,
~op=#parse,
`i=>{if(!Array.isArray(i)){e[1](i)}let v1,v5;v1=[];for(let v0=0;v0<i.length;++v0){let v3,v4;try{v3=e[0](i[v0]);v4=()=>{try{return v3().catch(v2=>{if(v2&&v2.s===s){v2.path=""+\'["\'+v0+\'"]\'+v2.path}throw v2})}catch(v2){if(v2&&v2.s===s){v2.path=""+\'["\'+v0+\'"]\'+v2.path}throw v2}};}catch(v2){if(v2&&v2.s===s){v2.path=""+\'["\'+v0+\'"]\'+v2.path}throw v2}v1.push(v4)}v5=()=>Promise.all(v1.map(t=>t()));return v5}`,
`i=>{if(!Array.isArray(i)){e[1](i)}let v4=[],v5=()=>Promise.all(v4.map(t=>t()));for(let v0=0;v0<i.length;++v0){let v2,v3;try{v2=e[0](i[v0]);v3=()=>{try{return v2().catch(v1=>{if(v1&&v1.s===s){v1.path=""+\'["\'+v0+\'"]\'+v1.path}throw v1})}catch(v1){if(v1&&v1.s===s){v1.path=""+\'["\'+v0+\'"]\'+v1.path}throw v1}}}catch(v1){if(v1&&v1.s===s){v1.path=""+\'["\'+v0+\'"]\'+v1.path}throw v1}v4.push(v3)}return v5}`,
)
})

Expand All @@ -79,7 +79,7 @@ module CommonWithNested = {
t->U.assertCompiledCode(
~schema,
~op=#serialize,
`i=>{let v1;v1=[];for(let v0=0;v0<i.length;++v0){let v3,v4;try{v3=i[v0];if(v3!==void 0){v4=e[0](v3)}else{v4=void 0}}catch(v2){if(v2&&v2.s===s){v2.path=""+'["'+v0+'"]'+v2.path}throw v2}v1.push(v4)}return v1}`,
`i=>{let v5=[];for(let v0=0;v0<i.length;++v0){let v4;try{let v2=i[v0],v3;if(v2!==void 0){v3=e[0](v2)}v4=v3}catch(v1){if(v1&&v1.s===s){v1.path=""+\'["\'+v0+\'"]\'+v1.path}throw v1}v5.push(v4)}return v5}`,
)
})
}
Expand Down
5 changes: 3 additions & 2 deletions packages/tests/src/core/S_catch_test.res
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ test("Compiled parse code snapshot", t => {
t->U.assertCompiledCode(
~schema,
~op=#parse,
`i=>{try{if(typeof i!=="boolean"){e[1](i)}}catch(v0){if(v0&&v0.s===s){i=e[0](i,v0)}else{throw v0}}return i}`,
// TODO: Improve to return i without reassigning
`i=>{let v1;try{if(typeof i!=="boolean"){e[1](i)}v1=i}catch(v0){if(v0&&v0.s===s){v1=e[0](i,v0)}else{throw v0}}return v1}`,
)
})

Expand All @@ -127,7 +128,7 @@ test("Compiled async parse code snapshot", t => {
t->U.assertCompiledCode(
~schema,
~op=#parse,
`i=>{let v1,v2;try{if(typeof i!=="boolean"){e[1](i)}v1=e[2](i);v2=()=>{try{return v1().catch(v0=>{if(v0&&v0.s===s){return e[0](i,v0)}else{throw v0}})}catch(v0){if(v0&&v0.s===s){return Promise.resolve(e[0](i,v0))}else{throw v0}}};}catch(v0){if(v0&&v0.s===s){v2=()=>Promise.resolve(e[0](i,v0))}else{throw v0}}return v2}`,
`i=>{let v1,v2;try{if(typeof i!=="boolean"){e[1](i)}v1=e[2](i);v2=()=>{try{return v1().catch(v0=>{if(v0&&v0.s===s){return e[0](i,v0)}else{throw v0}})}catch(v0){if(v0&&v0.s===s){return Promise.resolve(e[0](i,v0))}else{throw v0}}}}catch(v0){if(v0&&v0.s===s){v2=()=>Promise.resolve(e[0](i,v0))}else{throw v0}}return v2}`,
)
})

Expand Down
6 changes: 3 additions & 3 deletions packages/tests/src/core/S_dict_test.res
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ module CommonWithNested = {
t->U.assertCompiledCode(
~schema,
~op=#parse,
`i=>{if(!i||i.constructor!==Object){e[1](i)}let v1;v1={};for(let v0 in i){let v3;try{v3=i[v0];if(typeof v3!=="string"){e[0](v3)}}catch(v2){if(v2&&v2.s===s){v2.path=""+\'["\'+v0+\'"]\'+v2.path}throw v2}v1[v0]=v3}return v1}`,
`i=>{if(!i||i.constructor!==Object){e[1](i)}let v4={};for(let v0 in i){let v3;try{let v2=i[v0];if(typeof v2!=="string"){e[0](v2)}v3=v2}catch(v1){if(v1&&v1.s===s){v1.path=""+\'["\'+v0+\'"]\'+v1.path}throw v1}v4[v0]=v3}return v4}`,
)
})

Expand All @@ -62,7 +62,7 @@ module CommonWithNested = {
t->U.assertCompiledCode(
~schema,
~op=#parse,
`i=>{if(!i||i.constructor!==Object){e[1](i)}let v1,v9;v1={};for(let v0 in i){let v3,v4;try{v3=e[0](i[v0]);v4=()=>{try{return v3().catch(v2=>{if(v2&&v2.s===s){v2.path=""+'["'+v0+'"]'+v2.path}throw v2})}catch(v2){if(v2&&v2.s===s){v2.path=""+'["'+v0+'"]'+v2.path}throw v2}};}catch(v2){if(v2&&v2.s===s){v2.path=""+'["'+v0+'"]'+v2.path}throw v2}v1[v0]=v4}v9=()=>new Promise((v5,v6)=>{let v8=Object.keys(v1).length;for(let v0 in v1){v1[v0]().then(v7=>{v1[v0]=v7;if(v8--===1){v5(v1)}},v6)}});return v9}`,
`i=>{if(!i||i.constructor!==Object){e[1](i)}let v4={},v9=()=>new Promise((v5,v6)=>{let v8=Object.keys(v4).length;for(let v0 in v4){v4[v0]().then(v7=>{v4[v0]=v7;if(v8--===1){v5(v4)}},v6)}});for(let v0 in i){let v2,v3;try{v2=e[0](i[v0]);v3=()=>{try{return v2().catch(v1=>{if(v1&&v1.s===s){v1.path=""+\'["\'+v0+\'"]\'+v1.path}throw v1})}catch(v1){if(v1&&v1.s===s){v1.path=""+\'["\'+v0+\'"]\'+v1.path}throw v1}}}catch(v1){if(v1&&v1.s===s){v1.path=""+\'["\'+v0+\'"]\'+v1.path}throw v1}v4[v0]=v3}return v9}`,
)
})

Expand All @@ -78,7 +78,7 @@ module CommonWithNested = {
t->U.assertCompiledCode(
~schema,
~op=#serialize,
`i=>{let v1;v1={};for(let v0 in i){let v3,v4;try{v3=i[v0];if(v3!==void 0){v4=e[0](v3)}else{v4=void 0}}catch(v2){if(v2&&v2.s===s){v2.path=""+'["'+v0+'"]'+v2.path}throw v2}v1[v0]=v4}return v1}`,
`i=>{let v5={};for(let v0 in i){let v4;try{let v2=i[v0],v3;if(v2!==void 0){v3=e[0](v2)}v4=v3}catch(v1){if(v1&&v1.s===s){v1.path=""+\'["\'+v0+\'"]\'+v1.path}throw v1}v5[v0]=v4}return v5}`,
)
})
}
Expand Down
2 changes: 1 addition & 1 deletion packages/tests/src/core/S_jsonString_test.res
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ test("Compiled async parse code snapshot", t => {
t->U.assertCompiledCode(
~schema,
~op=#parse,
`i=>{if(typeof i!=="string"){e[3](i)}let v0,v1;try{v0=JSON.parse(i)}catch(t){e[0](t.message)}if(typeof v0!=="boolean"){e[1](v0)}v1=e[2](v0);return v1}`,
`i=>{if(typeof i!=="string"){e[3](i)}let v0;try{v0=JSON.parse(i)}catch(t){e[0](t.message)}if(typeof v0!=="boolean"){e[1](v0)}return e[2](v0)}`,
)
})

Expand Down
4 changes: 2 additions & 2 deletions packages/tests/src/core/S_literal_Undefined_test.res
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ module Common = {
test("Compiled parse code snapshot", t => {
let schema = factory()

t->U.assertCompiledCode(~schema, ~op=#parse, `i=>{i===void 0||e[0](i);return i}`)
t->U.assertCompiledCode(~schema, ~op=#parse, `i=>{i===undefined||e[0](i);return i}`)
})

test("Compiled serialize code snapshot", t => {
let schema = factory()

t->U.assertCompiledCode(~schema, ~op=#serialize, `i=>{i===void 0||e[0](i);return i}`)
t->U.assertCompiledCode(~schema, ~op=#serialize, `i=>{i===undefined||e[0](i);return i}`)
})
}
2 changes: 1 addition & 1 deletion packages/tests/src/core/S_null_test.res
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ module Common = {
t->U.assertCompiledCode(
~schema,
~op=#parse,
`i=>{let v0;if(i!==null){let v1;v1=e[0](i);v0=v1}else{v0=()=>Promise.resolve(void 0)}return v0}`,
`i=>{let v0;if(i!==null){v0=e[0](i)}else{v0=()=>Promise.resolve(void 0)}return v0}`,
)
})

Expand Down
6 changes: 3 additions & 3 deletions packages/tests/src/core/S_nullable_test.res
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ module NullCommon = {
t->U.assertCompiledCode(
~schema,
~op=#parse,
`i=>{if(i!==void 0&&(i!==null&&(typeof i!=="string"))){e[0](i)}let v0;if(i!==void 0){let v1;if(i!==null){v1=i}else{v1=void 0}v0=v1}else{v0=void 0}return v0}`,
`i=>{if(i!==void 0&&(i!==null&&(typeof i!=="string"))){e[0](i)}let v1;if(i!==void 0){let v0;if(i!==null){v0=i}else{v0=void 0}v1=v0}return v1}`,
)
})

Expand All @@ -50,7 +50,7 @@ module NullCommon = {
t->U.assertCompiledCode(
~schema,
~op=#parse,
`i=>{let v0;if(i!==void 0){let v1;if(i!==null){let v2;v2=e[0](i);v1=v2}else{v1=()=>Promise.resolve(void 0)}v0=v1}else{v0=()=>Promise.resolve(void 0)}return v0}`,
`i=>{let v1;if(i!==void 0){let v0;if(i!==null){v0=e[0](i)}else{v0=()=>Promise.resolve(void 0)}v1=v0}else{v1=()=>Promise.resolve(void 0)}return v1}`,
)
})

Expand All @@ -60,7 +60,7 @@ module NullCommon = {
t->U.assertCompiledCode(
~schema,
~op=#serialize,
`i=>{let v0;if(i!==void 0){let v1,v2;v1=e[0](i);if(v1!==void 0){v2=e[1](v1)}else{v2=null}v0=v2}else{v0=void 0}return v0}`,
`i=>{let v2;if(i!==void 0){let v0=e[0](i),v1;if(v0!==void 0){v1=e[1](v0)}else{v1=null}v2=v1}return v2}`,
)
})
}
Expand Down
8 changes: 4 additions & 4 deletions packages/tests/src/core/S_object_test.res
Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,7 @@ module Compiled = {
t->U.assertCompiledCode(
~schema,
~op=#parse,
`i=>{if(!i||i.constructor!==Object){e[2](i)}let v0,v1;v0=i["foo"];if(typeof v0!=="string"){e[0](v0)}v1=i["bar"];if(typeof v1!=="boolean"){e[1](v1)}return {"foo":v0,"bar":v1,}}`,
`i=>{if(!i||i.constructor!==Object){e[2](i)}let v0=i["foo"],v1=i["bar"];if(typeof v0!=="string"){e[0](v0)}if(typeof v1!=="boolean"){e[1](v1)}return {"foo":v0,"bar":v1,}}`,
)
})

Expand All @@ -1004,7 +1004,7 @@ module Compiled = {
t->U.assertCompiledCode(
~schema,
~op=#parse,
`i=>{if(!i||i.constructor!==Object){e[2](i)}let v0,v1,v2;v0=e[0](i["foo"]);v1=i["bar"];if(typeof v1!=="boolean"){e[1](v1)}v2=()=>Promise.all([v0()]).then(([v0])=>({"foo":v0,"bar":v1,}));return v2}`,
`i=>{if(!i||i.constructor!==Object){e[2](i)}let v0,v1=i["bar"],v2=()=>Promise.all([v0()]).then(([v0])=>({"foo":v0,"bar":v1,}));v0=e[0](i["foo"]);if(typeof v1!=="boolean"){e[1](v1)}return v2}`,
)
})

Expand All @@ -1030,7 +1030,7 @@ module Compiled = {
t->U.assertCompiledCode(
~schema,
~op=#parse,
`i=>{if(!i||i.constructor!==Object){e[3](i)}let v0,v1,v2;v1=i["foo"];if(typeof v1!=="string"){e[1](v1)}v2=i["bar"];if(typeof v2!=="boolean"){e[2](v2)}for(v0 in i){if(v0!=="foo"&&v0!=="bar"){e[0](v0)}}return {"foo":v1,"bar":v2,}}`,
`i=>{if(!i||i.constructor!==Object){e[3](i)}let v0,v1=i["foo"],v2=i["bar"];if(typeof v1!=="string"){e[1](v1)}if(typeof v2!=="boolean"){e[2](v2)}for(v0 in i){if(v0!=="foo"&&v0!=="bar"){e[0](v0)}}return {"foo":v1,"bar":v2,}}`,
)
})

Expand Down Expand Up @@ -1060,7 +1060,7 @@ module Compiled = {
t->U.assertCompiledCode(
~schema,
~op=#parse,
`i=>{if(!i||i.constructor!==Object){e[5](i)}let v0,v1,v2,v3;v3=i["tag"];v3===0||e[4](v3);v1=i["FOO"];if(typeof v1!=="string"){e[1](v1)}v2=i["BAR"];if(typeof v2!=="boolean"){e[2](v2)}for(v0 in i){if(v0!=="tag"&&v0!=="FOO"&&v0!=="BAR"){e[0](v0)}}return {"foo":v1,"bar":v2,"zoo":e[3],}}`,
`i=>{if(!i||i.constructor!==Object){e[5](i)}let v0,v1=i["FOO"],v2=i["BAR"],v3=i["tag"];v3===0||e[4](v3);if(typeof v1!=="string"){e[1](v1)}if(typeof v2!=="boolean"){e[2](v2)}for(v0 in i){if(v0!=="tag"&&v0!=="FOO"&&v0!=="BAR"){e[0](v0)}}return {"foo":v1,"bar":v2,"zoo":e[3],}}`,
)
},
)
Expand Down
6 changes: 3 additions & 3 deletions packages/tests/src/core/S_option_test.res
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ module Common = {
t->U.assertCompiledCode(
~schema,
~op=#parse,
`i=>{if(i!==void 0&&(typeof i!=="string")){e[0](i)}let v0;if(i!==void 0){v0=i}else{v0=void 0}return v0}`,
`i=>{if(i!==void 0&&(typeof i!=="string")){e[0](i)}let v0;if(i!==void 0){v0=i}return v0}`,
)
})

Expand All @@ -48,7 +48,7 @@ module Common = {
t->U.assertCompiledCode(
~schema,
~op=#parse,
`i=>{let v0;if(i!==void 0){let v1;v1=e[0](i);v0=v1}else{v0=()=>Promise.resolve(void 0)}return v0}`,
`i=>{let v0;if(i!==void 0){v0=e[0](i)}else{v0=()=>Promise.resolve(void 0)}return v0}`,
)
})

Expand All @@ -58,7 +58,7 @@ module Common = {
t->U.assertCompiledCode(
~schema,
~op=#serialize,
`i=>{let v0;if(i!==void 0){v0=e[0](i)}else{v0=void 0}return v0}`,
`i=>{let v0;if(i!==void 0){v0=e[0](i)}return v0}`,
)
})
}
Expand Down
Loading
Loading