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

[fix] don't strip type="application/.." tags #6887

Merged
merged 2 commits into from
Sep 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/cyan-pianos-bake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/package': patch
---

[fix] don't strip `type="application/.."` tags
6 changes: 5 additions & 1 deletion packages/package/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ export function resolve_lib_alias(file, content, config) {
*/
export function strip_lang_tags(content) {
return content
.replace(/(<!--[^]*?-->)|(<script[^>]*?)\s(?:type|lang)=(["']).*?\3/g, '$1$2')
.replace(
/(<!--[^]*?-->)|(<script[^>]*?)\s(?:type|lang)=(["'])(.*?)\3/g,
// things like application/ld+json should be kept as-is. Preprocessed languages are "ts" etc
(match, s1, s2, _, s4) => (s4.startsWith('application/') ? match : (s1 ?? '') + (s2 ?? ''))
)
.replace(/(<!--[^]*?-->)|(<style[^>]*?)\s(?:type|lang)=(["']).*?\3/g, '$1$2');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@
/** @type {import('./foo').Foo} */
export let foo;
</script>

<svelte:head>
<script type="application/ld+json">{JSON.stringify(jsonLd)}</script>
</svelte:head>
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@
/** @type {import('./foo').Foo} */
export let foo;
</script>

<svelte:head>
<script type="application/ld+json">{JSON.stringify(jsonLd)}</script>
</svelte:head>
4 changes: 3 additions & 1 deletion packages/package/test/fixtures/typescript/svelte.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import preprocess from 'svelte-preprocess';

export default {
preprocess: preprocess()
preprocess: preprocess({
preserve: ['ld+json']
})
};