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(core): replace scope placeholder globally #2071

Merged
merged 2 commits into from
Jan 25, 2023
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
4 changes: 2 additions & 2 deletions packages/core/src/generator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -637,8 +637,8 @@ export function createGenerator<Theme extends {} = {}>(config?: UserConfig<Theme
return new UnoGenerator<Theme>(config, defaults)
}

export const regexScopePlaceholder = / \$\$ /
export const hasScopePlaceholder = (css: string) => css.match(regexScopePlaceholder)
export const regexScopePlaceholder = /\s\$\$\s+/g
export const hasScopePlaceholder = (css: string) => css.match(/\s\$\$\s/)

function applyScope(css: string, scope?: string) {
if (hasScopePlaceholder(css))
Expand Down
6 changes: 6 additions & 0 deletions test/__snapshots__/preset-mini.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ exports[`preset-mini > custom var prefix 1`] = `
.scale-100{--hi-scale-x:1;--hi-scale-y:1;transform:translateX(var(--hi-translate-x)) translateY(var(--hi-translate-y)) translateZ(var(--hi-translate-z)) rotate(var(--hi-rotate)) rotateX(var(--hi-rotate-x)) rotateY(var(--hi-rotate-y)) rotateZ(var(--hi-rotate-z)) skewX(var(--hi-skew-x)) skewY(var(--hi-skew-y)) scaleX(var(--hi-scale-x)) scaleY(var(--hi-scale-y)) scaleZ(var(--hi-scale-z));}"
`;

exports[`preset-mini > dark class 1`] = `
"/* layer: default */
.dark .hello .dark\\\\:scope-\\\\[\\\\.hello\\\\]\\\\:text-1\\\\/2{font-size:0.25rem;line-height:0.5rem;}
.light [world] .scope-\\\\[\\\\[world\\\\]\\\\]\\\\:light\\\\:text-1\\\\/3{font-size:0.25rem;line-height:0.75rem;}"
`;

exports[`preset-mini > dark customizing selector 1`] = `
"/* layer: default */
[data-mode=\\"dark\\"] .dark\\\\:bg-white{--un-bg-opacity:1;background-color:rgba(255,255,255,var(--un-bg-opacity));}
Expand Down
17 changes: 17 additions & 0 deletions test/preset-mini.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,21 @@ describe('preset-mini', () => {
expect(uno.config.theme.fontSize.lg).toEqual(['3rem', '1.5em'])
expect(css).toMatchSnapshot()
})

test('dark class', async () => {
const uno = createGenerator({
presets: [
presetMini(),
],
})

const { css } = await uno.generate([
'dark:scope-[.hello]:text-1/2',
'scope-[[world]]:light:text-1/3',
].join(' '), {
preflights: false,
})

expect(css).toMatchSnapshot()
})
})