Skip to content

Commit

Permalink
PreviousConnectingVisitor: Utilize WeakReference (#730)
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm authored Dec 30, 2024
1 parent 675388c commit 525a9fa
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/Ast/ExpressionFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ private function findFirstPreviousOfNode(Node $node, callable $filter): ?Node
// move to previous expression
$previousStatement = $node->getAttribute(PreviousConnectingVisitor::ATTRIBUTE_PREVIOUS);
if (null !== $previousStatement) {
if ($previousStatement instanceof \WeakReference) {
$previousStatement = $previousStatement->get();
}

if (! $previousStatement instanceof Node) {
throw new ShouldNotHappenException();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Ast/PreviousConnectingVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function enterNode(Node $node)
&& ! $this->previous instanceof Node\Stmt\ClassLike
&& ! $this->previous instanceof VirtualNode
) {
$node->setAttribute(self::ATTRIBUTE_PREVIOUS, $this->previous);
$node->setAttribute(self::ATTRIBUTE_PREVIOUS, \WeakReference::create($this->previous));
}

return null;
Expand Down

0 comments on commit 525a9fa

Please sign in to comment.