diff --git a/composer.json b/composer.json index 829bcbcd..ef3bee69 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ "symfony/filesystem": "^5.4 || ^6.4 || ^7.0", "symfony/finder": "^5.4 || ^6.4 || ^7.0", "symfony/string": "^5.4.42 || ^6.4.10 || ~7.0.10 || ^7.1.3", - "twig/twig": "^3.10", + "twig/twig": "^3.4", "webmozart/assert": "^1.10" }, "require-dev": { diff --git a/src/Runner/Linter.php b/src/Runner/Linter.php index 8ea219de..d80da7b4 100644 --- a/src/Runner/Linter.php +++ b/src/Runner/Linter.php @@ -148,7 +148,7 @@ private function parseTemplate(string $content, string $filePath, Report $report try { $twigSource = new Source($content, $filePath); - return $this->env->parse($this->env->tokenize($twigSource)); + $node = $this->env->parse($this->env->tokenize($twigSource)); } catch (Error $error) { $violation = new Violation( Violation::LEVEL_FATAL, @@ -162,6 +162,14 @@ private function parseTemplate(string $content, string $filePath, Report $report return null; } + + // BC fix for twig/twig < 3.10. + $sourceContext = $node->getSourceContext(); + if (null !== $sourceContext) { + $node->setSourceContext($sourceContext); + } + + return $node; } private function setErrorHandler(Report $report, string $file): void diff --git a/tests/Environment/StubbedEnvironmentTest.php b/tests/Environment/StubbedEnvironmentTest.php index da26763b..2ed94a0e 100644 --- a/tests/Environment/StubbedEnvironmentTest.php +++ b/tests/Environment/StubbedEnvironmentTest.php @@ -126,10 +126,6 @@ public function testParse(): void public function testParseCacheTag(): void { - if (!InstalledVersions::satisfies(new VersionParser(), 'twig/twig', '>=3.2.0')) { - static::markTestSkipped('twig/twig ^3.2.0 is required.'); - } - $content = file_get_contents(__DIR__.'/Fixtures/cache_tag.html.twig'); static::assertNotFalse($content);