@@ -48,9 +48,9 @@ closing marker or the symmetric ``##}`` marker:
4848 Documenting Variable Bindings
4949-----------------------------
5050
51- Inside a tag or expression , an inline documentation comment starts with ``## ``
52- and continues until the end of the line. It describes the variable binding that
53- starts on the next line.
51+ Inside a tag, an inline documentation comment starts with ``## `` and continues
52+ until the end of the line. It describes the variable binding that starts on the
53+ next line.
5454
5555Type Declarations
5656~~~~~~~~~~~~~~~~~
@@ -93,28 +93,6 @@ Each target in a multiple assignment can have its own documentation:
9393 = user.first_name, user.last_name
9494 %}
9595
96- The same syntax works with the assignment operator, including sequence and
97- object destructuring:
98-
99- .. code-block :: twig
100-
101- {{ (## The normalized result.
102- result = normalize(value)) }}
103-
104- {{ ([
105- ## The first coordinate.
106- x,
107- ## The second coordinate.
108- y,
109- ] = coordinates) }}
110-
111- {{ ({
112- name: ## The user's display name.
113- display_name,
114- ## The user's email address.
115- email,
116- } = user) }}
117-
11896 Loop Targets
11997~~~~~~~~~~~~
12098
@@ -145,32 +123,16 @@ Documentation comments can describe individual macro arguments:
145123 name,
146124 ## The initial field value.
147125 value = null,
148- ## Extra HTML attributes.
149- ...attributes,
150126 ) %}
151127 ...
152128 {% endmacro %}
153129
154- Arrow Function Arguments
155- ~~~~~~~~~~~~~~~~~~~~~~~~
156-
157- Documentation comments can also describe arrow function arguments:
158-
159- .. code-block :: twig
160-
161- {% set formatter = (
162- ## The value to format.
163- value,
164- ## The requested locale.
165- locale
166- ) => value|format(locale) %}
167-
168130 Attachment Rules
169131----------------
170132
171- A documentation comment applies to the next supported construct or variable
172- binding. Consecutive documentation comments are combined and separated by
173- newlines:
133+ A documentation comment is considered for the construct or variable binding
134+ that immediately follows it and attaches only when that position is supported.
135+ Consecutive documentation comments are combined and separated by newlines:
174136
175137.. code-block :: twig
176138
@@ -189,9 +151,12 @@ construct or variable must therefore start on a later line:
189151 page = 1
190152 %}
191153
192- Documentation comments in unsupported positions remain comments and do not
193- attach metadata. In particular, they do not document ordinary variable reads,
194- mapping keys, function arguments or named call arguments.
154+ Documentation comments are attached on a best-effort basis where Twig can
155+ associate them directly with a construct or declaration. Comments in other
156+ positions remain regular comments and expose no metadata. In particular, they
157+ do not document ordinary variable reads, mapping keys, function arguments,
158+ named call arguments, assignment operators, destructuring assignments, arrow
159+ function arguments or variadic macro arguments.
195160
196161Reading Documentation from Nodes
197162--------------------------------
@@ -207,5 +172,5 @@ metadata is stored on the semantic node represented by the source:
207172* variable-binding documentation is stored on the node representing its
208173 assignment target.
209174
210- Documentation is discarded when an optimization or a node visitor replaces a
211- supported node with an unsupported node.
175+ Documentation metadata belongs to its node and is not preserved when an
176+ optimization or a node visitor replaces that node.
0 commit comments