Commit 8b22575
authored
Target first attribute at_sign in stmt_remove_leading_newlines for LocalFunction/ConstFunction (#1115)
* fix: target first attribute at_sign in stmt_remove_leading_newlines for LocalFunction/ConstFunction
When a LocalFunction or ConstFunction has a leading Luau attribute (e.g. @Native),
the actual first token of the statement is the attribute's at_sign, not the local/const
keyword. stmt_remove_leading_newlines was targeting the wrong token, leaving stray
newlines before the attribute at the start of a block.
Fixes #1109
* simplify: extract strip_attribute_leading_newlines helper, avoid allocation on no-attribute path
- Deduplicate the identical 6-line attribute-stripping logic from LocalFunction
and ConstFunction arms into a single helper function
- Use peekable iterator so no Vec is allocated when the function has no attributes
(the common case)
- Make both arms use a consistent if-let pattern instead of early-return vs if/else
- Remove redundant comment from test input file
* refactor: use next() to own first attribute, eliminating index and clone
Replace peek()+collect()+[0]+clone() with cloned().next()? which takes the
first element as an owned value so with_at_sign can consume it directly.
* style: rustfmt
* docs: add changelog entry for #11091 parent dfc5d9e commit 8b22575
4 files changed
Lines changed: 71 additions & 12 deletions
File tree
- src/formatters
- tests
- inputs-luau
- snapshots
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
| 22 | + | |
21 | 23 | | |
22 | 24 | | |
23 | 25 | | |
| |||
317 | 319 | | |
318 | 320 | | |
319 | 321 | | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
320 | 336 | | |
321 | 337 | | |
322 | 338 | | |
| |||
363 | 379 | | |
364 | 380 | | |
365 | 381 | | |
366 | | - | |
367 | | - | |
368 | | - | |
369 | | - | |
370 | | - | |
371 | | - | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
372 | 395 | | |
373 | 396 | | |
374 | 397 | | |
| |||
404 | 427 | | |
405 | 428 | | |
406 | 429 | | |
407 | | - | |
408 | | - | |
409 | | - | |
410 | | - | |
411 | | - | |
412 | | - | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
413 | 443 | | |
414 | 444 | | |
415 | 445 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
0 commit comments