Fix value property to return undefined for nodes without value concept#260
Merged
Conversation
…lue concept Node types like SelectorList, TypeSelector, Selector, Block, etc. have no value property in their type definitions. The value getter was falling through to the arena lookup and returning null (length === 0) for these nodes when it should return undefined, since null signals "has a value field but it is absent" while undefined signals "value is not a property of this node type at all". Added a guard in the value getter so only DECLARATION, FUNCTION, ATTRIBUTE_SELECTOR, SUPPORTS_QUERY, and PRELUDE_SELECTORLIST reach the arena value_start/value_length lookup. All other types now correctly return undefined. Added 20 regression tests covering the reported node types and representatives from every category (structural, selector, value, at-rule). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KETKttcckhFQtg8JzjxvuU
Contributor
|
| 📦 Package | 📋 Versions |
|---|---|
| tinybench | 2 versions
|
| @babel/helper-validator-identifier | 2 versions
|
| js-tokens | 2 versions
|
| @babel/parser | 2 versions
|
| @babel/types | 2 versions
|
| @babel/helper-string-parser | 2 versions
|
| @emnapi/core | 3 versions
|
| @emnapi/wasi-threads | 2 versions
|
| @emnapi/runtime | 3 versions
|
| @rolldown/binding-wasm32-wasi | 2 versions
|
| obug | 2 versions
|
| picomatch | 2 versions
|
| postcss-value-parser | 2 versions
|
| glob-parent | 2 versions
|
| yaml | 2 versions
|
| is-arrayish | 2 versions
|
| get-tsconfig | 2 versions
|
| semver | 2 versions
|
| @oxc-project/types | 2 versions
|
| rolldown | 2 versions
|
| @rolldown/binding-android-arm64 | 2 versions
|
| @rolldown/binding-darwin-arm64 | 2 versions
|
| @rolldown/binding-darwin-x64 | 2 versions
|
| @rolldown/binding-freebsd-x64 | 2 versions
|
| @rolldown/binding-linux-arm-gnueabihf | 2 versions
|
| @rolldown/binding-linux-arm64-gnu | 2 versions
|
| @rolldown/binding-linux-arm64-musl | 2 versions
|
| @rolldown/binding-linux-ppc64-gnu | 2 versions
|
| @rolldown/binding-linux-s390x-gnu | 2 versions
|
| @rolldown/binding-linux-x64-gnu | 2 versions
|
| @rolldown/binding-linux-x64-musl | 2 versions
|
| @rolldown/binding-openharmony-arm64 | 2 versions
|
| @rolldown/binding-win32-arm64-msvc | 2 versions
|
| @rolldown/binding-win32-x64-msvc | 2 versions
|
| tinyexec | 2 versions
|
💡 To find out what depends on a specific package, run: pnpm -r why example-package
⚠️ Package Size Increase
| 📦 Package | 📏 Base Size | 📏 Source Size | 📈 Size Change |
|---|---|---|---|
| @projectwallace/css-parser | 41 kB | 41 kB | +12 B |
TypeScript correctly rejects .value access on types that omit the property (StyleSheet, Rule, SelectorList, etc.) — that's the whole point. Tests that verify the runtime getter returns undefined must cast through the base CSSNode class, which has the generic value getter. Use a local get_value() helper to avoid repeating the cast on every assertion. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KETKttcckhFQtg8JzjxvuU
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixed a regression where certain CSS node types were incorrectly returning
nullinstead ofundefinedfor theirvalueproperty. This distinction is semantically important:nullmeans "has a value, but it is absent", whileundefinedmeans "value is not a property of this node type".Key Changes
CSSNode.valuegetter insrc/css-node.tsto explicitly returnundefinedfor node types that don't have a value concept, rather than attempting to read from the arena value fieldssrc/api.test.tscovering 20+ node types that should returnundefinedfor their value property, including:Implementation Details
The fix adds an explicit type check that returns
undefinedearly for all node types except the five that actually store values in the arena:DECLARATIONFUNCTIONATTRIBUTE_SELECTORSUPPORTS_QUERYPRELUDE_SELECTORLISTThis 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