Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions packages/cli/src/linter/model/handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,4 +356,66 @@ describe('ModelHandler', () => {
}
});
});

// ── Fix #42: numeric component props crash model builder ──────────
describe('numeric component property values', () => {
it('does not crash when fontWeight is a bare number', () => {
const result = handler.execute(makeParsed({
colors: { primary: '#000000' },
components: {
'button-primary': {
backgroundColor: '{colors.primary}',
fontWeight: 600 as unknown as string,
},
},
}));
expect(result.findings.filter(f => f.severity === 'error')).toHaveLength(0);
const btn = result.designSystem.components.get('button-primary');
expect(btn).toBeDefined();
expect(btn?.properties.get('fontWeight')).toBe(600);
});

it('stores numeric fontWeight value as-is in component properties', () => {
const result = handler.execute(makeParsed({
components: {
'heading': {
fontWeight: 700 as unknown as string,
},
},
}));
const heading = result.designSystem.components.get('heading');
expect(heading?.properties.get('fontWeight')).toBe(700);
});

it('does not crash when borderWidth is a bare number', () => {
const result = handler.execute(makeParsed({
components: {
'card': {
borderWidth: 1 as unknown as string,
},
},
}));
expect(result.findings.filter(f => f.severity === 'error')).toHaveLength(0);
const card = result.designSystem.components.get('card');
expect(card?.properties.get('borderWidth')).toBe(1);
});

it('handles mixed numeric and string props in same component without crashing', () => {
const result = handler.execute(makeParsed({
colors: { primary: '#ff0000' },
spacing: { md: '16px' },
components: {
'button': {
fontWeight: 600 as unknown as string,
backgroundColor: '{colors.primary}',
padding: '{spacing.md}',
borderRadius: '4px',
},
},
}));
expect(result.findings.filter(f => f.severity === 'error')).toHaveLength(0);
const btn = result.designSystem.components.get('button');
expect(btn?.properties.get('fontWeight')).toBe(600);
});
});
});
8 changes: 7 additions & 1 deletion packages/cli/src/linter/model/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,13 @@ export class ModelHandler implements ModelSpec {
const unresolvedRefs: string[] = [];

for (const [propName, rawValue] of Object.entries(props)) {
if (isTokenReference(rawValue)) {
// Numeric values (e.g. fontWeight: 600, borderWidth: 1) are valid
// per spec and must be stored as-is, coercing to string first
// would cause isTokenReference / isValidColor to call .match() on
// a number and crash with "raw.match is not a function".
if (typeof rawValue === 'number') {
properties.set(propName, rawValue);
} else if (isTokenReference(rawValue)) {
const refPath = rawValue.slice(1, -1);
const resolved = resolveReference(symbolTable, refPath, new Set());
if (resolved !== null) {
Expand Down
Loading