From 0157ab628539812b9a7e6266912d5a3d83531e4d Mon Sep 17 00:00:00 2001 From: xuegan Date: Wed, 6 May 2026 19:56:48 +0800 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20css=20strip-conditional=20=E5=AF=B9?= =?UTF-8?q?=E4=BA=8EMpx=E6=96=87=E4=BB=B6=E6=B7=BB=E5=8A=A0 块(支持多个 style 块) + const styleRegex = /(]*>)([\s\S]*?)(<\/style>)/gi + let lastIndex = 0 + let result = '' + let match + + while ((match = styleRegex.exec(content)) !== null) { + // match.index 到 match[1] 结束前的内容为非 style 区域 + const beforeStyle = content.substring(lastIndex, match.index) + // 检测非 style 区域是否包含条件指令 + if (hasConditionalDirective(beforeStyle)) { + logStripError(path, new Error('@mpx conditional directives are only allowed inside ` + const result = stripConditionForMpx(input, defs) + expect(result).toContain('Hello') + expect(result).toContain('.wx-only { color: red; }') + expect(result).not.toContain('.ali-only { color: blue; }') + }) + + it('should handle multiple +` + const result = stripConditionForMpx(input, defs) + expect(result).toContain('.block1 { color: red; }') + expect(result).toContain('.block2 { background: #000; }') + expect(result).not.toContain('.block3 { background: #fff; }') + }) + + it('should return original content and log error when conditional directive appears in