SyntaxError: parser error when using `postcss-lit` as Custom Syntax with Stylelint LSP
- Lenguaje dominante
- TypeScript
- Estrellas
- 90
- Forks
- 9
- Merge medio
- 1 d 9 min
- PR fusionados (30 d)
- 3
Descripción
Using `postcss-lit` as Custom Syntax with Stylelint makes most editors / Stylelint LSP throw babel parser errors in some cases.
Errors are usually thrown when writing incomplete syntax (which is very common in LSP context).
Of course it's normal for the parser to fail with incomplete syntax but the issue is that it throws errors instead of failing silently.
Using other custom syntaxes like [postcss-styled-syntax](https://github.com/hudochenkov/postcss-styled-syntax) fixes the issue.
## Steps to reproduce
I've created a small repo to make it easy to reproduce: https://github.com/florian-sanders/postcss-lit-stylelint
As explained in the repo, the issue occurs with VSCode & WebStorm.
The error content:
```js
[Error - 10:48:54 PM] [language-server] Error running lint | uri: "file:///home/flo-perso/Projects/postcss-lit-stylelint/wc-test.js" error: {"code":"BABEL_PARSER_SYNTAX_ERROR","reasonCode":"UnterminatedString","loc":{"line":9,"column":32,"index":168},"pos":168,"name":"SyntaxError","message":"Unterminated string constant. (9:32)","stack":"SyntaxError: Unterminated string constant. (9:32)\n at constructor (/home/flo-perso/Projects/postcss-lit-stylelint/node_modules/@babel/parser/lib/index.js:359:19)\n at TypeScriptParserMixin.raise (/home/flo-perso/Projects/postcss-lit-stylelint/node_modules/@babel/parser/lib/index.js:3266:19)\n at Object.unterminated (/home/flo-perso/Projects/postcss-lit-stylelint/node_modules/@babel/parser/lib/index.js:2334:20)\n at readStringContents (/home/flo-perso/Projects/postcss-lit-stylelint/node_modules/@babel/parser/lib/index.js:2076:16)\n at TypeScriptParserMixin.readString (/home/flo-perso/Projects/postcss-lit-stylelint/node_modules/@babel/parser/lib/index.js:3165:9)\n at TypeScriptParserMixin.getTokenFromCode (/home/flo-perso/Projects/postcss-lit-stylelint/node_modules/@babel/parser/lib/index.js:2925:14)\n at TypeScriptParserMixin.getTokenFromCode (/home/flo-perso/Projects/postcss-lit-stylelint/node_modules/@babel/parser/lib/index.js:6851:11)\n at TypeScriptParserMixin.getTokenFromCode (/home/flo-perso/Projects/postcss-lit-stylelint/node_modules/@babel/parser/lib/index.js:9640:11)\n at TypeScriptParserMixin.nextToken (/home/flo-perso/Projects/postcss-lit-stylelint/node_modules/@babel/parser/lib/index.js:2449:10)\n at TypeScriptParserMixin.next (/home/flo-perso/Projects/postcss-lit-stylelint/node_modules/@babel/parser/lib/index.js:2362:10)"}
```
Screenshots of the errors



Guía de contribución
No hay ninguna guía de contribución indexada para este repositorio
Línea de trabajo
The issue is in the postcss-lit parser's error handling when encountering incomplete syntax in template literals. Start by examining the custom syntax implementation in the source, likely in the parser or tokenizer. Compare with postcss-styled-syntax to see how it fails silently. The reproduction repo provides a test case; run it to see the babel parser error. The fix likely involves catching and suppressing syntax errors during linting.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- typescript
- Área
- devtools, tooling
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bien especificado
- Aptitud para principiantes
- 30/100