Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Blank line preservation

Aperta
#7 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
25/100
Tipo di issue
Funzionalità
Chiarezza
Da chiarire
Stato di attività
Ferma
Stack tecnologico
javascript, typescript
Ambito
tooling

Direzione di ricerca

Non viene indicato alcun file, test o punto di ingresso; inizia individuando le API per la stringificazione dei nodi e lo spostamento del codice. Definisci e testa come spaceBefore e spaceAfter rappresentano righe vuote, commenti, interruzioni di riga all’inizio della riga e indentazione, e stabilisci se toString(true) li include.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

enhancement

When moving a block of code, you can use toString on each node and "paste" the result by using the appropriate method. There needs to be a way to preserve blank lines between nodes, so we can preserve the author's style.

The first idea that comes to mind is a method that returns a string containing only newlines (and maybe indentation?) corresponding to the number of blank lines before or after the node (so two variants). This string can then be "pasted" just like the toString result.

As an example:

foo()

// comment 1
bar()

// comment 2
foo()

Assume the bar() expression is represented by node:

node.spaceBefore() // => "\n\n// comment 1\n"
node.toString()    // => "bar()"
node.spaceAfter()  // => "\n\n\n// comment 2\n"

In the above example, the \n that begins bar()'s line is included in the spaceBefore result. And the \n that begins the line after that is included in the spaceAfter result. I'm not certain, but I think that's the expected behavior.

I'm also undecided if indentation should be included or not. I'm leaning towards no, because toString currently strips indentation and we should match that behavior.

Another thing: maybe toString(true) can include the result of spaceAfter (and even the result of spaceBefore if we're the first sibling of a BlockStatement) to make things easier?

These decisions could easily be a source of many bugs if we aren't careful.

Lingua principale
TypeScript
Stelle
16
Fork
1
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di alloc/nebu

Tutte le issue di alloc/nebu

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.