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> tag is emptied when javascript string contains <!-- * --> #244

Closed
kristianvld opened this issue Aug 15, 2021 · 4 comments · Fixed by #247
Closed

<style> tag is emptied when javascript string contains <!-- * --> #244

kristianvld opened this issue Aug 15, 2021 · 4 comments · Fixed by #247

Comments

@kristianvld
Copy link

So a bit of a strange one. If there is an html comment within the script tag, then the whole style tag is just deleted when formatting.

Example test.svelte:

<script>
	const abc = "<!-- javascript string -->";
</script>

<div>Hello there</div>

<style>
	div {
		color: green;
	}
</style>

Output after formatting:

<script>
	const abc = "<!-- javascript string -->";
</script>

<div>Hello there</div>

<style></style>

As you can see, the style tag is just emptied. This seems to happen whenever the pattern <!--.*--> is within a script tag.

<script>
	const abc = "<" + "!-- javascript string -->";
</script>

<div>Hello there</div>

<style>
	div {
		color: green;
	}
</style>

for instance works as expected and the style remains.

Personally tested with the svelte prettier plugin for vs code with auto formatting on save.

VS Code: 1.59.0
Svelte for VS Code v105.3.4

@Mlocik97
Copy link

Mlocik97 commented Aug 15, 2021

I have same problem. doing something like ${'<'}!-- comment --> works fine, but it's similiar workaround as in #240 there is so a lot of bugs with prettier,...

@Mlocik97
Copy link

Mlocik97 commented Aug 15, 2021

<script>
	const abc = "<style></style>";
</script>

<div>Hello there</div>

<style>
	div {
		color: green;
	}
</style>

E: this gives same error. https://stackoverflow.com/a/236106 hmm, it seems JavaScript and HTML itself is buggy. You should probably escape Your HTML comment inside JS string...

so like this:

<script>
	const abc = "\<!-- javascript string --\>";
</script>

<div>Hello there</div>

<style>
	div {
		color: green;
	}
</style>

this is correct and works as expected, but I see formating remove those escape character, and at second formating, it still remove CSS: lol... Same ugly behaviour for other 2 examples. Hmm...

@Mlocik97
Copy link

<script>
	const abc = "<style>";
</script>

<div>Hello there</div>

<style>
	div {
		color: green;
	}
</style>

this give error: <script> must have a closing tagjs(-1)

@Mlocik97
Copy link

Mlocik97 commented Aug 15, 2021

<script>
	const abc = "</script>";
</script>

<div>Hello there</div>
{abc}

<style>
	div {
		color: green;
	}
</style>

give error </script> attempted to close an element that was not openjs(-1), and I see Svelte compiler fails on this code too. But I see, last one is https://stackoverflow.com/a/1659762 bug in javascript itself.

dummdidumm pushed a commit to dummdidumm/prettier-plugin-svelte that referenced this issue Aug 26, 2021
zakkor added a commit to metafy-gg/prettier-plugin-svelte that referenced this issue Aug 27, 2021
Bump path-parse from 1.0.6 to 1.0.7 (sveltejs#243)

Bumps [path-parse](https://github.com/jbgutierrez/path-parse) from 1.0.6 to 1.0.7.
- [Release notes](https://github.com/jbgutierrez/path-parse/releases)
- [Commits](https://github.com/jbgutierrez/path-parse/commits/v1.0.7)

---
updated-dependencies:
- dependency-name: path-parse
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

(fix) adjust wrong "is inside other tag" check (sveltejs#247)

Fixes sveltejs#244

(feat) format pug (sveltejs#248)

If the pug plugin is available, format template tags with that

update unreleased

Integrate with `tailwind-utils`

Make it work by `eval`ing TW config

Install TW plugins here, otherwise they won't be found when we require things in the Tailwind config

Include built plugin so we can use it without publishing to npm

Remove files from package.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants