From 5e2cf3cf1886683cd4f1f41b2c9e26ba542ce0c1 Mon Sep 17 00:00:00 2001 From: Liam DeBeasi Date: Mon, 28 Oct 2024 19:04:11 -0400 Subject: [PATCH] fix: async functions in store are preserved (#1612) * test: add failing test * preserve async status * add fix * fix path * better fix * snapshots * changeset * snapshots * workarounds do not apply for async fns * add comments * add another test case * account for object methods too * add comment * remove log * update snapshots * style --- .changeset/great-phones-exist.md | 5 + .../__snapshots__/alpine.test.ts.snap | 40 ++++ .../__snapshots__/angular.import.test.ts.snap | 80 +++++++ .../__snapshots__/angular.mapper.test.ts.snap | 82 ++++++++ .../__snapshots__/angular.state.test.ts.snap | 80 +++++++ .../__snapshots__/angular.styles.test.ts.snap | 66 ++++++ .../__snapshots__/angular.test.ts.snap | 146 +++++++++++++ .../__tests__/__snapshots__/html.test.ts.snap | 10 + .../__snapshots__/liquid.test.ts.snap | 10 + .../__tests__/__snapshots__/lit.test.ts.snap | 62 ++++++ .../__snapshots__/marko.test.ts.snap | 32 +++ .../__snapshots__/mitosis.test.ts.snap | 130 ++++++++++++ .../__snapshots__/parse-jsx.test.ts.snap | 104 ++++++++++ .../__snapshots__/preact.test.ts.snap | 48 +++++ .../__tests__/__snapshots__/qwik.test.ts.snap | 44 ++++ .../__snapshots__/react-native.test.ts.snap | 72 +++++++ .../react-state-builder.test.ts.snap | 46 ++++ .../react-state-mobx.test.ts.snap | 50 +++++ .../react-state-solid.test.ts.snap | 48 +++++ .../react-state-valtio.test.ts.snap | 48 +++++ .../react-state-variables.test.ts.snap | 42 ++++ .../__snapshots__/react.test.ts.snap | 46 ++++ .../__tests__/__snapshots__/rsc.test.ts.snap | 42 ++++ .../__snapshots__/solid.test.ts.snap | 108 ++++++++++ .../__snapshots__/stencil.test.ts.snap | 48 +++++ .../__snapshots__/svelte.test.ts.snap | 36 ++++ .../__tests__/__snapshots__/taro.test.ts.snap | 48 +++++ .../vue-composition.test.ts.snap | 36 ++++ .../__tests__/__snapshots__/vue.test.ts.snap | 52 +++++ .../__snapshots__/webcomponent.test.ts.snap | 196 ++++++++++++++++++ .../data/store-async-function.raw.tsx | 17 ++ packages/core/src/__tests__/test-generator.ts | 2 + .../core/src/generators/qwik/helpers/state.ts | 21 +- .../core/src/generators/react/generator.ts | 3 +- packages/core/src/parsers/jsx/state.ts | 45 ++++ 35 files changed, 1935 insertions(+), 10 deletions(-) create mode 100644 .changeset/great-phones-exist.md create mode 100644 packages/core/src/__tests__/data/store-async-function.raw.tsx diff --git a/.changeset/great-phones-exist.md b/.changeset/great-phones-exist.md new file mode 100644 index 0000000000..39f826e2df --- /dev/null +++ b/.changeset/great-phones-exist.md @@ -0,0 +1,5 @@ +--- +'@builder.io/mitosis': patch +--- + +respect async with anonymous arrow function in state diff --git a/packages/core/src/__tests__/__snapshots__/alpine.test.ts.snap b/packages/core/src/__tests__/__snapshots__/alpine.test.ts.snap index 6789407d19..2f6f8d96c9 100644 --- a/packages/core/src/__tests__/__snapshots__/alpine.test.ts.snap +++ b/packages/core/src/__tests__/__snapshots__/alpine.test.ts.snap @@ -2629,6 +2629,26 @@ exports[`Alpine.js > jsx > Javascript Test > spreadProps 1`] = ` " `; +exports[`Alpine.js > jsx > Javascript Test > store-async-function 1`] = ` +"
+ +" +`; + exports[`Alpine.js > jsx > Javascript Test > string-literal-store 1`] = ` "
+" +`; + exports[`Alpine.js > jsx > Typescript Test > string-literal-store 1`] = ` "
+ +
" +`; + exports[`Svelte > jsx > Javascript Test > string-literal-store 1`] = ` " + +
" +`; + exports[`Svelte > jsx > Typescript Test > string-literal-store 1`] = ` "" +`; + exports[`Vue > jsx > Javascript Test > string-literal-store 1`] = ` "" `; +exports[`Vue > jsx > Typescript Test > store-async-function 1`] = ` +" + +" +`; + exports[`Vue > jsx > Typescript Test > string-literal-store 1`] = ` "