@@ -43,10 +43,6 @@ function createValidTests(prefix, options) {
43
43
code : `<template><div v-if="${ prefix } foo()">{{ ${ prefix } bar }}</div></template><!-- ${ comment } -->` ,
44
44
options
45
45
} ,
46
- {
47
- code : `<template><div :parent="this"></div></template><!-- ${ comment } -->` ,
48
- options
49
- } ,
50
46
{
51
47
code : `<template><div v-for="x of ${ prefix } xs">{{this.x}}</div></template><!-- ${ comment } -->` ,
52
48
options
@@ -67,26 +63,6 @@ function createValidTests(prefix, options) {
67
63
code : `<template><div v-for="x of ${ prefix } xs">{{this['x']}}</div></template><!-- ${ comment } -->` ,
68
64
options
69
65
} ,
70
- {
71
- code : `<template><div>{{ this.class }}</div></template><!-- ${ comment } -->` ,
72
- options
73
- } ,
74
- {
75
- code : `<template><div>{{ this['0'] }}</div></template><!-- ${ comment } -->` ,
76
- options
77
- } ,
78
- {
79
- code : `<template><div>{{ this['this'] }}</div></template><!-- ${ comment } -->` ,
80
- options
81
- } ,
82
- {
83
- code : `<template><div>{{ this['foo bar'] }}</div></template><!-- ${ comment } -->` ,
84
- options
85
- } ,
86
- {
87
- code : `<template><div>{{ }}</div></template><!-- ${ comment } -->` ,
88
- options
89
- } ,
90
66
{
91
67
code : `<template>
92
68
<div>
@@ -97,12 +73,6 @@ function createValidTests(prefix, options) {
97
73
</div>
98
74
</template><!-- ${ comment } -->` ,
99
75
options
100
- } ,
101
-
102
- // We cannot use `.` in dynamic arguments because the right of the `.` becomes a modifier.
103
- {
104
- code : `<template><div v-on:[x]="1"></div></template><!-- ${ comment } -->` ,
105
- options
106
76
}
107
77
]
108
78
}
@@ -181,30 +151,14 @@ function createInvalidTests(prefix, options, message, type) {
181
151
) } bar"></div></template><!-- ${ comment } -->`,
182
152
errors : [ { message, type } ] ,
183
153
options
184
- } ,
154
+ }
185
155
186
156
// We cannot use `.` in dynamic arguments because the right of the `.` becomes a modifier.
187
157
// {
188
158
// code: `<template><div v-on:[${prefix}name]="1"></div></template><!-- ${comment} -->`,
189
159
// errors: [{ message, type }],
190
160
// options
191
161
// }
192
- ...( options [ 0 ] === 'always'
193
- ? [ ]
194
- : [
195
- {
196
- code : `<template><div>{{ this['xs'] }}</div></template><!-- ${ comment } -->` ,
197
- output : `<template><div>{{ xs }}</div></template><!-- ${ comment } -->` ,
198
- errors : [ { message, type } ] ,
199
- options
200
- } ,
201
- {
202
- code : `<template><div>{{ this['xs0AZ_foo'] }}</div></template><!-- ${ comment } -->` ,
203
- output : `<template><div>{{ xs0AZ_foo }}</div></template><!-- ${ comment } -->` ,
204
- errors : [ { message, type } ] ,
205
- options
206
- }
207
- ] )
208
162
]
209
163
}
210
164
@@ -216,7 +170,41 @@ ruleTester.run('this-in-template', rule, {
216
170
...createValidTests ( '' , [ ] ) ,
217
171
...createValidTests ( '' , [ 'never' ] ) ,
218
172
...createValidTests ( 'this.' , [ 'always' ] ) ,
219
- ...createValidTests ( 'this?.' , [ 'always' ] )
173
+ ...createValidTests ( 'this?.' , [ 'always' ] ) ,
174
+ ...[ [ ] , [ 'never' ] , [ 'always' ] ] . flatMap ( ( options ) => {
175
+ const comment = options . join ( '' )
176
+ return [
177
+ {
178
+ code : `<template><div :parent="this"></div></template><!-- ${ comment } -->` ,
179
+ options
180
+ } ,
181
+ {
182
+ code : `<template><div>{{ this.class }}</div></template><!-- ${ comment } -->` ,
183
+ options
184
+ } ,
185
+ {
186
+ code : `<template><div>{{ this['0'] }}</div></template><!-- ${ comment } -->` ,
187
+ options
188
+ } ,
189
+ {
190
+ code : `<template><div>{{ this['this'] }}</div></template><!-- ${ comment } -->` ,
191
+ options
192
+ } ,
193
+ {
194
+ code : `<template><div>{{ this['foo bar'] }}</div></template><!-- ${ comment } -->` ,
195
+ options
196
+ } ,
197
+ {
198
+ code : `<template><div>{{ }}</div></template><!-- ${ comment } -->` ,
199
+ options
200
+ } ,
201
+ // We cannot use `.` in dynamic arguments because the right of the `.` becomes a modifier.
202
+ {
203
+ code : `<template><div v-on:[x]="1"></div></template><!-- ${ comment } -->` ,
204
+ options
205
+ }
206
+ ]
207
+ } )
220
208
] ,
221
209
invalid : [
222
210
...createInvalidTests (
@@ -244,6 +232,25 @@ ruleTester.run('this-in-template', rule, {
244
232
'ThisExpression'
245
233
) ,
246
234
...createInvalidTests ( '' , [ 'always' ] , "Expected 'this'." , 'Identifier' ) ,
235
+ ...[ [ ] , [ 'never' ] ] . flatMap ( ( options ) => {
236
+ const comment = options . join ( '' )
237
+ const message = "Unexpected usage of 'this'."
238
+ const type = 'ThisExpression'
239
+ return [
240
+ {
241
+ code : `<template><div>{{ this['xs'] }}</div></template><!-- ${ comment } -->` ,
242
+ output : `<template><div>{{ xs }}</div></template><!-- ${ comment } -->` ,
243
+ errors : [ { message, type } ] ,
244
+ options
245
+ } ,
246
+ {
247
+ code : `<template><div>{{ this['xs0AZ_foo'] }}</div></template><!-- ${ comment } -->` ,
248
+ output : `<template><div>{{ xs0AZ_foo }}</div></template><!-- ${ comment } -->` ,
249
+ errors : [ { message, type } ] ,
250
+ options
251
+ }
252
+ ]
253
+ } ) ,
247
254
{
248
255
code : `<template><div v-if="fn(this.$foo)"></div></template><!-- never -->` ,
249
256
output : `<template><div v-if="fn($foo)"></div></template><!-- never -->` ,
0 commit comments