From 2604b3eeb34efa450d4225c72cefe742c550d94a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B1=90?= <31800073+Parsifa1@users.noreply.github.com> Date: Tue, 27 May 2025 09:09:14 +0800 Subject: [PATCH] Add embed format support for `script[type="text/jsx"]` in html (#17495) --- src/language-html/embed.js | 3 ++- src/language-html/utils/index.js | 1 + .../html/js/__snapshots__/format.test.js.snap | 8 ++++++++ tests/format/html/js/js.html | 4 ++++ .../html/script/__snapshots__/format.test.js.snap | 14 ++++++++++++++ tests/format/html/script/babel.html | 9 +++++++++ 6 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/language-html/embed.js b/src/language-html/embed.js index 739c1c64b..115f5fac7 100644 --- a/src/language-html/embed.js +++ b/src/language-html/embed.js @@ -91,7 +91,8 @@ function embed(path, options) { if ( attrMap && (attrMap.type === "module" || - (attrMap.type === "text/babel" && + ((attrMap.type === "text/babel" || + attrMap.type === "text/jsx") && attrMap["data-type"] === "module")) ) { sourceType = "module"; diff --git a/src/language-html/utils/index.js b/src/language-html/utils/index.js index bd599719b..1196bbd16 100644 --- a/src/language-html/utils/index.js +++ b/src/language-html/utils/index.js @@ -343,6 +343,7 @@ function inferParserByTypeAttribute(type) { case "module": case "text/javascript": case "text/babel": + case "text/jsx": case "application/javascript": return "babel"; diff --git a/tests/format/html/js/__snapshots__/format.test.js.snap b/tests/format/html/js/__snapshots__/format.test.js.snap index fb020c72e..5de24a784 100644 --- a/tests/format/html/js/__snapshots__/format.test.js.snap +++ b/tests/format/html/js/__snapshots__/format.test.js.snap @@ -38,6 +38,10 @@ printWidth: 80 + + + + + + + + + + + +