Skip to content

Commit d5c3670

Browse files
committed
Match against dynamic attributes first
1 parent 8158072 commit d5c3670

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/index.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -280,9 +280,10 @@ function transformHtml(ast: any, { env, changes }: TransformerContext) {
280280
let { parser } = env.options
281281

282282
for (let attr of ast.attrs ?? []) {
283-
if (matcher.hasStaticAttr(attr.name)) {
284-
attr.value = sortClasses(attr.value, { env })
285-
} else if (matcher.hasDynamicAttr(attr.name)) {
283+
// We match against dynamic attributes first otherwise we might accidentally
284+
// interpret a dynamic attribute as a static one. These always start with :,
285+
// v-bind:, or are enclosed in `[…]`
286+
if (matcher.hasDynamicAttr(attr.name)) {
286287
if (!/[`'"]/.test(attr.value)) {
287288
continue
288289
}
@@ -293,6 +294,11 @@ function transformHtml(ast: any, { env, changes }: TransformerContext) {
293294
transformDynamicJsAttribute(attr, env)
294295
}
295296
}
297+
298+
//
299+
else if (matcher.hasStaticAttr(attr.name)) {
300+
attr.value = sortClasses(attr.value, { env })
301+
}
296302
}
297303

298304
for (let child of ast.children ?? []) {

0 commit comments

Comments
 (0)