From d21189d64c94d2daefe1733dd8e42ef8b0c87a57 Mon Sep 17 00:00:00 2001 From: Saya Date: Fri, 2 Sep 2022 12:51:04 +0800 Subject: [PATCH] fix(preset-mini): fix escaped underscore replacements in h.bracket --- packages/preset-mini/src/_utils/handlers/handlers.ts | 1 + test/__snapshots__/preset-mini.test.ts.snap | 6 +++--- test/__snapshots__/preset-wind.test.ts.snap | 2 +- test/handler.test.ts | 9 +++++++++ 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/packages/preset-mini/src/_utils/handlers/handlers.ts b/packages/preset-mini/src/_utils/handlers/handlers.ts index ae53c1be66..37c4c8ce14 100644 --- a/packages/preset-mini/src/_utils/handlers/handlers.ts +++ b/packages/preset-mini/src/_utils/handlers/handlers.ts @@ -122,6 +122,7 @@ function bracketWithType(str: string, type?: string) { return base .replace(/(url\(.*?\))/g, v => v.replace(/_/g, '\\_')) .replace(/([^\\])_/g, '$1 ') + .replace(/\\_/g, '_') .replace(/(?:calc|clamp|max|min)\((.*)/g, (v) => { return v.replace(/(-?\d*\.?\d(?!\b-.+[,)](?![^+\-/*])\D)(?:%|[a-z]+)?|\))([+\-/*])/g, '$1 $2 ') }) diff --git a/test/__snapshots__/preset-mini.test.ts.snap b/test/__snapshots__/preset-mini.test.ts.snap index 03283fac81..cd8c106fff 100644 --- a/test/__snapshots__/preset-mini.test.ts.snap +++ b/test/__snapshots__/preset-mini.test.ts.snap @@ -43,9 +43,9 @@ exports[`preset-mini > targets 1`] = ` .items-\\\\$size{align-items:var(--size);} .ws-\\\\$variable{white-space:var(--variable);} .\\\\[a\\\\:b\\\\]{a:b;} -.\\\\[background-image\\\\:url\\\\(star_transparent\\\\.gif\\\\)\\\\,_url\\\\(cat_front\\\\.png\\\\)\\\\]{background-image:url(star\\\\_transparent.gif), url(cat\\\\_front.png);} +.\\\\[background-image\\\\:url\\\\(star_transparent\\\\.gif\\\\)\\\\,_url\\\\(cat_front\\\\.png\\\\)\\\\]{background-image:url(star_transparent.gif), url(cat_front.png);} .\\\\[content\\\\:attr\\\\(attr_content\\\\)\\\\]{content:attr(attr content);} -.\\\\[content\\\\:attr\\\\(attr\\\\\\\\_content\\\\)\\\\]{content:attr(attr\\\\_content);} +.\\\\[content\\\\:attr\\\\(attr\\\\\\\\_content\\\\)\\\\]{content:attr(attr_content);} .\\\\[margin\\\\:logical_1rem_2rem_3rem\\\\]{margin:logical 1rem 2rem 3rem;} .all-\\\\[\\\\.target\\\\]-\\\\[combinator\\\\:test-2\\\\] .target, .children-\\\\[\\\\.target\\\\]-\\\\[combinator\\\\:test-2\\\\]>.target, @@ -675,7 +675,7 @@ div:hover .group-\\\\[div\\\\:hover\\\\]-\\\\[combinator\\\\:test-4\\\\]{combina .aspect-ratio-square{aspect-ratio:1/1;} .aspect-ratio-video{aspect-ratio:16/9;} .aspect-unset{aspect-ratio:unset;} -.cursor-\\\\[url\\\\(cursor_2\\\\.png\\\\)_2_2\\\\,_pointer\\\\]{cursor:url(cursor\\\\_2.png) 2 2, pointer;} +.cursor-\\\\[url\\\\(cursor_2\\\\.png\\\\)_2_2\\\\,_pointer\\\\]{cursor:url(cursor_2.png) 2 2, pointer;} .cursor-\\\\$pointer-var{cursor:var(--pointer-var);} .cursor-inherit{cursor:inherit;} .cursor-pointer{cursor:pointer;} diff --git a/test/__snapshots__/preset-wind.test.ts.snap b/test/__snapshots__/preset-wind.test.ts.snap index b635f4d72c..56a148a75d 100644 --- a/test/__snapshots__/preset-wind.test.ts.snap +++ b/test/__snapshots__/preset-wind.test.ts.snap @@ -101,7 +101,7 @@ exports[`preset-wind > targets 1`] = ` @keyframes bounce{0%, 100% {transform:translateY(-25%);animation-timing-function:cubic-bezier(0.8,0,1,1)} 50% {transform:translateY(0);animation-timing-function:cubic-bezier(0,0,0.2,1)}} @keyframes ping{0%{transform:scale(1);opacity:1}75%,100%{transform:scale(2);opacity:0}} .\\\\!animate-ping{animation:ping 1s cubic-bezier(0,0,.2,1) infinite !important;} -.animate-\\\\[4s_linear_0s_infinite_alternate_move\\\\\\\\_eye\\\\]{animation:4s linear 0s infinite alternate move\\\\_eye;} +.animate-\\\\[4s_linear_0s_infinite_alternate_move\\\\\\\\_eye\\\\]{animation:4s linear 0s infinite alternate move_eye;} .animate-\\\\$variable{animation:var(--variable);} .animate-pulse{animation:pulse 2s cubic-bezier(0.4,0,.6,1) infinite;} .animate-pulse-alt{animation:pulse-alt 1s ease-in-out infinite;} diff --git a/test/handler.test.ts b/test/handler.test.ts index 3d2cdb5004..f5e14396c3 100644 --- a/test/handler.test.ts +++ b/test/handler.test.ts @@ -20,4 +20,13 @@ describe('value handler', () => { expect(h.bracket('[]][[]]]]')).eql(undefined) expect(h.bracket('[[][[[]]]]')).eql('[][[[]]]') }) + + it('bracket underscore', () => { + expect(h.bracket('[a_b]')).eql('a b') + expect(h.bracket('[a\\_b]')).eql('a_b') + expect(h.bracket('[url(a_b)]')).eql('url(a_b)') + expect(h.bracket('[url(a\\_b)]')).eql('url(a\\_b)') + expect(h.bracket('[var(--A_B)]')).eql('var(--A B)') + expect(h.bracket('[var(--A\\_B)]')).eql('var(--A_B)') + }) })