From 5382ad031b269b193a0715d7a3e22701e65ff0ce Mon Sep 17 00:00:00 2001 From: YashNayakk Date: Wed, 17 Jun 2026 14:02:15 +0530 Subject: [PATCH] fix: support spread properties in defineContentScript --- .../src/core/utils/__tests__/transform.test.ts | 15 +++++++++++++++ packages/wxt/src/core/utils/transform.ts | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/packages/wxt/src/core/utils/__tests__/transform.test.ts b/packages/wxt/src/core/utils/__tests__/transform.test.ts index f3f5326c3..3123b7d74 100644 --- a/packages/wxt/src/core/utils/__tests__/transform.test.ts +++ b/packages/wxt/src/core/utils/__tests__/transform.test.ts @@ -170,5 +170,20 @@ export default defineBackground();`; const actual = removeMainFunctionCode(input).code; expect(actual).toEqual(expected); }); + + it('should remove main field when object contains spread properties', () => { + const input = ` + export default defineContentScript({ + ...SHARED_CONFIG, + main: () => {}, + }) + `; + + const actual = removeMainFunctionCode(input).code; + + expect(actual).toContain('...SHARED_CONFIG'); + expect(actual).not.toContain('main:'); + }); + }); }); diff --git a/packages/wxt/src/core/utils/transform.ts b/packages/wxt/src/core/utils/transform.ts index 1a5fe50f5..90243c272 100644 --- a/packages/wxt/src/core/utils/transform.ts +++ b/packages/wxt/src/core/utils/transform.ts @@ -41,7 +41,7 @@ function emptyMainFunction(mod: ProxifiedModule): void { // ex: "fn({ ..., main: () => {} })" to "fn({ ... })" mod.exports.default.$ast.arguments[0].properties = mod.exports.default.$ast.arguments[0].properties.filter( - (prop: any) => prop.key.name !== 'main', + (prop: any) => prop.key?.name !== 'main', ); } }