Repository navigation
feat!: rename next_token_fast to next_token and drop the Token-returning next_token - #321
Merged
Merged
Conversation
…ing next_token Lexer.next_token() now returns the token type and exposes the position via token_start, token_end, token_line and token_column. tokenize() still yields Token objects.
Contributor
🎉 Package Size Decrease
|
commit: |
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
Lexerhad two ways to advance:next_token_fast()(returns the token type, no allocation) andnext_token()(wraps the former and allocates aTokenobject "for backwards compatibility"). This removes the wrapper and gives the fast method the plain name.Lexer.next_token(skip_whitespace?)now returns aTokenTypenumber.Lexer.next_token_fastis removed.tokenize()is unchanged for consumers: it still yieldsTokenobjects, now built directly from the lexer's position fields.next_token.tokenize.test.tsuses a small localnext(lexer)helper to keep itsToken-shaped assertions.Breaking change / migration
Only affects code that uses
Lexerdirectly (the@projectwallace/css-parser/tokenizersubpath).tokenize()users need no changes.1. Old
next_token()(returned aToken | null)Position fields on the lexer after each call:
token_start,token_end,token_line,token_column. If you need a standalone object, build it yourself:Note the old method's
nullreturn never actually occurred; end of input is signalled byTOKEN_EOF, as before.2.
next_token_fast()Just rename the call.
Verification
vitest run(1496 tests),tsc --noEmit,oxlint/oxfmt --checkandknipall pass.Generated by Claude Code