Skip to content

fix(model): handle numeric component prop values without crashing#43

Open
tejas100 wants to merge 1 commit intogoogle-labs-code:mainfrom
tejas100:fix/numeric-font-weight-crash
Open

fix(model): handle numeric component prop values without crashing#43
tejas100 wants to merge 1 commit intogoogle-labs-code:mainfrom
tejas100:fix/numeric-font-weight-crash

Conversation

@tejas100
Copy link
Copy Markdown
Contributor

Fixes #42

Problem

The lint command crashes with Unexpected error during model building: raw.match is not a function when a component defines a numeric prop like
fontWeight: 600 or borderWidth: 1. The spec explicitly states bare
numbers and quoted strings are equivalent, so this is a spec violation.

Root Cause

In Phase 3 of ModelHandler, all component prop values were passed
directly to isTokenReference() and isValidColor(), both of which call
.match() internally. When rawValue is a number, .match doesn't exist
— crash.

Fix

Added a typeof rawValue === 'number' guard at the top of the component
property loop, storing numeric values as-is. This mirrors the pattern
already used by parseTypography for the same property.

Tests

Added 4 new test cases covering:

  • fontWeight: 600 (exact repro from issue)
  • fontWeight: 700 stored correctly as a number
  • borderWidth: 1 (also mentioned in issue)
  • Mixed numeric + string + token ref props in one component

Numeric values such as fontWeight: 600 or borderWidth: 1 are valid per
the DESIGN.md spec, which states bare numbers and quoted strings are
equivalent. However, the component property loop in ModelHandler passed
all rawValues directly to isTokenReference / isValidColor, both of which
call .match() and crash when rawValue is a number.

Fix: add a typeof rawValue === 'number' guard at the top of the loop,
storing numeric values as-is — matching the pattern already used by
parseTypography for the same property.

Fixes google-labs-code#42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

lint: numeric fontWeight on components crashes model builder with "raw.match is not a function"

1 participant