Skip to content

Commit

Permalink
fix(preset-attributify): apply prefixedOnly filter on extractor (#1964
Browse files Browse the repository at this point in the history
)
  • Loading branch information
sibbng committed Dec 19, 2022
1 parent 94c0754 commit 8b3bb65
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/preset-attributify/src/extractor.ts
Expand Up @@ -52,6 +52,9 @@ export const extractorAttributify = (options?: AttributifyOptions): Extractor =>
.filter(isValidSelector)
}
else {
if (options?.prefixedOnly && options.prefix && !name.startsWith(options.prefix))
return []

const extractTernary = Array.from(content.matchAll(/(?:[\?:].*?)(["'])([^\1]*?)\1/gms))
.map(([,,v]) => v.split(splitterRE)).flat()
return (extractTernary.length ? extractTernary : content.split(splitterRE))
Expand Down
9 changes: 9 additions & 0 deletions test/__snapshots__/preset-attributify.test.ts.snap
Expand Up @@ -33,6 +33,7 @@ Set {
"[border~=\\"rounded\\"]",
"[border~=\\"blue-200\\"]",
"[un-children~=\\"m-auto\\"]",
"[x-transition:enter-start~=\\"opacity-0\\"]",
"[pt2=\\"\\"]",
"[rounded-sm=\\"\\"]",
"[inline-block=\\"\\"]",
Expand Down Expand Up @@ -330,6 +331,13 @@ exports[`attributify > fixture4 1`] = `
}"
`;

exports[`attributify > prefixedOnly 1`] = `
"/* layer: default */
.absolute{position:absolute;}
.fixed{position:fixed;}
[un-children~=\\"m-auto\\"]>*{margin:auto;}"
`;

exports[`attributify > variant 1`] = `
[
"uno-layer-base-c-white/10",
Expand Down Expand Up @@ -363,6 +371,7 @@ exports[`attributify > variant 1`] = `
"border-rounded",
"border-blue-200",
"children-m-auto",
"x-transition:enter-start-opacity-0",
"pt2",
"rounded-sm",
"inline-block",
Expand Down
15 changes: 15 additions & 0 deletions test/preset-attributify.test.ts
Expand Up @@ -23,6 +23,9 @@ describe('attributify', () => {
v-bind:p="y-2 x-4"
border="2 rounded blue-200"
un-children="m-auto"
x-transition:enter-start="opacity-0"
:x-transition:enter-start="opacity-0"
v-bind:x-transition:enter-start="opacity-0"
pt2 rounded-sm
inline-block
transform
Expand Down Expand Up @@ -174,6 +177,18 @@ describe('attributify', () => {
.toMatchSnapshot()
})

test('prefixedOnly', async () => {
const uno = createGenerator({
presets: [
presetAttributify({ strict: true, prefix: 'un-', prefixedOnly: true }),
presetUno({ attributifyPseudo: true }),
],
})

const { css } = await uno.generate(fixture1, { preflights: false })
expect(css).toMatchSnapshot()
})

test('fixture1', async () => {
const { css } = await uno.generate(fixture1, { preflights: false })
expect(css).toMatchSnapshot()
Expand Down

0 comments on commit 8b3bb65

Please sign in to comment.