From 2251c9db5e6a544e0c8c0cf249eadb0202353c93 Mon Sep 17 00:00:00 2001 From: BEERINHO Date: Fri, 6 Dec 2024 16:00:37 +0100 Subject: [PATCH] Improve error handling of the async transform --- packages/core/vite.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/core/vite.ts b/packages/core/vite.ts index c0f9c9f..1eb87f1 100644 --- a/packages/core/vite.ts +++ b/packages/core/vite.ts @@ -5,6 +5,7 @@ import type { CallExpression, FunctionExpression, ImportDeclaration, + Program, } from 'acorn'; import type { Plugin } from 'vite'; @@ -25,11 +26,16 @@ export async function asyncTransform(): Promise { name: 'sheepdog-async-transform', async transform(code, id) { try { - const ast = parse(code, { - ecmaVersion: 'latest', - locations: true, - sourceType: 'module', - }); + let ast: Program; + try { + ast = parse(code, { + ecmaVersion: 'latest', + locations: true, + sourceType: 'module', + }); + } catch { + return; + } let task_fn_name: string; const transform_fn_names = new Set(); // let's walk once to find the name (we were using a promise before but that's just messy)