sveltejs / sveltejs/esrap

Comment flush edge cases: EOF trailing comment moves to its own line; pad-space artifacts break print idempotency

Open
#175 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
139
Forks
18
Avg merge
1d 20h
Merged PRs (30d)
7

Description

Three boundary conditions in the comment flush machinery (all with parser-native locs):

  1. A trailing comment at EOF without a final newline moves onto its own line:

    console.log(1); // keep me
    

    (no trailing \n) prints

    console.log(1);
    // keep me
    

    Line-bound directives (eslint-disable-line and friends) stop covering their statement. Root: flush_trailing_comments requires before(comment.loc.end, next) STRICTLY, and at EOF-no-newline the comment ends exactly at Program.loc.end.

  2. Multiline block comment before a statement leaves a stray pad space (the newline after */ is intentional per #82 - the leftover is the pad):

    /* lead
     */ console.log(1);
    

    prints */\n console.log(1); - note the leading space. The next print of that output drops it, so the first print is not a fixed point.

  3. Comment-only file without a final newline grows a space per print:

    // alone
    

    (no trailing \n) prints // alone - the pad space intended for a following statement lands INSIDE the line-comment token, so every reprint grows the comment's text by one space (non-converging).

Context: found by a parse -> print -> reparse structural gate over a ~8.5k-file TS/JS corpus while adopting esrap in core-js's build plugin, then re-verified in isolation. esrap 2.3.5; the ASTs below come from @typescript-eslint/typescript-estree 8.67 with loc/range enabled, so the repros are independent of our own (oxc-based) pipeline.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the flush_trailing_comments machinery and reproduce the three snippets described in the issue, including the EOF and multiline-comment boundaries. Verify that trailing comments stay on the intended line, block-comment padding is not emitted, and comment-only files print to the same text on repeated runs.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.