Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

Blank line preservation

Abierto
#7 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
25/100
Tipo de issue
Nueva funcionalidad
Claridad
Necesita aclaración
Estado de actividad
Estancado
Stack tecnológico
javascript, typescript
Área
tooling

Línea de trabajo

No se nombra ningún archivo, prueba ni punto de entrada; empieza por localizar las APIs de stringificación de nodos y de movimiento de código. Define y prueba cómo spaceBefore y spaceAfter representan líneas en blanco, comentarios, saltos de línea al inicio de línea y sangría, y decide si toString(true) los incluye.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
TypeScript
Estrellas
16
Forks
1
Métricas de merge de PR
Sin PR fusionados en 30 d

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de alloc/nebu

Todos los issues de alloc/nebu

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.