1414
1515use Twig \Attribute \FirstClassTwigCallableReady ;
1616use Twig \Error \SyntaxError ;
17+ use Twig \Node \EmptyNode ;
1718use Twig \Node \Expression \AbstractExpression ;
1819use Twig \Node \Expression \ArrayExpression ;
1920use Twig \Node \Expression \ArrowFunctionExpression ;
3233use Twig \Node \Expression \Unary \PosUnary ;
3334use Twig \Node \Expression \Unary \SpreadUnary ;
3435use Twig \Node \Node ;
36+ use Twig \Node \Nodes ;
3537
3638/**
3739 * Parses expressions.
@@ -110,7 +112,7 @@ private function parseArrow()
110112 $ names = [new AssignNameExpression ($ token ->getValue (), $ token ->getLine ())];
111113 $ stream ->expect (Token::ARROW_TYPE );
112114
113- return new ArrowFunctionExpression ($ this ->parseExpression (0 ), new Node ($ names ), $ line );
115+ return new ArrowFunctionExpression ($ this ->parseExpression (0 ), new Nodes ($ names ), $ line );
114116 }
115117
116118 // first, determine if we are parsing an arrow function by finding => (long form)
@@ -151,7 +153,7 @@ private function parseArrow()
151153 $ stream ->expect (Token::PUNCTUATION_TYPE , ') ' );
152154 $ stream ->expect (Token::ARROW_TYPE );
153155
154- return new ArrowFunctionExpression ($ this ->parseExpression (0 ), new Node ($ names ), $ line );
156+ return new ArrowFunctionExpression ($ this ->parseExpression (0 ), new Nodes ($ names ), $ line );
155157 }
156158
157159 private function getPrimary (): AbstractExpression
@@ -467,7 +469,7 @@ public function getFunctionNode($name, $line)
467469 $ function = $ this ->getFunction ($ name , $ line );
468470
469471 if ($ function ->getParserCallable ()) {
470- $ fakeNode = new Node (lineno: $ line );
472+ $ fakeNode = new EmptyNode ( $ line );
471473 $ fakeNode ->setSourceContext ($ this ->parser ->getStream ()->getSourceContext ());
472474
473475 return ($ function ->getParserCallable ())($ this ->parser , $ fakeNode , $ args , $ line );
@@ -556,7 +558,7 @@ public function parseSubscriptExpression($node)
556558 }
557559
558560 $ filter = $ this ->getFilter ('slice ' , $ token ->getLine ());
559- $ arguments = new Node ([$ arg , $ length ]);
561+ $ arguments = new Nodes ([$ arg , $ length ]);
560562 $ filter = new ($ filter ->getNodeClass ())($ node , $ filter , $ arguments , $ token ->getLine ());
561563
562564 $ stream ->expect (Token::PUNCTUATION_TYPE , '] ' );
@@ -587,7 +589,7 @@ public function parseFilterExpressionRaw($node)
587589 $ token = $ this ->parser ->getStream ()->expect (Token::NAME_TYPE );
588590
589591 if (!$ this ->parser ->getStream ()->test (Token::PUNCTUATION_TYPE , '( ' )) {
590- $ arguments = new Node ();
592+ $ arguments = new EmptyNode ();
591593 } else {
592594 $ arguments = $ this ->parseArguments (true , false , true );
593595 }
@@ -691,7 +693,7 @@ public function parseArguments($namedArguments = false, $definition = false, $al
691693 }
692694 $ stream ->expect (Token::PUNCTUATION_TYPE , ') ' , 'A list of arguments must be closed by a parenthesis ' );
693695
694- return new Node ($ args );
696+ return new Nodes ($ args );
695697 }
696698
697699 public function parseAssignmentExpression ()
@@ -717,7 +719,7 @@ public function parseAssignmentExpression()
717719 }
718720 }
719721
720- return new Node ($ targets );
722+ return new Nodes ($ targets );
721723 }
722724
723725 public function parseMultitargetExpression ()
@@ -730,7 +732,7 @@ public function parseMultitargetExpression()
730732 }
731733 }
732734
733- return new Node ($ targets );
735+ return new Nodes ($ targets );
734736 }
735737
736738 private function parseNotTestExpression (Node $ node ): NotUnary
@@ -747,7 +749,7 @@ private function parseTestExpression(Node $node): TestExpression
747749 if ($ stream ->test (Token::PUNCTUATION_TYPE , '( ' )) {
748750 $ arguments = $ this ->parseArguments (true );
749751 } elseif ($ test ->hasOneMandatoryArgument ()) {
750- $ arguments = new Node ([0 => $ this ->parsePrimaryExpression ()]);
752+ $ arguments = new Nodes ([0 => $ this ->parsePrimaryExpression ()]);
751753 }
752754
753755 if ('defined ' === $ test ->getName () && $ node instanceof NameExpression && null !== $ alias = $ this ->parser ->getImportedSymbol ('function ' , $ node ->getAttribute ('name ' ))) {
0 commit comments