|
1 | 1 | import { test } from "./util/helpers.mjs"; |
2 | | -import apiTest from "./util/runner.mjs"; |
3 | | -import parser from "../../dist/index.js"; |
4 | 2 |
|
5 | 3 | test("class name", ".one", (t, tree) => { |
6 | 4 | t.deepEqual(tree.nodes[0].nodes[0].value, "one"); |
@@ -276,79 +274,3 @@ test("class selector with escaping (36)", ".not-pseudo\\:\\:focus", (t, tree) => |
276 | 274 | t.deepEqual(tree.nodes[0].nodes[0].type, "class"); |
277 | 275 | t.deepEqual(tree.nodes[0].nodes[0].raws.value, "not-pseudo\\:\\:focus"); |
278 | 276 | }); |
279 | | - |
280 | | -for (const [value, escaped] of [ |
281 | | - ["hover:bg-blue", "hover\\:bg-blue"], |
282 | | - ["1abc", "\\31 abc"], |
283 | | - ["foo.bar", "foo\\.bar"], |
284 | | - ["foo\\bar", "foo\\\\bar"], |
285 | | - ["♥", "\\2665"], |
286 | | -]) { |
287 | | - apiTest(`ClassName constructor escapes ${value}`, (t) => { |
288 | | - const className = parser.className({ value }); |
289 | | - t.is(className.value, value); |
290 | | - t.is(className.toString(), `.${escaped}`, "constructor must escape the semantic value"); |
291 | | - t.is(parser().astSync(className.toString()).first.first.value, value); |
292 | | - }); |
293 | | -} |
294 | | - |
295 | | -apiTest("ClassName constructor preserves explicit raw spelling in either option order", (t) => { |
296 | | - for (const opts of [ |
297 | | - { value: "hover:bg-blue", raws: { value: "hover\\3A bg-blue" } }, |
298 | | - { raws: { value: "hover\\3A bg-blue" }, value: "hover:bg-blue" }, |
299 | | - ]) { |
300 | | - const className = parser.className(opts); |
301 | | - t.is(className.value, "hover:bg-blue"); |
302 | | - t.is(className.toString(), ".hover\\3A bg-blue"); |
303 | | - } |
304 | | -}); |
305 | | - |
306 | | -apiTest("ClassName constructor without a value still supports later assignment", (t) => { |
307 | | - const className = parser.className(); |
308 | | - t.is(className.value, undefined); |
309 | | - className.value = "hover:bg-blue"; |
310 | | - t.is(className.toString(), ".hover\\:bg-blue"); |
311 | | -}); |
312 | | - |
313 | | -apiTest("ClassName constructor leaves a plain identifier and other raw properties intact", (t) => { |
314 | | - const plain = parser.className({ value: "button" }); |
315 | | - t.is(plain.toString(), ".button"); |
316 | | - t.is(plain.raws, undefined); |
317 | | - const className = parser.className({ |
318 | | - value: "hover:bg-blue", |
319 | | - raws: { spaces: { before: "/* before */" } }, |
320 | | - }); |
321 | | - t.is( |
322 | | - className.toString(), |
323 | | - "/* before */.hover\\:bg-blue", |
324 | | - "other raw fields must not suppress escaping", |
325 | | - ); |
326 | | -}); |
327 | | - |
328 | | -apiTest( |
329 | | - "ClassName clones preserve raw spelling and escape replacement values independently", |
330 | | - (t) => { |
331 | | - const original = parser.className({ |
332 | | - value: "hover:bg-blue", |
333 | | - raws: { value: "hover\\3A bg-blue" }, |
334 | | - }); |
335 | | - const clone = original.clone(); |
336 | | - t.is(clone.toString(), original.toString()); |
337 | | - t.not(clone.raws, original.raws); |
338 | | - const replaced = original.clone({ value: "focus:bg-red" }); |
339 | | - t.is(replaced.toString(), ".focus\\:bg-red"); |
340 | | - t.is(original.toString(), ".hover\\3A bg-blue"); |
341 | | - }, |
342 | | -); |
343 | | - |
344 | | -apiTest("Parsed classes keep their original raw state when cloned", (t) => { |
345 | | - for (const input of [".button", ".♥", ".foo@{bar}", ".hover\\3A bg-blue"]) { |
346 | | - const original = parser().astSync(input).first.first; |
347 | | - const clone = original.clone(); |
348 | | - t.is(clone.toString(), input); |
349 | | - t.deepEqual(clone.raws, original.raws); |
350 | | - if (!input.includes("\\")) { |
351 | | - t.is(original.raws, undefined); |
352 | | - } |
353 | | - } |
354 | | -}); |
0 commit comments