Skip to content

fix(parse): return undefined instead of throwing on invalid dimension#272

Open
spokodev wants to merge 1 commit into
Evercoder:mainfrom
spokodev:fix/parse-invalid-dimension-throws
Open

fix(parse): return undefined instead of throwing on invalid dimension#272
spokodev wants to merge 1 commit into
Evercoder:mainfrom
spokodev:fix/parse-invalid-dimension-throws

Conversation

@spokodev

@spokodev spokodev commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

parse() is documented to return undefined for input it cannot handle, but it threw a TypeError on valid CSS syntax that it does not support. num() returns undefined when a number is followed by a non-angle identifier, that undefined was pushed into the token stream, and consumeCoords later dereferenced it. Inputs such as parse('rgb(1px 2 3)'), parse('hsl(90DEG 100% 50%)'), and parse('rgb(1 2 3 / 1px)') threw Cannot read properties of undefined instead of returning undefined.

This guards the alpha dereference and returns undefined when the token stream contains a gap. Adds a test that the listed inputs return undefined rather than throw.

A number followed by an identifier that is not an angle unit made the
tokenizer emit an undefined token, which crashed consumeCoords with a
TypeError. parse() now returns undefined for such input, as it does for
other unparseable strings.
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.

1 participant