Skip to content

Commit

Permalink
Fix compatability issue with sveltekit-flash-messages (#1222)
Browse files Browse the repository at this point in the history
Co-authored-by: Alec Aivazis <[email protected]>
  • Loading branch information
eikaramba and AlecAivazis committed Oct 28, 2023
1 parent ae73932 commit 7ae3abc
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/selfish-turkeys-move.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'houdini-svelte': patch
---

Fix bug extending load functions that are wrapped by a utility
25 changes: 25 additions & 0 deletions packages/houdini-svelte/src/plugin/transforms/kit/session.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,31 @@ test('modifies root +layout.svelte with data prop', async function () {
`)
})

test('export const load', async function () {
const result = await test_transform_js(
'src/routes/+layout.server.js',
`
export const load = loadFlash(async () => {
"some random stuff that's valid javascript"
})
`
)

expect(result).toMatchInlineSnapshot(`
import { buildSessionObject } from "$houdini/plugins/houdini-svelte/runtime/session";
export const load = loadFlash(async event => {
"some random stuff that's valid javascript";
const __houdini__vite__plugin__return__value__ = {};
return {
...buildSessionObject(event),
...__houdini__vite__plugin__return__value__
};
});
`)
})

test('modifies root +layout.svelte without data prop', async function () {
// run the test
const result = await test_transform_svelte('src/routes/+layout.svelte', ``)
Expand Down
10 changes: 10 additions & 0 deletions packages/houdini/src/vite/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ export function find_exported_fn(
init = init.expression
}

//if the value is a CallExpression the actual FunctionExpression might reside inside the arguments array, see https://github.com/HoudiniGraphql/houdini/issues/1137
if (
init.type === 'CallExpression' &&
init.arguments[0] &&
(init.arguments[0].type === 'FunctionExpression' ||
init.arguments[0].type === 'ArrowFunctionExpression')
) {
init = init.arguments[0]
}

if (init.type === 'FunctionExpression' || init.type === 'ArrowFunctionExpression') {
return init
}
Expand Down

0 comments on commit 7ae3abc

Please sign in to comment.