Skip to content

Commit

Permalink
Evaluated operation: Move var allocation after type check
Browse files Browse the repository at this point in the history
  • Loading branch information
DZakh committed May 11, 2024
1 parent cad31f0 commit 34a5ae5
Show file tree
Hide file tree
Showing 15 changed files with 33 additions and 30 deletions.
2 changes: 1 addition & 1 deletion packages/tests/src/core/Example_test.res
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ test("Compiled parse code snapshot", t => {
t->U.assertCompiledCode(
~schema=filmSchema,
~op=#parse,
`i=>{let v0,v1,v2,v3,v8,v9,v14,v15;if(!i||i.constructor!==Object){e[11](i)}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,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,}}`,
)
})

Expand Down
4 changes: 2 additions & 2 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=>{let v0;if(i!==void 0&&(typeof i!=="boolean")){e[1](i)}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}else{v0=void 0}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=>{let v0,v3;if(i!==void 0&&(typeof i!=="boolean")){e[2](i)}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,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}`,
)
})

Expand Down
4 changes: 2 additions & 2 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=>{let v0;if(i!==void 0&&(typeof i!=="boolean")){e[1](i)}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}else{v0=void 0}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=>{let v0,v3;if(i!==void 0&&(typeof i!=="boolean")){e[2](i)}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,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}`,
)
})

Expand Down
4 changes: 2 additions & 2 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=>{let v1;if(!Array.isArray(i)){e[1](i)}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 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}`,
)
})

Expand All @@ -62,7 +62,7 @@ module CommonWithNested = {
t->U.assertCompiledCode(
~schema,
~op=#parse,
`i=>{let v1,v5;if(!Array.isArray(i)){e[1](i)}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 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}`,
)
})

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=>{let v1;if(!i||i.constructor!==Object){e[1](i)}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 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}`,
)
})

Expand All @@ -62,7 +62,7 @@ module CommonWithNested = {
t->U.assertCompiledCode(
~schema,
~op=#parse,
`i=>{let v1,v9;if(!i||i.constructor!==Object){e[1](i)}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 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}`,
)
})

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 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}`,
)
})
}
Expand Down
4 changes: 2 additions & 2 deletions packages/tests/src/core/S_jsonString_test.res
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ test("Compiled parse code snapshot", t => {
t->U.assertCompiledCode(
~schema,
~op=#parse,
`i=>{let v0;if(typeof i!=="string"){e[2](i)}try{v0=JSON.parse(i)}catch(t){e[0](t.message)}if(typeof v0!=="boolean"){e[1](v0)}return v0}`,
`i=>{if(typeof i!=="string"){e[2](i)}let v0;try{v0=JSON.parse(i)}catch(t){e[0](t.message)}if(typeof v0!=="boolean"){e[1](v0)}return v0}`,
)
})

Expand All @@ -81,7 +81,7 @@ test("Compiled async parse code snapshot", t => {
t->U.assertCompiledCode(
~schema,
~op=#parse,
`i=>{let v0,v1;if(typeof i!=="string"){e[3](i)}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,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}`,
)
})

Expand Down
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 @@ -38,7 +38,7 @@ module Common = {
t->U.assertCompiledCode(
~schema,
~op=#parse,
`i=>{let v0;if(i!==null&&(typeof i!=="string")){e[0](i)}if(i!==null){v0=i}else{v0=void 0}return v0}`,
`i=>{if(i!==null&&(typeof i!=="string")){e[0](i)}let v0;if(i!==null){v0=i}else{v0=void 0}return v0}`,
)
})

Expand Down
2 changes: 1 addition & 1 deletion 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=>{let v0;if(i!==void 0&&(i!==null&&(typeof i!=="string"))){e[0](i)}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 v0;if(i!==void 0){let v1;if(i!==null){v1=i}else{v1=void 0}v0=v1}else{v0=void 0}return v0}`,
)
})

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=>{let v0,v1;if(!i||i.constructor!==Object){e[2](i)}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,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,}}`,
)
})

Expand All @@ -1004,7 +1004,7 @@ module Compiled = {
t->U.assertCompiledCode(
~schema,
~op=#parse,
`i=>{let v0,v1,v2;if(!i||i.constructor!==Object){e[2](i)}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,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}`,
)
})

Expand All @@ -1030,7 +1030,7 @@ module Compiled = {
t->U.assertCompiledCode(
~schema,
~op=#parse,
`i=>{let v0,v1,v2;if(!i||i.constructor!==Object){e[3](i)}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,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,}}`,
)
})

Expand Down Expand Up @@ -1060,7 +1060,7 @@ module Compiled = {
t->U.assertCompiledCode(
~schema,
~op=#parse,
`i=>{let v0,v1,v2,v3;if(!i||i.constructor!==Object){e[5](i)}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,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],}}`,
)
},
)
Expand Down
2 changes: 1 addition & 1 deletion 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=>{let v0;if(i!==void 0&&(typeof i!=="string")){e[0](i)}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}else{v0=void 0}return v0}`,
)
})

Expand Down
2 changes: 1 addition & 1 deletion packages/tests/src/core/S_refine_test.res
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@ test("Compiled parse code snapshot for simple object with refine", t => {
t->U.assertCompiledCode(
~schema,
~op=#parse,
`i=>{let v0,v1,v2;if(!i||i.constructor!==Object){e[3](i)}v0=i["foo"];if(typeof v0!=="string"){e[0](v0)}v1=i["bar"];if(typeof v1!=="boolean"){e[1](v1)}v2={"foo":v0,"bar":v1,};e[2](v2);return v2}`,
`i=>{if(!i||i.constructor!==Object){e[3](i)}let v0,v1,v2;v0=i["foo"];if(typeof v0!=="string"){e[0](v0)}v1=i["bar"];if(typeof v1!=="boolean"){e[1](v1)}v2={"foo":v0,"bar":v1,};e[2](v2);return v2}`,
)
})
2 changes: 1 addition & 1 deletion packages/tests/src/core/S_transform_test.res
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ test("Compiled async parse code snapshot", t => {
t->U.assertCompiledCode(
~schema,
~op=#parse,
`i=>{let v0;if(typeof i!=="number"||i>2147483647||i<-2147483648||i%1!==0){e[1](i)}v0=e[0](i);return v0}`,
`i=>{if(typeof i!=="number"||i>2147483647||i<-2147483648||i%1!==0){e[1](i)}let v0;v0=e[0](i);return v0}`,
)
})

Expand Down
6 changes: 3 additions & 3 deletions packages/tests/src/core/S_tuple_test.res
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ module Compiled = {
t->U.assertCompiledCode(
~schema,
~op=#parse,
`i=>{let v0,v1;if(!Array.isArray(i)){e[3](i)}if(i.length!==2){e[0](i.length)}v0=i["0"];if(typeof v0!=="string"){e[1](v0)}v1=i["1"];if(typeof v1!=="boolean"){e[2](v1)}return [v0,v1,]}`,
`i=>{if(!Array.isArray(i)){e[3](i)}let v0,v1;if(i.length!==2){e[0](i.length)}v0=i["0"];if(typeof v0!=="string"){e[1](v0)}v1=i["1"];if(typeof v1!=="boolean"){e[2](v1)}return [v0,v1,]}`,
)
})

Expand All @@ -247,7 +247,7 @@ module Compiled = {
t->U.assertCompiledCode(
~schema,
~op=#parse,
`i=>{let v0,v1,v2;if(!Array.isArray(i)){e[3](i)}if(i.length!==2){e[0](i.length)}v0=e[1](i["0"]);v1=i["1"];if(typeof v1!=="boolean"){e[2](v1)}v2=()=>Promise.all([v0()]).then(([v0])=>([v0,v1,]));return v2}`,
`i=>{if(!Array.isArray(i)){e[3](i)}let v0,v1,v2;if(i.length!==2){e[0](i.length)}v0=e[1](i["0"]);v1=i["1"];if(typeof v1!=="boolean"){e[2](v1)}v2=()=>Promise.all([v0()]).then(([v0])=>([v0,v1,]));return v2}`,
)
})

Expand Down Expand Up @@ -277,7 +277,7 @@ module Compiled = {
t->U.assertCompiledCode(
~schema,
~op=#parse,
`i=>{let v0,v1,v2;if(!Array.isArray(i)){e[5](i)}if(i.length!==3){e[0](i.length)}v2=i["0"];v2===0||e[4](v2);v0=i["1"];if(typeof v0!=="string"){e[1](v0)}v1=i["2"];if(typeof v1!=="boolean"){e[2](v1)}return {"foo":v0,"bar":v1,"zoo":e[3],}}`,
`i=>{if(!Array.isArray(i)){e[5](i)}let v0,v1,v2;if(i.length!==3){e[0](i.length)}v2=i["0"];v2===0||e[4](v2);v0=i["1"];if(typeof v0!=="string"){e[1](v0)}v1=i["2"];if(typeof v1!=="boolean"){e[2](v1)}return {"foo":v0,"bar":v1,"zoo":e[3],}}`,
)
},
)
Expand Down
7 changes: 4 additions & 3 deletions src/S_Core.bs.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,9 @@ function build(builder, schema, operation) {
e: []
};
var output = builder(b, schema, "");
if (b.l !== "") {
b.c = "let " + b.l + ";" + b.c;
}
if (operation === "Parsing") {
var typeFilter = schema.f;
if (typeFilter !== undefined) {
Expand All @@ -328,9 +331,7 @@ function build(builder, schema, operation) {
if (b.c === "" && output === "i") {
return noopOperation;
}
var inlinedFunction = "i=>{" + (
b.l === "" ? "" : "let " + b.l + ";"
) + b.c + "return " + output + "}";
var inlinedFunction = "i=>{" + b.c + "return " + output + "}";
return new Function("e", "s", "return " + inlinedFunction)(b.e, symbol);
}

Expand Down
8 changes: 5 additions & 3 deletions src/S_Core.res
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,10 @@ module Builder = {
~path=Path.empty,
)

if b._varsAllocation !== "" {
b.code = `let ${b._varsAllocation};${b.code}`
}

if operation === Parsing {
switch schema.maybeTypeFilter {
| Some(typeFilter) =>
Expand All @@ -672,9 +676,7 @@ module Builder = {
if b.code === "" && output === intitialInputVar {
noopOperation
} else {
let inlinedFunction = `${intitialInputVar}=>{${b._varsAllocation === ""
? ""
: `let ${b._varsAllocation};`}${b.code}return ${output}}`
let inlinedFunction = `${intitialInputVar}=>{${b.code}return ${output}}`

// Js.log(inlinedFunction)

Expand Down

1 comment on commit 34a5ae5

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: 34a5ae5 Previous: 9fb2e69 Ratio
Parse string 878390967 ops/sec (±0.27%) 819064824 ops/sec (±0.11%) 0.93
Serialize string 877068099 ops/sec (±0.28%) 819779932 ops/sec (±0.08%) 0.93
Advanced object schema factory 452618 ops/sec (±0.49%) 431262 ops/sec (±0.44%) 0.95
Parse advanced object 50238278 ops/sec (±0.99%) 46671133 ops/sec (±0.42%) 0.93
Create and parse advanced object 36346 ops/sec (±0.83%) 34129 ops/sec (±0.58%) 0.94
Parse advanced strict object 23737594 ops/sec (±1.26%) 22262984 ops/sec (±0.24%) 0.94
Serialize advanced object 871069839 ops/sec (±0.32%) 807737293 ops/sec (±0.20%) 0.93

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.