fix(design-system): DS-10 显式识别 var() fallback 为混合间距

审查指出:已登记变量带不含数字的合法 fallback(如
p-[var(--space-4,initial)])时,/\d/ 判定不到,被归为纯
spacing-expression,审阅者会误以为整个表达式都来自已验证间距源。

mixed 判定改为显式识别 var() 的 fallback(名字后带逗号),
initial、auto、嵌套 var 一律归 mixed-spacing-expression;
无 fallback 的纯 calc 派生表达式保持 spacing-expression。

Signed-off-by: Kirozeng <kirozeng@gmail.com>
This commit is contained in:
Kirozeng
2026-09-14 12:48:53 +08:00
parent 2f77214219
commit bf95bf72ac
2 changed files with 7 additions and 1 deletions

View File

@@ -145,6 +145,9 @@ test('spacing reports distinguish real generated references, unknown variables a
['p-[var(--size-input-lg)]', 'unknown-spacing-reference'],
['px-[calc(var(--space-4)+1px)]', 'mixed-spacing-expression'],
['p-[var(--space-4,13px)]', 'mixed-spacing-expression'],
['p-[var(--space-4,initial)]', 'mixed-spacing-expression'],
['p-[var(--space-4,auto)]', 'mixed-spacing-expression'],
['p-[var(--space-4,var(--space-2))]', 'mixed-spacing-expression'],
['p-[calc(var(--space-4)*2)]', 'mixed-spacing-expression'],
['gap-[calc(var(--space-4)-var(--space-2))]', 'spacing-expression'],
['p-[var(--space-4,var(--missing))]', 'unknown-spacing-reference'],

View File

@@ -55,7 +55,10 @@ function classifySpacing(value, spacingVariables = getSpacingVariables()) {
reason: 'Contains a variable outside the generated spacing bindings; verify its source, fallbacks and component role. A variable name alone is not approval.' };
}
if (references.length) {
const mixed = /\d/.test(expression.replace(/--[\w-]+/g, ''));
// A var() fallback is a second value even when it carries no digit
// (initial, auto, a nested var): recognise it explicitly, never by
// whether a digit happens to appear in the rest of the expression.
const mixed = /var\(\s*--[\w-]+\s*,/.test(expression) || /\d/.test(expression.replace(/--[\w-]+/g, ''));
return { classification: mixed ? 'mixed-spacing-expression' : 'spacing-expression',
reason: mixed ? 'Combines spacing references with literal values (including fallbacks); review each literal and the component role.'
: 'Derived spacing expression; verify the calculation and component role. References do not approve the whole expression.' };