Skip to content

Commit

Permalink
fix(preset-attributify): fix parsing error for inline arrow functions (
Browse files Browse the repository at this point in the history
  • Loading branch information
lzl0304 committed Mar 26, 2024
1 parent 112f256 commit 13faa7a
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/preset-attributify/src/extractor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const strippedPrefixes = [
]

const splitterRE = /[\s'"`;]+/g
const elementRE = /<[^>\s]*\s((?:'.*?'|".*?"|`.*?`|\{.*?\}|[^>]*?)*)/g
const elementRE = /<[^>\s]*\s((?:'.*?'|".*?"|`.*?`|\{.*?\}|=>|[^>]*?)*)/g
const valuedAttributeRE = /([?]|(?!\d|-{2}|-\d)[a-zA-Z0-9\u00A0-\uFFFF-_:!%-.~<]+)=?(?:["]([^"]*)["]|[']([^']*)[']|[{]([^}]*)[}])?/gms

export const defaultIgnoreAttributes = ['placeholder', 'fill', 'opacity', 'stroke-opacity']
Expand Down
18 changes: 18 additions & 0 deletions test/__snapshots__/preset-attributify.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,24 @@ exports[`attributify > prefixedOnly 1`] = `
[un-children~="m-auto"]>*{margin:auto;}"
`;

exports[`attributify > support inline arrow functions 1`] = `
"/* layer: default */
.h-1px,
[h-1px=""]{height:1px;}"
`;

exports[`attributify > support inline arrow functions 2`] = `
"/* layer: default */
.h-1px,
[h-1px=""]{height:1px;}"
`;

exports[`attributify > support inline arrow functions 3`] = `
"/* layer: default */
.h-1px,
[h-1px=""]{height:1px;}"
`;

exports[`attributify > variant 1`] = `
[
"uno-layer-base-c-white/10",
Expand Down
30 changes: 30 additions & 0 deletions test/preset-attributify.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,4 +210,34 @@ describe('attributify', async () => {
`, { preflights: false })
expect(css).toMatchSnapshot()
})

it('support inline arrow functions', async () => {
const uno = createGenerator({
presets: [
presetAttributify(),
presetUno(),
],
})
const { css: css1 } = await uno.generate('<div v-for="(v, i) of [0].map(() => 1)" h-1px />', { preflights: false })
expect(css1).toMatchSnapshot()

const { css: css2 } = await uno.generate(`
<div
h-1px
v-for="(
v, i
) of [0].map(() => 1)"
/>
`, { preflights: false })
expect(css2).toMatchSnapshot()

const { css: css3 } = await uno.generate(`
<div v-for="(
v, i
) of [0].map(() => 1)"
h-1px
/>
`, { preflights: false })
expect(css3).toMatchSnapshot()
})
})

0 comments on commit 13faa7a

Please sign in to comment.