diff --git a/apps/oxfmt/test/tailwindcss/tailwindcss.test.ts b/apps/oxfmt/test/tailwindcss/tailwindcss.test.ts
index 6a0d8a53a938a..abe828f66d20f 100644
--- a/apps/oxfmt/test/tailwindcss/tailwindcss.test.ts
+++ b/apps/oxfmt/test/tailwindcss/tailwindcss.test.ts
@@ -1055,6 +1055,7 @@ describe("Tailwind CSS Sorting works with other options", () => {
const input = `
Hello
;
Hello
;
+ title
`;
const result = await format("test.tsx", input, {
@@ -1067,6 +1068,7 @@ describe("Tailwind CSS Sorting works with other options", () => {
expect(result.code).toMatchInlineSnapshot(`
"Hello
;
Hello
;
+ title
;
"
`);
});
@@ -1075,6 +1077,7 @@ describe("Tailwind CSS Sorting works with other options", () => {
const input = `
Hello
;
Hello
;
+ title
`;
const result = await format("test.tsx", input, {
@@ -1086,6 +1089,7 @@ describe("Tailwind CSS Sorting works with other options", () => {
expect(result.code).toMatchInlineSnapshot(`
"Hello
;
Hello
;
+ title
;
"
`);
});
diff --git a/crates/oxc_formatter/src/formatter/context.rs b/crates/oxc_formatter/src/formatter/context.rs
index 63e8249636b59..5a507fbcba77c 100644
--- a/crates/oxc_formatter/src/formatter/context.rs
+++ b/crates/oxc_formatter/src/formatter/context.rs
@@ -14,8 +14,6 @@ use super::{Comments, SourceText};
/// Entry in the Tailwind context stack, tracking whether we're inside a Tailwind class context.
#[derive(Clone, Copy, Debug)]
pub struct TailwindContextEntry {
- /// Whether the context is inside a JSX attribute (affects quote style).
- pub is_jsx: bool,
/// Whether to preserve whitespace (newlines) in template literals.
pub preserve_whitespace: bool,
/// Whether we're inside a template literal expression (between `${` and `}`).
@@ -42,9 +40,8 @@ pub struct TailwindContextEntry {
impl TailwindContextEntry {
/// Create a new context entry for JSX attributes or function calls.
- pub fn new(is_jsx: bool, preserve_whitespace: bool) -> Self {
+ pub fn new(preserve_whitespace: bool) -> Self {
Self {
- is_jsx,
preserve_whitespace,
in_template_expression: false,
quasi_before_has_trailing_ws: true, // Default: can collapse
@@ -63,7 +60,6 @@ impl TailwindContextEntry {
quasi_after_has_leading_ws: bool,
) -> Self {
Self {
- is_jsx: parent.is_jsx,
preserve_whitespace: parent.preserve_whitespace,
in_template_expression: true,
quasi_before_has_trailing_ws,
diff --git a/crates/oxc_formatter/src/utils/tailwindcss.rs b/crates/oxc_formatter/src/utils/tailwindcss.rs
index 697e9ec3a9e24..fdbd5be1581d4 100644
--- a/crates/oxc_formatter/src/utils/tailwindcss.rs
+++ b/crates/oxc_formatter/src/utils/tailwindcss.rs
@@ -210,7 +210,9 @@ pub fn write_tailwind_string_literal<'a>(
let normalized_string = FormatLiteralStringToken::new(
f.source_text().text_for(&string_literal),
- ctx.is_jsx,
+ // `className="string"`
+ // ^^^^^^^^
+ matches!(string_literal.parent, AstNodes::JSXAttribute(_)),
StringLiteralParentKind::Expression,
)
.clean_text(f);
diff --git a/crates/oxc_formatter/src/write/jsx/mod.rs b/crates/oxc_formatter/src/write/jsx/mod.rs
index f4940a3a8d68b..83ac70a52df41 100644
--- a/crates/oxc_formatter/src/write/jsx/mod.rs
+++ b/crates/oxc_formatter/src/write/jsx/mod.rs
@@ -332,7 +332,7 @@ impl<'a> FormatWrite<'a> for AstNode<'a, JSXAttribute<'a>> {
.experimental_tailwindcss
.as_ref()
.filter(|opts| is_tailwind_jsx_attribute(&self.name, opts))
- .map(|opts| TailwindContextEntry::new(true, opts.preserve_whitespace));
+ .map(|opts| TailwindContextEntry::new(opts.preserve_whitespace));
if let Some(ctx) = tailwind_ctx_to_push {
f.context_mut().push_tailwind_context(ctx);
diff --git a/crates/oxc_formatter/src/write/mod.rs b/crates/oxc_formatter/src/write/mod.rs
index 557b5340d02b0..a879089b099e2 100644
--- a/crates/oxc_formatter/src/write/mod.rs
+++ b/crates/oxc_formatter/src/write/mod.rs
@@ -297,7 +297,7 @@ impl<'a> FormatWrite<'a> for AstNode<'a, CallExpression<'a>> {
f.options()
.experimental_tailwindcss
.as_ref()
- .map(|opts| TailwindContextEntry::new(false, opts.preserve_whitespace))
+ .map(|opts| TailwindContextEntry::new(opts.preserve_whitespace))
} else {
None
};
diff --git a/crates/oxc_formatter/src/write/template.rs b/crates/oxc_formatter/src/write/template.rs
index 862129b42040f..027fe93f81562 100644
--- a/crates/oxc_formatter/src/write/template.rs
+++ b/crates/oxc_formatter/src/write/template.rs
@@ -61,7 +61,7 @@ impl<'a> FormatWrite<'a> for AstNode<'a, TaggedTemplateExpression<'a>> {
.experimental_tailwindcss
.as_ref()
.filter(|opts| is_tailwind_function_call(&self.tag, opts))
- .map(|opts| TailwindContextEntry::new(false, opts.preserve_whitespace));
+ .map(|opts| TailwindContextEntry::new(opts.preserve_whitespace));
if let Some(ctx) = tailwind_ctx_to_push {
f.context_mut().push_tailwind_context(ctx);