You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix value property to return undefined for nodes without value concept (#260)
## Summary
Fixed a regression where certain CSS node types were incorrectly
returning `null` instead of `undefined` for their `value` property. This
distinction is semantically important: `null` means "has a value, but it
is absent", while `undefined` means "value is not a property of this
node type".
## Key Changes
- **Updated `CSSNode.value` getter** in `src/css-node.ts` to explicitly
return `undefined` for node types that don't have a value concept,
rather than attempting to read from the arena value fields
- **Added comprehensive regression tests** in `src/api.test.ts` covering
20+ node types that should return `undefined` for their value property,
including:
- Structural nodes: StyleSheet, Rule, Block, SelectorList, Selector
- Selector types: TypeSelector, ClassSelector, IdSelector,
PseudoClassSelector, PseudoElementSelector, UniversalSelector,
Combinator, Nth
- Value nodes: Value, Identifier, Hash, String
- At-rule nodes: Atrule, MediaQuery
- Other nodes: Raw
## Implementation Details
The fix adds an explicit type check that returns `undefined` early for
all node types except the five that actually store values in the arena:
- `DECLARATION`
- `FUNCTION`
- `ATTRIBUTE_SELECTOR`
- `SUPPORTS_QUERY`
- `PRELUDE_SELECTORLIST`
This ensures the correct semantic distinction between nodes that have no
value concept (undefined) and nodes that have a value but it's empty
(null).
https://claude.ai/code/session_01KETKttcckhFQtg8JzjxvuU
---------
Co-authored-by: Claude <noreply@anthropic.com>
0 commit comments