From 605faab020945e9d628e88ac5af34a663eac73ce Mon Sep 17 00:00:00 2001 From: Sreetam Das Date: Fri, 5 May 2023 10:17:32 +0530 Subject: [PATCH] Update `hasLoadDeclaration` regex for assigned type --- packages/sveltekit/src/vite/autoInstrument.ts | 4 +++- packages/sveltekit/test/vite/autoInstrument.test.ts | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/sveltekit/src/vite/autoInstrument.ts b/packages/sveltekit/src/vite/autoInstrument.ts index c30299c6b8a3..136d1fef0148 100644 --- a/packages/sveltekit/src/vite/autoInstrument.ts +++ b/packages/sveltekit/src/vite/autoInstrument.ts @@ -98,7 +98,9 @@ export async function canWrapLoad(id: string, debug: boolean): Promise debug && console.log(`Skipping wrapping ${id} because it already contains Sentry code`); } - const hasLoadDeclaration = /((const|let|var|function)\s+load\s*(=|\())|as\s+load\s*(,|})/gm.test(codeWithoutComments); + const hasLoadDeclaration = /((const|let|var|function)\s+load\s*(=|\(|:))|as\s+load\s*(,|})/gm.test( + codeWithoutComments, + ); if (!hasLoadDeclaration) { // eslint-disable-next-line no-console debug && console.log(`Skipping wrapping ${id} because it doesn't declare a \`load\` function`); diff --git a/packages/sveltekit/test/vite/autoInstrument.test.ts b/packages/sveltekit/test/vite/autoInstrument.test.ts index bc1f8d13adb8..0b5599912e7a 100644 --- a/packages/sveltekit/test/vite/autoInstrument.test.ts +++ b/packages/sveltekit/test/vite/autoInstrument.test.ts @@ -176,6 +176,12 @@ describe('canWrapLoad', () => { async function somethingElse(){}; export { somethingElse as load, foo }`, ], + + [ + 'export variable declaration - inline function with assigned type', + `import type { LayoutLoad } from './$types'; + export const load : LayoutLoad = async () => { return { props: { msg: "hi" } } }`, + ], ])('returns `true` if a load declaration (%s) exists and no Sentry code was found', async (_, code) => { fileContent = code; expect(await canWrapLoad('+page.ts', false)).toEqual(true);