Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion apps/oxfmt/src-js/libs/prettier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export async function resolvePlugins(): Promise<string[]> {
export type FormatEmbeddedCodeParam = {
code: string;
parserName: string;
options: Options;
options: Options & { _tailwindPluginEnabled?: boolean };
};

/**
Expand All @@ -53,6 +53,10 @@ export async function formatEmbeddedCode({
// SAFETY: `options` is created in Rust side, so it's safe to mutate here
options.parser = parserName;

// Enable Tailwind CSS plugin for embedded code (e.g., html`...` in JS)
// when `options._tailwindPluginEnabled` is set
await setupTailwindPlugin(options);

// NOTE: This will throw if:
// - Specified parser is not available
// - Or, code has syntax errors
Expand Down
15 changes: 15 additions & 0 deletions apps/oxfmt/test/tailwindcss/tailwindcss.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1118,3 +1118,18 @@ describe("Tailwind CSS Sorting works with other options", () => {
`);
});
});

describe("Tailwind CSS Sorting in Embedded HTML (Tagged Template Literals)", () => {
test("should sort Tailwind classes in html tagged template literal", async () => {
const input = `const view = html\`<div class="p-4 flex bg-red-500">Hello</div>\`;`;

const result = await format("test.ts", input, {
experimentalTailwindcss: {},
});

// After sorting, flex should come before p-4 (display before spacing)
expect(result.code).toContain('class="flex');
expect(result.code).not.toContain('class="p-4 flex');
expect(result.errors).toStrictEqual([]);
});
});
Loading