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 d264d60
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,11 @@
]
}
</script>

<script type="application/json">
{ "hello": ${JSON.stringify(world)} }
</script>

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

script type="application/json"
-- { "hello": ${JSON.stringify(world)} }

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

<script type="application/json">
{ "hello": ${JSON.stringify(world)} }
</script>

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

<script type="application/json">
{ "hello": ${JSON.stringify(world)} }
</script>

<script type="unknown">
${foo}
</script>
4 changes: 4 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,7 @@
}]
}
</script>

<script type="application/json">{ "hello": ${JSON.stringify(world)} }</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 d264d60

Please sign in to comment.