1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
// Member-only chain handling
//
// Handles chains that contain only member accesses (no calls), giving each
// lookup its own group — prettier's `printMemberExpression` shape.
use ;
use ;
use cratePrinter;
use crate;
use ;
/// True if a member-only chain has a line comment in any inter-member gap.
///
/// Block-only comments stay on the width-driven path (they format inline without forcing a
/// break); a line comment must end its line, so it forces the chain to break to
/// preserve the comment where the author wrote it — see
/// [`build_member_only_chain_with_comments_doc`].
///
/// The second spelling of "does a node's gap hold a `//`" — the grouping asks the same
/// question as `analysis::gap_has_line_comment`, over `chain_gap_share_any`'s share rather
/// than this printer-narrowed [`node_comment_gap`]; both stop at a computed member's `[`, and
/// differ only in that the share can be asked before `Printer::chain_has_comments` is set.
///
/// Routed through [`chain_gap_any`] like every other question about a chain gap. A
/// member-ONLY chain never widens — `apply_paren_gaps` requires a call — so the hole is
/// always `None` here and the seam is inert; it is used anyway so the reader does not have
/// to re-derive that, and so a widening this file cannot see cannot make it wrong.
pub
/// Build a member-only chain that has interior line comments.
///
/// Reverses the historical "emit every mid-chain comment via `line_suffix`"
/// approach, which deferred line comments to end of line — merging and reversing
/// consecutive ones (`a.b // c1⏎// c2⏎.c` → `a.b.c; // c2 // c1`) and dropping
/// nothing only by luck. Instead the chain breaks at every member (the same shape a
/// call in the chain already forces) and each gap's comments are emitted in place
/// via the shared [`push_gap_comments_and_break`] — the exact primitive the
/// call-chain breaking path uses. Comments stay where the author wrote them.
///
/// Prettier hoists the own-line comment before the whole expression and trails the
/// rest; tsv preserves position. Documented divergence
/// (`chained/member_only_interior_line_comment`).
pub
/// Prettier's `shouldInline` clause for a lone `a.prop` (member.js): the lookup's OBJECT
/// is an `Identifier`, its PROPERTY is an `Identifier`, and its first non-chain-element-
/// wrapper parent is not itself a member. Every one of the three is literal, and after
/// linearization each names a position in the node list:
///
/// - **object** — the lookup sits IMMEDIATELY after the base, and that base is a bare
/// identifier. `this` and `super` are `ThisExpression` / `Super` nodes, and a leading
/// `!` or `[i]` makes the object a `TSNonNullExpression` / `MemberExpression`, so
/// `this.p`, `super.p`, `a!.p` and `a[i].p` are all outside the clause.
/// - **property** — the lookup is a [`ChainNode::Member`], not a
/// [`ChainNode::PrivateMember`] (`a.#p`).
/// - **parent** — no further LOOKUP may follow, of either kind: a `Member` /
/// `PrivateMember` parent is a `MemberExpression`, and so is a `ComputedMember` one
/// (`a.p[i]` makes `a.p`'s parent a member exactly as `a.p.q` does — `node.computed` is
/// the parent's OWN inline clause, not a wrapper the ancestor walk steps over). A
/// trailing `!` and the `?.` spelling ARE stepped over: `TSNonNullExpression` and
/// `ChainExpression` are prettier's two chain-element wrappers, so `a.p!` and `a?.p`
/// stay in.
///
/// Together those are `[Base(Identifier), Member, NonNull*]`. Widening any of the three
/// welds a lookup that has to drop to its own line past the print width — for most of
/// these shapes the only break point they have (`member/lone_lookup_base_long`,
/// `member/lone_lookup_adjacency_long`, `member/lone_lookup_numeric_index_long`). Keep
/// this separable from `inline_every_lookup` above rather than folding the two: they
/// answer to different prettier clauses and only agree on the output.
/// Build doc for member-only chains: one group per lookup, mirroring prettier's
/// `printMemberExpression`.
///
/// Break points are ONLY at member access (`.foo`), not at non-null (`!`) and not at a
/// computed lookup (`[i]` — see [`ChainNode::is_dot_lookup`]). This ensures `.foo!` stays together as
/// a unit.
///
/// Example: `a!.b!.c!` breaks as:
/// ```text
/// a!.b!
/// .c!
/// ```
/// NOT as:
/// ```text
/// a!
/// .b!
/// .c!
/// ```
///
/// `inline_every_lookup` suppresses every one of those break points: a chain the parent
/// marked — an assignment TARGET, a `new` CALLEE — prints as one unbreakable unit (see
/// [`super::super::inline_lookups::resolve_inline_lookups`]).
pub