Skip to content
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

<style></style> in comment results incorrect output #212

Closed
JounQin opened this issue Feb 22, 2021 · 6 comments · Fixed by #216
Closed

<style></style> in comment results incorrect output #212

JounQin opened this issue Feb 22, 2021 · 6 comments · Fixed by #216
Labels
bug Something isn't working

Comments

@JounQin
Copy link

JounQin commented Feb 22, 2021

source:

<!-- <style>
.foo {
  background-image: url("x");
}
</style> -->

<style lang="scss">
.foo {
  background-image: url("x");
}

$map: (
  'alpha': 10,
  'beta': 20,
  'gamma': 30
);
</style>

<span>Hi</span>

result:

<span>Hi</span>

<!-- <style ✂prettier:content✂="Ci5mb28gewogIGJhY2tncm91bmQtaW1hZ2U6IHVybCgieCIpOwp9Cg=="></style> -->
<style lang="scss">
  .foo {
    background-image: url('x');
  }

  $map: (
    'alpha': 10,
    'beta': 20,
    'gamma': 30
  );
</style>
@dummdidumm
Copy link
Member

We need to adjust this regex to account for comments.

@dummdidumm dummdidumm added the bug Something isn't working label Feb 22, 2021
@JounQin
Copy link
Author

JounQin commented Feb 22, 2021

Besides, if there are two style tags, the error message is not original text which is very confusing:

test/fixtures/check.inert.svelte
[error] test/fixtures/check.inert.svelte: You can only have one top-level <style> tag per component
[error]   1 | <style ✂prettier:content✂="CiAgLmZvbyB7CiAgICBiYWNrZ3JvdW5kLWltYWdlOiB1cmwoJ3gnKTsKICB9Cg=="></style>
[error]   2 | 
[error] > 3 | <style lang="scss" ✂prettier:content✂="CiAgLmZvbyB7CiAgICBiYWNrZ3JvdW5kLWltYWdlOiB1cmwoJ3gnKTsKICB9CgogICRtYXA6ICgKICAgICdhbHBoYSc6IDEwLAogICAgJ2JldGEnOiAyMCwKICAgICdnYW1tYSc6IDMwLAogICk7Cg=="></style>
[error]   4 | 
[error]   5 | <span>Hi</span> (3:0)
[error] 1: <style ✂prettier:content✂="CiAgLmZvbyB7CiAgICBiYWNrZ3JvdW5kLWltYWdlOiB1cmwoJ3gnKTsKICB9Cg=="></style>
[error] 2: 
[error] 3: <style lang="scss" ✂prettier:content✂="CiAgLmZvbyB7CiAgICBiYWNrZ3JvdW5kLWltYWdlOiB1cmwoJ3gnKTsKICB9CgogICRtYXA6ICgKICAgICdhbHBoYSc6IDEwLAogICAgJ2JldGEnOiAyMCwKICAgICdnYW1tYSc6IDMwLAogICk7Cg=="></style>
[error]    ^
[error] 4: 
[error] 5: <span>Hi</span>

@JulianvonGebhardi
Copy link

I just came across this problem myself. I hope it gets fixed soon. Currently, its messing up any regex pattern which includes the style tag.

@dummdidumm
Copy link
Member

That's #70 . Accounting for html comments is a special case of that but easier to handle.

@kmcfate
Copy link

kmcfate commented Mar 19, 2021

This isn't just style tags in comments. Any comments cause problems:

This:

<script>
  import * as fs from 'fs';
  // some long test comment to see if this breaks
</script>

Results in:

<script>
  import * as fs from 'fs'; ;
  // some long test comment to see if this br
</script>

Note the extra semicolon and truncation.

Edit: This happens only in combination with import-sort and svelte.

@dummdidumm
Copy link
Member

This is a separate issue, please open a new issue for that with more details on now to reproduce

dummdidumm pushed a commit to dummdidumm/prettier-plugin-svelte that referenced this issue Apr 23, 2021
Account for the script/style being inside a comment
Fixes sveltejs#212
dummdidumm added a commit that referenced this issue Apr 23, 2021
Account for the script/style being inside a comment
Fixes #212
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants