Skip to content

Commit

Permalink
fix: treat application/json scripts as json
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanPiercey committed Oct 29, 2024
1 parent 1482663 commit 13f0f75
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/__tests__/__snapshots__/script-with-type.expected/auto.marko
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,19 @@
]
}
</script>

<script type="application/json">
{ "hello": ${JSON.stringify(
world,
)}, "and-a-lot-more": "stuff-in-here-to-line-break" }
</script>
<script type="application/json">
{
"hello": 345873495873985893,
"and-a-lot-more": "stuff-in-here-to-line-break"
}
</script>

<script type="unknown">
${foo}
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,20 @@ script nonce=$global.cspNonce type="speculationrules"
]
}
--

script type="application/json"
--
{ "hello": ${JSON.stringify(
world,
)}, "and-a-lot-more": "stuff-in-here-to-line-break" }
--
script type="application/json"
--
{
"hello": 345873495873985893,
"and-a-lot-more": "stuff-in-here-to-line-break"
}
--

script type="unknown"
-- ${foo}
16 changes: 16 additions & 0 deletions src/__tests__/__snapshots__/script-with-type.expected/html.marko
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,19 @@
]
}
</script>

<script type="application/json">
{ "hello": ${JSON.stringify(
world,
)}, "and-a-lot-more": "stuff-in-here-to-line-break" }
</script>
<script type="application/json">
{
"hello": 345873495873985893,
"and-a-lot-more": "stuff-in-here-to-line-break"
}
</script>

<script type="unknown">
${foo}
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,19 @@
]
}
</script>

<script type="application/json">
{ "hello": ${JSON.stringify(
world,
)}, "and-a-lot-more": "stuff-in-here-to-line-break" }
</script>
<script type="application/json">
{
"hello": 345873495873985893,
"and-a-lot-more": "stuff-in-here-to-line-break"
}
</script>

<script type="unknown">
${foo}
</script>
5 changes: 5 additions & 0 deletions src/__tests__/fixtures/script-with-type.marko
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@
}]
}
</script>

<script type="application/json">{ "hello": ${JSON.stringify(world)}, "and-a-lot-more": "stuff-in-here-to-line-break" }</script>
<script type="application/json">{ "hello": 345873495873985893, "and-a-lot-more": "stuff-in-here-to-line-break" }</script>

<script type="unknown">${foo}</script>
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1274,6 +1274,7 @@ function getScriptParser(tag: types.MarkoTag) {
return scriptParser;
case "importmap":
case "speculationrules":
case "application/json":
return "json";
default:
return false;
Expand Down

0 comments on commit 13f0f75

Please sign in to comment.