Skip to content

Commit

Permalink
fix: improve fallback content printint
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanPiercey committed Oct 24, 2024
1 parent 2559fa8 commit 29cec40
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
style {
invalid { color blue; }
}
style { invalid { color blue; } }

<style>
body
color: blue;
</style>
<script>
console->log(
'a'
);
</script>
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
style {
invalid { color blue; }
}
style { invalid { color blue; } }

style
--
body
color: blue;
--
script
--
console->log(
'a'
);
--
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
style {
invalid { color blue; }
}
style { invalid { color blue; } }

<style>
body
color: blue;
</style>
<script>
console->log(
'a'
);
</script>
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
style {
invalid { color blue; }
}
style { invalid { color blue; } }

<style>
body
color: blue;
</style>
<script>
console->log(
'a'
);
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<script nonce=$global.cspNonce type="speculationrules">
{
"prerender": [{
"where": { "href_matches": "/*" },
"eagerness": "moderate"
}]
}
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
script nonce=$global.cspNonce type="speculationrules"
--
{
"prerender": [{
"where": { "href_matches": "/*" },
"eagerness": "moderate"
}]
}
--
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<script nonce=$global.cspNonce type="speculationrules">
{
"prerender": [{
"where": { "href_matches": "/*" },
"eagerness": "moderate"
}]
}
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<script nonce=$global.cspNonce type="speculationrules">
{
"prerender": [{
"where": { "href_matches": "/*" },
"eagerness": "moderate"
}]
}
</script>
8 changes: 8 additions & 0 deletions src/__tests__/fixtures/script-with-type.marko
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<script nonce=$global.cspNonce type="speculationrules">
{
"prerender": [{
"where": { "href_matches": "/*" },
"eagerness": "moderate"
}]
}
</script>
18 changes: 14 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,11 @@ export const printers: Record<string, Printer<types.Node>> = {
: b.ifBreak("--", " --", { groupId }),
opts.markoSyntax === "html" ? "" : b.line,
replaceEmbeddedPlaceholders(
await toDoc(embeddedCode, { parser: scriptParser }),
await toDoc(embeddedCode, {
parser: scriptParser,
}).catch(() =>
asLiteralTextContent(embeddedCode.trim()),
),
placeholders,
),
opts.markoSyntax === "html"
Expand Down Expand Up @@ -781,7 +785,12 @@ export const printers: Record<string, Printer<types.Node>> = {
"style",
!lang || lang === ".css" ? "" : lang,
" {",
b.indent([b.line, await toDoc(code, { parser })]),
b.indent([
b.line,
await toDoc(code, { parser }).catch(() =>
asLiteralTextContent(code.trim()),
),
]),
b.line,
"}",
]),
Expand Down Expand Up @@ -888,14 +897,15 @@ export const printers: Record<string, Printer<types.Node>> = {
: b.ifBreak("--", " --", { groupId }),
opts.markoSyntax === "html" ? "" : b.line,
replaceEmbeddedPlaceholders(
await toDoc(embeddedCode, { parser }),
await toDoc(embeddedCode, { parser }).catch(() =>
asLiteralTextContent(embeddedCode.trim()),
),
placeholders,
),
opts.markoSyntax === "html"
? ""
: b.ifBreak([b.softline, "--"]),
]);

doc.push(b.indent([wrapSep, bodyDoc]));

if (opts.markoSyntax === "html") {
Expand Down

0 comments on commit 29cec40

Please sign in to comment.