Skip to content

Commit

Permalink
[fix] don't strip type="application/.." tags (#6887)
Browse files Browse the repository at this point in the history
* [fix] don't strip type="application/.." tags

Fixes #6862

* changeset
  • Loading branch information
dummdidumm committed Sep 19, 2022
1 parent 6c706c3 commit e3de793
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 2 deletions.
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']
})
};

0 comments on commit e3de793

Please sign in to comment.