microsoft / microsoft/TypeScript
Tolerate invalid identifier syntax errors in list parsing
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Go
- Estrellas
- 111k
- Forks
- 14.4k
- Merge medio
- 1 d 19 h
- PR fusionados (30 d)
- 117
Descripción
Search Terms
parser variable name list identifiers
Suggestion
Instead of aborting parsing a list when an invalid identifier is reached, have the parser emit a syntax error but otherwise parsing. In other words: it should successfully parse lists such as variable declarations as if the identifiers were valid, with the one difference of emitting a syntax error that doesn't affect parsing.
Use Cases
Issues such as #11648 and #19352 pop up from situations where the parser attempts to read in a list, such as one of variable declarations, and cannot because an identifier is invalid.
const case = 123;
// ~~~~ 'case' is not allowed as a variable declaration name.(1389)
// ~ Variable declaration expected.(1134)
// ~~~ Variable declaration expected.(1134)
Although #40105 improved the first error message (previously it was also Variable declaration expected.), the underlying issue remains: the parser aborts reading in the list, resulting in an odd error message and surprising emitted JavaScript.
const ;
123;
Examples
Collecting a few examples from the linked issues...
const data = { in: 1 };
const { in } = data;
for (const case of [1, 2, 3]) console.log(case);
const case = 123;
let delete = true;
Checklist
My suggestion meets these guidelines:
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
El issue no indica archivos de implementación ni pruebas. Empieza reproduciendo los casos de identificadores no válidos indicados en el parser de TypeScript y siguiendo cómo el análisis de listas gestiona el primer error de sintaxis. Se considera terminado cuando el parser informa del error del identificador y continúa analizando la declaración o lista circundante sin producir la salida con formato incorrecto actual.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- typescript
- Área
- compilers
- Tipo de issue
- Nueva funcionalidad
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 38/100