Commit d3ce11f
committed
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 tagFile tree
3 files changed
+34
-15
lines changed- src/TwigComponent
- src
- DependencyInjection
- tests/Unit
3 files changed
+34
-15
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| 22 | + | |
| 23 | + | |
21 | 24 | | |
22 | | - | |
| 25 | + | |
23 | 26 | | |
24 | 27 | | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
25 | 33 | | |
26 | 34 | | |
27 | 35 | | |
28 | 36 | | |
29 | 37 | | |
30 | 38 | | |
31 | 39 | | |
32 | | - | |
| 40 | + | |
33 | 41 | | |
34 | 42 | | |
35 | 43 | | |
| |||
Lines changed: 2 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
68 | | - | |
| 68 | + | |
69 | 69 | | |
70 | | - | |
71 | | - | |
72 | | - | |
| 70 | + | |
73 | 71 | | |
74 | 72 | | |
75 | 73 | | |
| |||
101 | 99 | | |
102 | 100 | | |
103 | 101 | | |
104 | | - | |
105 | | - | |
106 | 102 | | |
107 | 103 | | |
108 | 104 | | |
| |||
Lines changed: 22 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| |||
36 | 37 | | |
37 | 38 | | |
38 | 39 | | |
39 | | - | |
40 | | - | |
| 40 | + | |
| 41 | + | |
41 | 42 | | |
42 | 43 | | |
43 | 44 | | |
| |||
84 | 85 | | |
85 | 86 | | |
86 | 87 | | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
87 | 99 | | |
88 | 100 | | |
89 | 101 | | |
| |||
106 | 118 | | |
107 | 119 | | |
108 | 120 | | |
109 | | - | |
110 | | - | |
| 121 | + | |
| 122 | + | |
111 | 123 | | |
112 | 124 | | |
113 | 125 | | |
114 | 126 | | |
115 | 127 | | |
116 | 128 | | |
117 | | - | |
| 129 | + | |
118 | 130 | | |
119 | | - | |
| 131 | + | |
| 132 | + | |
120 | 133 | | |
121 | | - | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
122 | 137 | | |
123 | 138 | | |
0 commit comments