Skip to content

Commit

Permalink
fix(preset-mini): fix escaped underscore replacements in h.bracket (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
chu121su12 committed Sep 2, 2022
1 parent ffffad8 commit 2b369d6
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/preset-mini/src/_utils/handlers/handlers.ts
Expand Up @@ -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 ')
})
Expand Down
6 changes: 3 additions & 3 deletions test/__snapshots__/preset-mini.test.ts.snap
Expand Up @@ -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,
Expand Down Expand Up @@ -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;}
Expand Down
2 changes: 1 addition & 1 deletion test/__snapshots__/preset-wind.test.ts.snap
Expand Up @@ -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;}
Expand Down
9 changes: 9 additions & 0 deletions test/handler.test.ts
Expand Up @@ -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)')
})
})

0 comments on commit 2b369d6

Please sign in to comment.