-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Script & style contents lost when invoked with range option #233
Comments
Unfortunately getting rid of some kind of snipping is not possible given the way the Svelte compiler is written. From what I understand, the compiler expects vanilla JS/CSS in the script/style tags, and is greedy, meaning the moment it encounters a script or style tag it switches to a JS/CSS parser and parses until it finds a closing tag. If those JS/CSS parsers find anything that's not valid JS/CSS syntax, they throw. |
Hmm you're right it would be really complex. Shallow parser would open Pandora box of brace nesting and quoting issues... Snipping unfortunately also messes up offset inside file, length of base64 encode is different than that of original. |
I'm not that familar with how formatting a specific range works in prettier. Possible solutions without knowing more:
|
I dug into this today and found out that right now it's impossible to support range formatting, because we can't hook into Prettier at the required position: prettier/prettier#11404 |
any update on this? it still doesen't work. |
+1 |
This is not solved these days , and it was reported first time 3 years ago. :( :( |
Hello 👋
There are some cases when users would like to reformat only parts of file, unfortunately it's not working right now.
Reproduction:
Use following file
and run
Output:
Apart from nothing being really formatted (different issue, I've noticed it also does not work in official html), we get those base64 encoded placeholders.
During my investigation I've noticed that
parser.preprocess
encodes content, andprinter.embed
decodes it, butprinter.embed
is not called with custom range used.I'd like to ask, what is the technical reasoning behind those placeholders? This package uses
svelte
parser under the hood, and it returns deep AST with embedded JS already parsed (and TS types stripped, right?). Would it be possible to get rid ofparse.preprocess
if svelte parser had shallow option that would leave text ofScript
andStyle
nodes as text? I believe it could be then passed totextToDoc
inembed
The text was updated successfully, but these errors were encountered: