43081j / 43081j/postcss-lit

SyntaxError: parser error when using `postcss-lit` as Custom Syntax with Stylelint LSP

Aperta
#60 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
TypeScript
Stelle
90
Fork
9
Merge medio
1g 9m
PR unite (30g)
3

Descrizione

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

![VSCode error collapsed](https://github.com/user-attachments/assets/d305d9e8-a8be-46e2-99db-548cb436d081)
![image](https://github.com/user-attachments/assets/adbef956-8b6d-4217-8aba-c0fd67e3edee)
![image](https://github.com/user-attachments/assets/e51edbcd-f2f5-4a6b-9069-809840eda85c)

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Direzione di ricerca

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.

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

Valutazione

Stack tecnologico
typescript
Ambito
devtools, tooling
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Specificata chiaramente
Idoneità per principianti
30/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.