Skip to content

[FEATURE] Add consumeWhitespaceWithComments and redirect consumeWhitespace (backported) #670

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: v8.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -7,10 +7,16 @@ This project adheres to [Semantic Versioning](https://semver.org/).

### Added

- Add `ParserState::consumeWhiteSpaceWithComments()` method (#670)

### Changed

- Redirect `ParserState::consumeWhiteSpace()` to `ParserState::consumeWhiteSpaceWithComments()` (#670)

### Deprecated

- Deprecate `ParserState::consumeWhiteSpace()` in favor of `ParserState::consumeWhiteSpaceWithComments()` (#670)

### Removed

### Fixed
25 changes: 24 additions & 1 deletion src/Parsing/ParserState.php
Original file line number Diff line number Diff line change
@@ -226,12 +226,35 @@ public function parseCharacter($bIsForIdentifier)
}

/**
* @return array<int, Comment>|void
* Consumes whitespace and comments and returns a list of comments.
*
* @return list<Comment> List of comments.
*
* @throws UnexpectedEOFException
* @throws UnexpectedTokenException
*
* @deprecated From version 9.0.0 onwards this method will be undergo a breaking
* change. This method will no longer consume comments, only whitespace.
* Use `ParserState::consumeWhiteSpaceWithComments` as a replacement if you
* need the former behaviour of consuming whitespace and comments.
*
* @see `ParserState::consumeWhiteSpaceWithComments` for a version that also
* returns comments.
*/
public function consumeWhiteSpace()
{
return $this->consumeWhiteSpaceWithComments();
}

/**
* Consumes whitespace and comments and returns a list of comments.
*
* @return list<Comment> List of comments.
*
* @throws UnexpectedEOFException
* @throws UnexpectedTokenException
*/
public function consumeWhiteSpaceWithComments()
{
$aComments = [];
do {