Skip to content

Commit 139bf0b

Browse files
committed
fix(no-deprecated-slot-attribute): handle v-for with dynamic slot
1 parent 705d262 commit 139bf0b

File tree

2 files changed

+44
-5
lines changed

2 files changed

+44
-5
lines changed

lib/rules/syntaxes/slot-attribute.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,8 @@ module.exports = {
5656
// parse error or empty expression
5757
return false
5858
}
59-
const slotName = sourceCode.getText(slotAttr.value.expression).trim()
60-
// If non-Latin characters are included it can not be converted.
61-
// It does not check the space only because `a>b?c:d` should be rejected.
62-
return !/[^a-z]/i.test(slotName)
59+
60+
return slotAttr.value.expression.type === 'Identifier'
6361
}
6462

6563
/**
@@ -102,7 +100,18 @@ module.exports = {
102100
yield fixer.remove(scopeAttr)
103101
}
104102

105-
yield fixer.insertTextBefore(element, `<template ${replaceText}>\n`)
103+
const vFor = startTag.attributes.find(
104+
(attr) => attr.directive && attr.key.name.name === 'for'
105+
)
106+
const vForText = vFor ? `${sourceCode.getText(vFor)} ` : ''
107+
if (vFor) {
108+
yield fixer.remove(vFor)
109+
}
110+
111+
yield fixer.insertTextBefore(
112+
element,
113+
`<template ${vForText}${replaceText}>\n`
114+
)
106115
yield fixer.insertTextAfter(element, `\n</template>`)
107116
}
108117
}

tests/lib/rules/no-deprecated-slot-attribute.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,36 @@ tester.run('no-deprecated-slot-attribute', rule, {
643643
}
644644
],
645645
errors: ['`slot` attributes are deprecated.']
646+
},
647+
{
648+
code: `
649+
<template>
650+
<my-component>
651+
<slot
652+
v-for="slot in Object.keys($slots)"
653+
:slot="slot"
654+
:name="slot"
655+
></slot>
656+
</my-component>
657+
</template>`,
658+
output: `
659+
<template>
660+
<my-component>
661+
<template v-for="slot in Object.keys($slots)" v-slot:[slot]>
662+
<slot
663+
664+
665+
:name="slot"
666+
></slot>
667+
</template>
668+
</my-component>
669+
</template>`,
670+
options: [
671+
{
672+
ignore: ['one']
673+
}
674+
],
675+
errors: ['`slot` attributes are deprecated.']
646676
}
647677
]
648678
})

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy