Hypothesis
During AST construction, the parser processes tokens in several methods (decl, rule, atrule, other) that each independently handle whitespace/comment tokens. For a typical declaration, the token flow involves:
- Collect tokens in other() until reaching a boundary
- Call spacesAndCommentsFromEnd() — scans tokens backwards
- Call spacesAndCommentsFromStart() — scans tokens forwards
- Call raw() to extract the value — iterates tokens again
These three passes over the same token array are redundant. A single forward scan could extract before-spaces, the prop, between-spaces, the value, and after-spaces in one pass, populating all raws fields simultaneously.
Implement a single-pass token processor for the common declaration case:
// Single pass: scan tokens[0..n], partition into:
// before_spaces | prop_tokens | between_spaces | value_tokens | after_spaces
// Set all raws in one go
Editable surface
- lib/parser.js — single-pass token processing for common declaration/rule patterns
What's different from prior work
Expected impact
METRIC_A improvement of 2-4ms (large file, thousands of declarations). METRIC_B improvement of 2-4ms. Combined 3-5ms.
Hypothesis
During AST construction, the parser processes tokens in several methods (decl, rule, atrule, other) that each independently handle whitespace/comment tokens. For a typical declaration, the token flow involves:
These three passes over the same token array are redundant. A single forward scan could extract before-spaces, the prop, between-spaces, the value, and after-spaces in one pass, populating all raws fields simultaneously.
Implement a single-pass token processor for the common declaration case:
Editable surface
What's different from prior work
Expected impact
METRIC_A improvement of 2-4ms (large file, thousands of declarations). METRIC_B improvement of 2-4ms. Combined 3-5ms.