You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
bug #1199 [TwigComponent] Fix twig:lint bug with anonymous component tag (smnandre)
This PR was squashed before being merged into the 2.x branch.
Discussion
----------
[TwigComponent] Fix twig:lint bug with anonymous component tag
| Q | A
| ------------- | ---
| Bug fix? | yes
| New feature? | no
| Tickets | Fix#1089
| License | MIT
Sincerely i'm not sure how to handle this properly "today"..
There is a lot of things i'd like to refactor in a future version, and the fact than auto-closing tags and classic ones are handled by two entirely different processes is at the top of my todo :)
But right now, i'm not sure we can do better than a quick patch, allowing the "lint:twig" to not crash for anonymous <twig:Foo></twig:Foo> tags.
Timeline of what "bugs":
- the lint:twig command find all templates, and for each one create an empty template loader, then parse & compile the template
- during the parsing, the ComponentParser calls [ComponentFactory::metadataFor](https://github.com/symfony/ux/blob/46d0b6885830b8cf546cd2c2479be2024f154ed3/src/TwigComponent/src/Twig/ComponentTokenParser.php#L50) to find the template matching the component name
- if no class-based component matches, the ComponentFactory calls the the [ComponentTemplateFinder](https://github.com/symfony/ux/blob/2.x/src/TwigComponent/src/ComponentTemplateFinder.php)
- the ComponentTemplateFinder then asks the Loader if a matching template exists
- but as the Loader is temporary "empty".... 🐞
So we must ether:
- A) stop resolving template during the parser/compiler work
- B) ensure the TemplateFinder always contains the real "full" loader
- C) change the way the lint:twig command works
A is my long-term objective, but clearly not "today".
C is not so easy, as the corresponding code is hidden between 3 private methods
So.... first suggestion (dirty but working)
Commits
-------
632954e [TwigComponent] Fix twig:lint bug with anonymous component tag
trigger_deprecation('symfony/ux-twig-component', '2.13', 'The "%s()" method will require "%s $loader" as first argument in 3.0. Passing an "Environment" instance is deprecated.', __METHOD__, LoaderInterface::class);
30
+
$loader = $loader->getLoader();
31
+
}
32
+
$this->loader = $loader;
25
33
if (null === $this->directory) {
26
34
trigger_deprecation('symfony/ux-twig-component', '2.13', 'The "%s()" method will require "string $directory" argument in 3.0. Not defining it or passing null is deprecated.', __METHOD__);
$this->expectDeprecation('Since symfony/ux-twig-component 2.13: The "Symfony\UX\TwigComponent\ComponentTemplateFinder::__construct()" method will require "Twig\Loader\LoaderInterface $loader" as first argument in 3.0. Passing an "Environment" instance is deprecated.');
0 commit comments