diff --git a/packages/weapp-tailwindcss/src/uni-app-x/transform.ts b/packages/weapp-tailwindcss/src/uni-app-x/transform.ts index 4e7fdc776..9817d40c4 100644 --- a/packages/weapp-tailwindcss/src/uni-app-x/transform.ts +++ b/packages/weapp-tailwindcss/src/uni-app-x/transform.ts @@ -346,7 +346,7 @@ export function transformUVue( }) } - if (descriptor.script) { + if (descriptor.script && descriptor.script.start < descriptor.script.end) { localStyleCollector?.collectRuntimeClasses(descriptor.script.content) const { code } = jsHandler(descriptor.script.content, runtimeSet ?? new Set(), defaultCreateJsHandlerOptions) ms.update( @@ -355,7 +355,7 @@ export function transformUVue( localStyleCollector ? localStyleCollector.rewriteTransformedCode(code) : code, ) } - if (descriptor.scriptSetup) { + if (descriptor.scriptSetup && descriptor.scriptSetup.start < descriptor.scriptSetup.end) { localStyleCollector?.collectRuntimeClasses(descriptor.scriptSetup.content) const { code } = jsHandler(descriptor.scriptSetup.content, runtimeSet ?? new Set(), defaultCreateJsHandlerOptions) ms.update( diff --git a/packages/weapp-tailwindcss/test/uni-app-x/index.test.ts b/packages/weapp-tailwindcss/test/uni-app-x/index.test.ts index 74cd130c9..6930eb486 100644 --- a/packages/weapp-tailwindcss/test/uni-app-x/index.test.ts +++ b/packages/weapp-tailwindcss/test/uni-app-x/index.test.ts @@ -96,6 +96,16 @@ const label = 'hi' expect(jsHandler).toHaveBeenCalled() }) + it('ignores empty external WXS script blocks', () => { + const jsHandler: JsHandler = vi.fn(source => ({ code: source })) + const code = ` +` + + const result = transformUVue(code, 'external-wxs.uvue', jsHandler, new Set()) + expect(result?.code).toBe(code) + expect(jsHandler).not.toHaveBeenCalled() + }) + it('transforms object literal class bindings with whitespace', () => { const { jsHandler } = getCompilerContext() const runtimeSet = new Set([