Skip to content

Commit

Permalink
fix(core): replace scope placeholder globally (#2071)
Browse files Browse the repository at this point in the history
Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>
Fix #2068
  • Loading branch information
chu121su12 committed Jan 25, 2023
1 parent fcab142 commit f2d6b6c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/core/src/generator/index.ts
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
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
Expand Up @@ -159,4 +159,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()
})
})

0 comments on commit f2d6b6c

Please sign in to comment.