Skip to content

Commit 5c784a0

Browse files
committed
fix this-in-template to avoid making invalid syntax in autofix
1 parent e227f99 commit 5c784a0

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

lib/rules/this-in-template.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ module.exports = {
8484
}
8585
: {
8686
'VExpressionContainer' (node) {
87+
if (node.parent.type === 'VDirectiveKey') {
88+
// We cannot use `.` in dynamic arguments because the right of the `.` becomes a modifier.
89+
// For example, In `:[this.prop]` case, `:[this` is an argument and `prop]` is a modifier.
90+
return
91+
}
8792
if (node.references) {
8893
for (const reference of node.references) {
8994
if (!scope.nodes.some(el => el.name === reference.id.name)) {

tests/lib/rules/this-in-template.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ function createValidTests (prefix, options) {
106106
</div>
107107
</template><!-- ${comment} -->`,
108108
options
109+
},
110+
111+
// We cannot use `.` in dynamic arguments because the right of the `.` becomes a modifier.
112+
{
113+
code: `<template><div v-on:[x]="1"></div></template><!-- ${comment} -->`,
114+
options
109115
}
110116
]
111117
}
@@ -153,6 +159,13 @@ function createInvalidTests (prefix, options, message, type) {
153159
errors: [{ message, type }],
154160
options
155161
}
162+
163+
// We cannot use `.` in dynamic arguments because the right of the `.` becomes a modifier.
164+
// {
165+
// code: `<template><div v-on:[${prefix}name]="1"></div></template><!-- ${comment} -->`,
166+
// errors: [{ message, type }],
167+
// options
168+
// }
156169
].concat(options[0] === 'always'
157170
? []
158171
: [

0 commit comments

Comments
 (0)