From 13f0f751d65c72374a6d6f8c7c9957e22963ed59 Mon Sep 17 00:00:00 2001 From: dpiercey Date: Tue, 29 Oct 2024 10:45:47 -0700 Subject: [PATCH] fix: treat application/json scripts as json --- .../script-with-type.expected/auto.marko | 16 ++++++++++++++++ .../script-with-type.expected/concise.marko | 17 +++++++++++++++++ .../script-with-type.expected/html.marko | 16 ++++++++++++++++ .../script-with-type.expected/with-parens.marko | 16 ++++++++++++++++ src/__tests__/fixtures/script-with-type.marko | 5 +++++ src/index.ts | 1 + 6 files changed, 71 insertions(+) diff --git a/src/__tests__/__snapshots__/script-with-type.expected/auto.marko b/src/__tests__/__snapshots__/script-with-type.expected/auto.marko index dc82cd2..14ad8ae 100644 --- a/src/__tests__/__snapshots__/script-with-type.expected/auto.marko +++ b/src/__tests__/__snapshots__/script-with-type.expected/auto.marko @@ -8,3 +8,19 @@ ] } + + + + + diff --git a/src/__tests__/__snapshots__/script-with-type.expected/concise.marko b/src/__tests__/__snapshots__/script-with-type.expected/concise.marko index 077b6d7..4b0bce0 100644 --- a/src/__tests__/__snapshots__/script-with-type.expected/concise.marko +++ b/src/__tests__/__snapshots__/script-with-type.expected/concise.marko @@ -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} diff --git a/src/__tests__/__snapshots__/script-with-type.expected/html.marko b/src/__tests__/__snapshots__/script-with-type.expected/html.marko index dc82cd2..14ad8ae 100644 --- a/src/__tests__/__snapshots__/script-with-type.expected/html.marko +++ b/src/__tests__/__snapshots__/script-with-type.expected/html.marko @@ -8,3 +8,19 @@ ] } + + + + + diff --git a/src/__tests__/__snapshots__/script-with-type.expected/with-parens.marko b/src/__tests__/__snapshots__/script-with-type.expected/with-parens.marko index dc82cd2..14ad8ae 100644 --- a/src/__tests__/__snapshots__/script-with-type.expected/with-parens.marko +++ b/src/__tests__/__snapshots__/script-with-type.expected/with-parens.marko @@ -8,3 +8,19 @@ ] } + + + + + diff --git a/src/__tests__/fixtures/script-with-type.marko b/src/__tests__/fixtures/script-with-type.marko index 92dcfc9..2c90b0b 100644 --- a/src/__tests__/fixtures/script-with-type.marko +++ b/src/__tests__/fixtures/script-with-type.marko @@ -6,3 +6,8 @@ }] } + + + + + diff --git a/src/index.ts b/src/index.ts index a008d01..b91c0da 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1274,6 +1274,7 @@ function getScriptParser(tag: types.MarkoTag) { return scriptParser; case "importmap": case "speculationrules": + case "application/json": return "json"; default: return false;