From 9bff4f2d72f19310c41e78da3788223b70b4f068 Mon Sep 17 00:00:00 2001
From: Dave Long <dave@longwaveconsulting.com>
Date: Wed, 27 Nov 2024 09:26:08 +0000
Subject: [PATCH] Issue #3488365 by andypost: Upgrade twig/twig to 3.15.0

---
 composer.lock                                    | 16 ++++++++--------
 .../Metapackage/CoreRecommended/composer.json    |  2 +-
 core/composer.json                               |  2 +-
 .../Core/Template/ComponentNodeVisitor.php       | 11 ++++++-----
 core/lib/Drupal/Core/Template/TwigNodeTrans.php  |  6 ++++--
 .../lib/Drupal/Core/Template/TwigNodeVisitor.php |  3 ++-
 .../TwigNodeVisitorCheckDeprecations.php         |  3 ++-
 .../src/Twig/NodeVisitor/TestNodeVisitor.php     |  5 +++--
 8 files changed, 27 insertions(+), 21 deletions(-)

diff --git a/composer.lock b/composer.lock
index ced3b6c27d75..17aab695a202 100644
--- a/composer.lock
+++ b/composer.lock
@@ -496,7 +496,7 @@
             "dist": {
                 "type": "path",
                 "url": "core",
-                "reference": "60fa149dea68d06e2de45c93bf07d1d94b5394e7"
+                "reference": "7369e7a4e89825b0e5c1c8c3a4beaa3a18e5f3ef"
             },
             "require": {
                 "asm89/stack-cors": "^2.1",
@@ -541,7 +541,7 @@
                 "symfony/serializer": "^6.4",
                 "symfony/validator": "^6.4",
                 "symfony/yaml": "^6.4",
-                "twig/twig": "^3.14.2"
+                "twig/twig": "^3.15.0"
             },
             "conflict": {
                 "drush/drush": "<12.4.3"
@@ -4347,16 +4347,16 @@
         },
         {
             "name": "twig/twig",
-            "version": "v3.14.2",
+            "version": "v3.15.0",
             "source": {
                 "type": "git",
                 "url": "https://github.com/twigphp/Twig.git",
-                "reference": "0b6f9d8370bb3b7f1ce5313ed8feb0fafd6e399a"
+                "reference": "2d5b3964cc21d0188633d7ddce732dc8e874db02"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/twigphp/Twig/zipball/0b6f9d8370bb3b7f1ce5313ed8feb0fafd6e399a",
-                "reference": "0b6f9d8370bb3b7f1ce5313ed8feb0fafd6e399a",
+                "url": "https://api.github.com/repos/twigphp/Twig/zipball/2d5b3964cc21d0188633d7ddce732dc8e874db02",
+                "reference": "2d5b3964cc21d0188633d7ddce732dc8e874db02",
                 "shasum": ""
             },
             "require": {
@@ -4410,7 +4410,7 @@
             ],
             "support": {
                 "issues": "https://github.com/twigphp/Twig/issues",
-                "source": "https://github.com/twigphp/Twig/tree/v3.14.2"
+                "source": "https://github.com/twigphp/Twig/tree/v3.15.0"
             },
             "funding": [
                 {
@@ -4422,7 +4422,7 @@
                     "type": "tidelift"
                 }
             ],
-            "time": "2024-11-07T12:36:22+00:00"
+            "time": "2024-11-17T15:59:19+00:00"
         }
     ],
     "packages-dev": [
diff --git a/composer/Metapackage/CoreRecommended/composer.json b/composer/Metapackage/CoreRecommended/composer.json
index 8c97197e692a..043b660bbae5 100644
--- a/composer/Metapackage/CoreRecommended/composer.json
+++ b/composer/Metapackage/CoreRecommended/composer.json
@@ -61,6 +61,6 @@
         "symfony/var-dumper": "~v6.4.15",
         "symfony/var-exporter": "~v6.4.13",
         "symfony/yaml": "~v6.4.13",
-        "twig/twig": "~v3.14.2"
+        "twig/twig": "~v3.15.0"
     }
 }
diff --git a/core/composer.json b/core/composer.json
index d4ae3a935efd..52681368e31f 100644
--- a/core/composer.json
+++ b/core/composer.json
@@ -33,7 +33,7 @@
         "symfony/process": "^6.4",
         "symfony/polyfill-iconv": "^1.26",
         "symfony/yaml": "^6.4",
-        "twig/twig": "^3.14.2",
+        "twig/twig": "^3.15.0",
         "doctrine/annotations": "^1.14",
         "guzzlehttp/guzzle": "^7.5",
         "guzzlehttp/psr7": "^2.4.5",
diff --git a/core/lib/Drupal/Core/Template/ComponentNodeVisitor.php b/core/lib/Drupal/Core/Template/ComponentNodeVisitor.php
index 6b67035a7a5f..2d55d0c42759 100644
--- a/core/lib/Drupal/Core/Template/ComponentNodeVisitor.php
+++ b/core/lib/Drupal/Core/Template/ComponentNodeVisitor.php
@@ -9,6 +9,7 @@
 use Drupal\Core\Render\Component\Exception\InvalidComponentException;
 use Drupal\Core\Theme\ComponentPluginManager;
 use Twig\Environment;
+use Twig\Node\Nodes;
 use Twig\TwigFunction;
 use Twig\Node\Expression\ConstantExpression;
 use Twig\Node\Expression\FunctionExpression;
@@ -57,24 +58,24 @@ public function leaveNode(Node $node, Environment $env): ?Node {
     }
     $print_nodes[] = new PrintNode(new FunctionExpression(
       new TwigFunction('attach_library', [$env->getExtension(TwigExtension::class), 'attachLibrary']),
-      new Node([new ConstantExpression($component->getLibraryName(), $line)]),
+      new Nodes([new ConstantExpression($component->getLibraryName(), $line)]),
       $line
     ), $line);
     $print_nodes[] = new PrintNode(new FunctionExpression(
       new TwigFunction('add_component_context', [$env->getExtension(ComponentsTwigExtension::class), 'addAdditionalContext'], ['needs_context' => TRUE]),
-      new Node([new ConstantExpression($component_id, $line)]),
+      new Nodes([new ConstantExpression($component_id, $line)]),
       $line
     ), $line);
     $print_nodes[] = new PrintNode(new FunctionExpression(
       new TwigFunction('validate_component_props', [$env->getExtension(ComponentsTwigExtension::class), 'validateProps'], ['needs_context' => TRUE]),
-      new Node([new ConstantExpression($component_id, $line)]),
+      new Nodes([new ConstantExpression($component_id, $line)]),
       $line
     ), $line);
 
     // Append the print nodes to the display_start node.
     $node->setNode(
       'display_start',
-      new Node([
+      new Nodes([
         $node->getNode('display_start'),
         ...$print_nodes,
       ]),
@@ -84,7 +85,7 @@ public function leaveNode(Node $node, Environment $env): ?Node {
       // Append the closing comment to the display_end node.
       $node->setNode(
         'display_end',
-        new Node([
+        new Nodes([
           new PrintNode(new ConstantExpression(sprintf('<!-- %s Component end: %s -->', $emoji, $component_id), $line), $line),
           $node->getNode('display_end'),
         ])
diff --git a/core/lib/Drupal/Core/Template/TwigNodeTrans.php b/core/lib/Drupal/Core/Template/TwigNodeTrans.php
index 0ac6b93ed5a8..801fd7ec48a1 100644
--- a/core/lib/Drupal/Core/Template/TwigNodeTrans.php
+++ b/core/lib/Drupal/Core/Template/TwigNodeTrans.php
@@ -13,7 +13,9 @@
 use Twig\Node\Expression\GetAttrExpression;
 use Twig\Node\Expression\NameExpression;
 use Twig\Node\Expression\TempNameExpression;
+use Twig\Node\Expression\Variable\ContextVariable;
 use Twig\Node\Node;
+use Twig\Node\Nodes;
 use Twig\Node\PrintNode;
 
 /**
@@ -178,7 +180,7 @@ protected function compileString(Node $body) {
             if (!is_null($args)) {
               $argName = $args->getAttribute('name');
             }
-            $expr = new NameExpression($argName, $n->getTemplateLine());
+            $expr = new ContextVariable($argName, $n->getTemplateLine());
           }
           $placeholder = sprintf('%s%s', $argPrefix, $argName);
           $text .= $placeholder;
@@ -198,7 +200,7 @@ protected function compileString(Node $body) {
     }
 
     return [
-      new Node([new ConstantExpression(trim($text), $body->getTemplateLine())]),
+      new Nodes([new ConstantExpression(trim($text), $body->getTemplateLine())]),
       $tokens,
     ];
   }
diff --git a/core/lib/Drupal/Core/Template/TwigNodeVisitor.php b/core/lib/Drupal/Core/Template/TwigNodeVisitor.php
index e4755fcdec2b..64ed90fa4803 100644
--- a/core/lib/Drupal/Core/Template/TwigNodeVisitor.php
+++ b/core/lib/Drupal/Core/Template/TwigNodeVisitor.php
@@ -3,6 +3,7 @@
 namespace Drupal\Core\Template;
 
 use Twig\Environment;
+use Twig\Node\Nodes;
 use Twig\TwigFunction;
 use Twig\Node\Expression\FilterExpression;
 use Twig\Node\Expression\FunctionExpression;
@@ -50,7 +51,7 @@ public function leaveNode(Node $node, Environment $env): ?Node {
       return new $class(
         new FunctionExpression(
           new TwigFunction('render_var', [$env->getExtension(TwigExtension::class), 'renderVar']),
-          new Node([$node->getNode('expr')]),
+          new Nodes([$node->getNode('expr')]),
           $line
         ),
         $line
diff --git a/core/lib/Drupal/Core/Template/TwigNodeVisitorCheckDeprecations.php b/core/lib/Drupal/Core/Template/TwigNodeVisitorCheckDeprecations.php
index 1ee7efa5d8c3..5f8e17572b4a 100644
--- a/core/lib/Drupal/Core/Template/TwigNodeVisitorCheckDeprecations.php
+++ b/core/lib/Drupal/Core/Template/TwigNodeVisitorCheckDeprecations.php
@@ -7,6 +7,7 @@
 use Twig\Node\Expression\NameExpression;
 use Twig\Node\ModuleNode;
 use Twig\Node\Node;
+use Twig\Node\Nodes;
 use Twig\NodeVisitor\NodeVisitorInterface;
 
 /**
@@ -59,7 +60,7 @@ public function leaveNode(Node $node, Environment $env): ?Node {
     // At the end of the template, check the used variables are not deprecated.
     if ($node instanceof ModuleNode) {
       if (!empty($this->usedNames)) {
-        $checkNode = new Node([new TwigNodeCheckDeprecations($this->usedNames), $node->getNode('display_end')]);
+        $checkNode = new Nodes([new TwigNodeCheckDeprecations($this->usedNames), $node->getNode('display_end')]);
         $node->setNode('display_end', $checkNode);
       }
     }
diff --git a/core/modules/system/tests/modules/sdc_other_node_visitor/src/Twig/NodeVisitor/TestNodeVisitor.php b/core/modules/system/tests/modules/sdc_other_node_visitor/src/Twig/NodeVisitor/TestNodeVisitor.php
index 8e3305b83315..0224554073af 100644
--- a/core/modules/system/tests/modules/sdc_other_node_visitor/src/Twig/NodeVisitor/TestNodeVisitor.php
+++ b/core/modules/system/tests/modules/sdc_other_node_visitor/src/Twig/NodeVisitor/TestNodeVisitor.php
@@ -7,6 +7,7 @@
 use Twig\Environment;
 use Twig\Node\ModuleNode;
 use Twig\Node\Node;
+use Twig\Node\Nodes;
 use Twig\NodeVisitor\NodeVisitorInterface;
 
 /**
@@ -44,11 +45,11 @@ public function enterNode(Node $node, Environment $env): Node {
    */
   public function leaveNode(Node $node, Environment $env): ?Node {
     if ($node instanceof ModuleNode) {
-      $node->setNode('display_start', new Node([
+      $node->setNode('display_start', new Nodes([
         new EnterProfileNode($this->extensionName, $this->varName),
         $node->getNode('display_start'),
       ]));
-      $node->setNode('display_end', new Node([
+      $node->setNode('display_end', new Nodes([
         new LeaveProfileNode($this->varName),
         $node->getNode('display_end'),
       ]));
-- 
GitLab