From 848f9c3edfbfbfa0903f4dd76ee2fec1cfb12224 Mon Sep 17 00:00:00 2001 From: Vladimir Razuvaev Date: Tue, 25 Apr 2017 18:02:45 +0700 Subject: [PATCH] Preserve backwards compatibility of Ast\Node::toArray(): do shallow conversion by default --- src/Language/AST/Node.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Language/AST/Node.php b/src/Language/AST/Node.php index 05ffa03..3ce3be1 100644 --- a/src/Language/AST/Node.php +++ b/src/Language/AST/Node.php @@ -81,22 +81,26 @@ abstract class Node */ public function __toString() { - $tmp = $this->toArray(); + $tmp = $this->toArray(true); return json_encode($tmp); } /** + * @param bool $recursive * @return array */ - public function toArray() + public function toArray($recursive = false) { $tmp = (array) $this; + $tmp['loc'] = [ 'start' => $this->loc->start, 'end' => $this->loc->end ]; - $this->recursiveToArray($tmp); + if ($recursive) { + $this->recursiveToArray($tmp); + } return $tmp; } @@ -108,7 +112,7 @@ abstract class Node { if ($object instanceof Node) { /** @var Node $object */ - $object = $object->toArray(); + $object = $object->toArray(true); } elseif (is_object($object)) { $object = (array) $object; } elseif (is_array($object)) {