@@ -43,10 +43,6 @@ function createValidTests(prefix, options) {
4343 code : `<template><div v-if="${ prefix } foo()">{{ ${ prefix } bar }}</div></template><!-- ${ comment } -->` ,
4444 options
4545 } ,
46- {
47- code : `<template><div :parent="this"></div></template><!-- ${ comment } -->` ,
48- options
49- } ,
5046 {
5147 code : `<template><div v-for="x of ${ prefix } xs">{{this.x}}</div></template><!-- ${ comment } -->` ,
5248 options
@@ -67,26 +63,6 @@ function createValidTests(prefix, options) {
6763 code : `<template><div v-for="x of ${ prefix } xs">{{this['x']}}</div></template><!-- ${ comment } -->` ,
6864 options
6965 } ,
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- } ,
9066 {
9167 code : `<template>
9268 <div>
@@ -97,12 +73,6 @@ function createValidTests(prefix, options) {
9773 </div>
9874 </template><!-- ${ comment } -->` ,
9975 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
10676 }
10777 ]
10878}
@@ -181,30 +151,14 @@ function createInvalidTests(prefix, options, message, type) {
181151 ) } bar"></div></template><!-- ${ comment } -->`,
182152 errors : [ { message, type } ] ,
183153 options
184- } ,
154+ }
185155
186156 // We cannot use `.` in dynamic arguments because the right of the `.` becomes a modifier.
187157 // {
188158 // code: `<template><div v-on:[${prefix}name]="1"></div></template><!-- ${comment} -->`,
189159 // errors: [{ message, type }],
190160 // options
191161 // }
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- ] )
208162 ]
209163}
210164
@@ -216,7 +170,41 @@ ruleTester.run('this-in-template', rule, {
216170 ...createValidTests ( '' , [ ] ) ,
217171 ...createValidTests ( '' , [ 'never' ] ) ,
218172 ...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+ } )
220208 ] ,
221209 invalid : [
222210 ...createInvalidTests (
@@ -244,6 +232,25 @@ ruleTester.run('this-in-template', rule, {
244232 'ThisExpression'
245233 ) ,
246234 ...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+ } ) ,
247254 {
248255 code : `<template><div v-if="fn(this.$foo)"></div></template><!-- never -->` ,
249256 output : `<template><div v-if="fn($foo)"></div></template><!-- never -->` ,
0 commit comments