Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(preset-mini): fix negative variant not accepting string theme #1057

Merged
merged 1 commit into from Jun 3, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/preset-mini/src/variants/misc.ts
Expand Up @@ -77,7 +77,7 @@ const numberRE = /[0-9.]+(?:[a-z]+|%)?/
export const variantNegative: Variant = {
name: 'negative',
match(matcher) {
if (!matcher.startsWith('-') || !matcher.match(/\d|-px|-full/))
if (!matcher.startsWith('-'))
return

return {
Expand Down
10 changes: 10 additions & 0 deletions test/__snapshots__/preset-mini.test.ts.snap
Expand Up @@ -7,6 +7,15 @@ exports[`preset-mini > custom var prefix 1`] = `
.scale-100{--hi-scale-x:1;--hi-scale-y:1;transform:var(--hi-transform);}"
`;

exports[`preset-mini > stray targets 1`] = `
"/* layer: preflights */
*,::before,::after{--un-rotate:0;--un-rotate-x:0;--un-rotate-y:0;--un-rotate-z:0;--un-scale-x:1;--un-scale-y:1;--un-scale-z:1;--un-skew-x:0;--un-skew-y:0;--un-translate-x:0;--un-translate-y:0;--un-translate-z:0;--un-transform:translateX(var(--un-translate-x)) translateY(var(--un-translate-y)) translateZ(var(--un-translate-z)) rotate(var(--un-rotate)) rotateX(var(--un-rotate-x)) rotateY(var(--un-rotate-y)) rotateZ(var(--un-rotate-z)) skewX(var(--un-skew-x)) skewY(var(--un-skew-y)) scaleX(var(--un-scale-x)) scaleY(var(--un-scale-y)) scaleZ(var(--un-scale-z));--un-ring-offset-shadow:0 0 #0000;--un-ring-shadow:0 0 #0000;--un-shadow-inset:var(--un-empty,/*!*/ /*!*/);--un-shadow:0 0 #0000;--un-ring-inset:var(--un-empty,/*!*/ /*!*/);--un-ring-offset-width:0px;--un-ring-offset-color:#fff;--un-ring-width:0px;--un-ring-color:rgba(147,197,253,0.5);}
/* layer: default */
.-border-solid{border-style:solid;}
.-decoration-none{text-decoration:none;}
.-color-blue-400{--un-text-opacity:-1;color:rgba(-96,165,250,var(--un-text-opacity));}"
`;

exports[`preset-mini > targets 1`] = `
"/* layer: preflights */
*,::before,::after{--un-rotate:0;--un-rotate-x:0;--un-rotate-y:0;--un-rotate-z:0;--un-scale-x:1;--un-scale-y:1;--un-scale-z:1;--un-skew-x:0;--un-skew-y:0;--un-translate-x:0;--un-translate-y:0;--un-translate-z:0;--un-transform:translateX(var(--un-translate-x)) translateY(var(--un-translate-y)) translateZ(var(--un-translate-z)) rotate(var(--un-rotate)) rotateX(var(--un-rotate-x)) rotateY(var(--un-rotate-y)) rotateZ(var(--un-rotate-z)) skewX(var(--un-skew-x)) skewY(var(--un-skew-y)) scaleX(var(--un-scale-x)) scaleY(var(--un-scale-y)) scaleZ(var(--un-scale-z));--un-ring-offset-shadow:0 0 #0000;--un-ring-shadow:0 0 #0000;--un-shadow-inset:var(--un-empty,/*!*/ /*!*/);--un-shadow:0 0 #0000;--un-ring-inset:var(--un-empty,/*!*/ /*!*/);--un-ring-offset-width:0px;--un-ring-offset-color:#fff;--un-ring-width:0px;--un-ring-color:rgba(147,197,253,0.5);}
Expand Down Expand Up @@ -65,6 +74,7 @@ div:hover .group-\\\\[div\\\\:hover\\\\]-\\\\[combinator\\\\:test-4\\\\]{combina
.pis{padding-inline-start:1rem;}
.pbs-\\\\$title2{padding-block-start:var(--title2);}
.pis-10px{padding-inline-start:10px;}
.-m-lg{margin:-1.125rem;}
.\\\\!m-\\\\$c-m{margin:var(--c-m) !important;}
.all\\\\:m-auto *,
.children\\\\:m-auto>*,
Expand Down
8 changes: 8 additions & 0 deletions test/assets/preset-mini-targets.ts
Expand Up @@ -500,6 +500,7 @@ export const presetMiniTargets: string[] = [
'mbs',
'mxy',
'm-xy',
'-m-lg',

// static
'contents',
Expand Down Expand Up @@ -863,3 +864,10 @@ export const presetMiniTargets: string[] = [
'parent-hover:text-center',
'previous-checked:bg-red-500',
]

export const presetMiniStrayTargets: string[] = [
// variants - negative
'-border-solid',
'-color-blue-400',
'-decoration-none',
]
1 change: 0 additions & 1 deletion test/assets/preset-wind-targets.ts
Expand Up @@ -365,5 +365,4 @@ export const presetWindTargets: string[] = [
export const presetWindNonTargets: string[] = [
'[outline~="active\:none"]',
'[i~="dark\:carbon-moon"]',
'-border-solid',
]
17 changes: 16 additions & 1 deletion test/preset-mini.test.ts
@@ -1,7 +1,7 @@
import { createGenerator, escapeSelector } from '@unocss/core'
import presetMini from '@unocss/preset-mini'
import { describe, expect, test } from 'vitest'
import { presetMiniTargets } from './assets/preset-mini-targets'
import { presetMiniStrayTargets, presetMiniTargets } from './assets/preset-mini-targets'
import { presetWindTargets } from './assets/preset-wind-targets'

const uno = createGenerator({
Expand Down Expand Up @@ -61,4 +61,19 @@ describe('preset-mini', () => {

expect(css).toMatchSnapshot()
})

test('stray targets', async () => {
const code = presetMiniStrayTargets.join(' ')
const { css } = await uno.generate(code)
const { css: css2 } = await uno.generate(code)

const unmatched = []
for (const i of presetMiniStrayTargets) {
if (!css.includes(escapeSelector(i)))
unmatched.push(i)
}
expect(unmatched).toEqual([])
expect(css).toMatchSnapshot()
expect(css).toEqual(css2)
})
})