New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix siblings and interleaving issues reported in #2342 #2348
base: master
Are you sure you want to change the base?
Fix siblings and interleaving issues reported in #2342 #2348
Conversation
Hi @FloEdelmann, thank you for reporting #2342, I have hopefully addressed those here, please let me know if I missed something. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have not yet looked into your implementation, but I noticed one wrong test case.
const siblings = node.parent.children.filter( | ||
(child) => child.type === 'VElement' | ||
) | ||
|
||
return siblings.some( | ||
(sibling) => | ||
sibling !== node && | ||
sibling.type === 'VElement' && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we need to check the element's type anyway in the some
predicate, then we can avoid filter
ing the list before.
const siblings = node.parent.children.filter( | |
(child) => child.type === 'VElement' | |
) | |
return siblings.some( | |
(sibling) => | |
sibling !== node && | |
sibling.type === 'VElement' && | |
return node.parent.children.some( | |
(sibling) => | |
sibling !== node && | |
sibling.type === 'VElement' && |
let needsKey = false | ||
|
||
context.report({ | ||
node: node.startTag, | ||
loc: node.startTag.loc, | ||
messageId: 'requireKey', | ||
data: { | ||
componentName | ||
}, | ||
fix(fixer) { | ||
const afterComponentNamePosition = | ||
node.startTag.range[0] + componentName.length + 1 | ||
return fixer.insertTextBeforeRange( | ||
[afterComponentNamePosition, afterComponentNamePosition], | ||
` key="${uniqueKey}"` | ||
) | ||
if (node === conditionalFamily.if || node === conditionalFamily.else) { | ||
needsKey = true | ||
} else if (conditionalFamily.elseIf.includes(node)) { | ||
needsKey = true | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please replace with a single const:
const needsKey =
conditionalFamily.if === node ||
conditionalFamily.else === node ||
conditionalFamily.elseIf.includes(node)
// Reset if family already has an 'if' directive | ||
usageInfo.count = 1 | ||
usageInfo.firstNode = node |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this work for the following case? Please also add this as a test case:
<ComponentA v-if="foo" />
<ComponentA v-else />
<ComponentA v-if="bar" />
<ComponentA v-else-if="baz" />
<ComponentA v-else />
An error should be reported for all of them.
This PR addresses the bugs reported in #2342
And added tests