Skip to content

Commit

Permalink
fix(preset-attributify): try to break out of unmatched regex (#2134)
Browse files Browse the repository at this point in the history
  • Loading branch information
chu121su12 committed Feb 1, 2023
1 parent eea51f6 commit 0210a93
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/preset-attributify/src/extractor.ts
Expand Up @@ -8,7 +8,7 @@ const strippedPrefixes = [
]

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

export const defaultIgnoreAttributes = ['placeholder', 'fill', 'opacity']
Expand All @@ -22,6 +22,7 @@ export const extractorAttributify = (options?: AttributifyOptions): Extractor =>
name: 'attributify',
extract({ code }) {
const result = Array.from(code.matchAll(elementRE))
.filter(match => match[0].endsWith('>'))
.flatMap(match => Array.from((match[1] || '').matchAll(valuedAttributeRE)))
.flatMap(([, name, ...contents]) => {
const content = contents.filter(Boolean).join('')
Expand Down

0 comments on commit 0210a93

Please sign in to comment.