From 15013264fe958a3eaa1a21a745a10688bd6d4b5b Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Thu, 6 Jun 2024 11:30:08 -0400 Subject: [PATCH 1/3] Add tests for escapes --- tests/format.test.js | 14 ++++++++++++++ tests/plugins.test.js | 3 +++ 2 files changed, 17 insertions(+) diff --git a/tests/format.test.js b/tests/format.test.js index 255bfee7..a24546eb 100644 --- a/tests/format.test.js +++ b/tests/format.test.js @@ -93,6 +93,15 @@ let javascript = [ ';
', ';
', ], + [ + `;
`, + `;
`, + ], + + [ + `;
`, + `;
`, + ], ] javascript = javascript.concat( javascript.map((test) => [ @@ -141,6 +150,11 @@ let vue = [ `
`, `
`, ], + + [ + `
`, + `
`, + ], ] let glimmer = [ diff --git a/tests/plugins.test.js b/tests/plugins.test.js index b8542b2c..f9c2101e 100644 --- a/tests/plugins.test.js +++ b/tests/plugins.test.js @@ -430,6 +430,9 @@ import Custom from '../components/Custom.astro' `
`, `
`, ], + + // Escapes + t`
`, ], }, }, From ae34102b9a4a97551da4a6dd3c6fd383c15e5bb4 Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Thu, 6 Jun 2024 11:30:58 -0400 Subject: [PATCH 2/3] Make sure escapes in classes are preserved in string literals --- src/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index b718147b..a766a7c9 100644 --- a/src/index.js +++ b/src/index.js @@ -450,12 +450,12 @@ function sortStringLiteral( node.extra = { ...node.extra, rawValue: result, - raw: raw[0] + result + raw.slice(-1), + raw: raw[0] + result.replace(/\\/g, '\\\\') + raw.slice(-1), } } else { // TypeScript (Literal) let raw = node.raw - node.raw = raw[0] + result + raw.slice(-1) + node.raw = raw[0] + result.replace(/\\/g, '\\\\') + raw.slice(-1) } return didChange } From 84d2fadc22911090e1c319e4d972d5ef91283046 Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Thu, 6 Jun 2024 11:33:01 -0400 Subject: [PATCH 3/3] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index da0badce..ee411f47 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Only remove duplicate Tailwind classes ([#277](https://github.com/tailwindlabs/prettier-plugin-tailwindcss/pull/277)) +- Make sure escapes in classes are preserved in string literals ([#286](https://github.com/tailwindlabs/prettier-plugin-tailwindcss/pull/286)) ## [0.6.1] - 2024-05-31