Skip to content

Commit

Permalink
Factor file pos when hashing nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
Muqsit committed Sep 30, 2023
1 parent 98b8188 commit 331b337
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/ParsedFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,20 @@
final class ParsedFile{

public static function nodeHash(Node $node) : ?string{
$tokens = [$node->getLine(), $node->getStartLine(), $node->getEndLine(), $node->getStartTokenPos(), $node->getEndTokenPos()];
$add_non_expr_tokens = true;
$tokens = [
$node->getType(), $node->getLine(),
$node->getStartFilePos(), $node->getEndFilePos(),
$node->getStartLine(), $node->getEndLine(),
$node->getStartTokenPos(), $node->getEndTokenPos()
];
if($node instanceof Expr){
try{
static $printer = null;
$printer ??= new Standard();
$tokens[] = $printer->prettyPrintExpr($node);
$add_non_expr_tokens = false;
}catch(Error | Exception){
}
}
if($add_non_expr_tokens){
array_push($tokens, $node->getType(), $node->getStartLine(), $node->getEndLine(), $node->getStartTokenPos());
}
return implode(":", $tokens);
}

Expand Down

0 comments on commit 331b337

Please sign in to comment.