fix(core): improve island props serialization (#3071)

This commit is contained in:
Marvin Hagemeister
2025-06-30 16:31:58 +02:00
committed by GitHub
parent 8d3b8c53c6
commit 8416078b6a
5 changed files with 135 additions and 7 deletions
+13
View File
@@ -53,3 +53,16 @@ export function pathToExportName(filePath: string): string {
const regex = /^[^a-z_$]|[^a-z0-9_$]/gi;
return name.replaceAll(regex, "_").replaceAll(/_{2,}/g, "_");
}
const SCRIPT_ESCAPE = /<\/(style|script)/gi;
const COMMENT_ESCAPE = /<!--/gi;
// See https://html.spec.whatwg.org/multipage/scripting.html#restrictions-for-contents-of-script-elements
export function escapeScript(
content: string,
options: { json?: boolean } = {},
): string {
return content
.replaceAll(SCRIPT_ESCAPE, "<\\/$1")
.replaceAll(COMMENT_ESCAPE, options.json ? "\\u003C!--" : "\\x3C!--");
}