@@ -9,18 +9,16 @@ const traverseNodes = vueAST.traverseNodes;
99
1010const UNKNOWN = Symbol ( "unknown" ) ;
1111
12- type DataPropertyNode = AST . ESLintExpression | AST . ESLintPattern ;
13- type ComputedPropertyNode = AST . ESLintExpression | AST . ESLintPattern ;
1412type Properties = {
1513 data :
1614 | {
17- [ key : string ] : DataPropertyNode [ ] ;
15+ [ key : string ] : AST . ESLintExpression [ ] ;
1816 [ UNKNOWN ] ?: true ;
1917 }
2018 | typeof UNKNOWN ;
2119 computed :
2220 | {
23- [ key : string ] : ComputedPropertyNode [ ] ;
21+ [ key : string ] : AST . ESLintExpression [ ] ;
2422 [ UNKNOWN ] ?: true ;
2523 }
2624 | typeof UNKNOWN ;
@@ -44,14 +42,13 @@ export class VueComponentContext {
4442 * @param {string } name property name
4543 * @returns {ASTNode[] } the Vue component property value nodes
4644 */
47- public findVueComponentProperty (
48- name : string
49- ) :
50- | ( AST . ESLintBlockStatement | AST . ESLintExpression | AST . ESLintPattern ) [ ]
51- | null {
45+ public findVueComponentProperty ( name : string ) : AST . ESLintExpression [ ] | null {
5246 const properties =
5347 this . properties ||
54- ( this . properties = extractVueComponentPropertes ( this . node , this . context ) ) ;
48+ ( this . properties = extractVueComponentProperties (
49+ this . node ,
50+ this . context
51+ ) ) ;
5552
5653 if ( properties [ UNKNOWN ] ) {
5754 return null ;
@@ -108,7 +105,7 @@ export function createVueComponentContext(
108105/**
109106 * Extract properties and properties value nodes, of Vue component.
110107 */
111- function extractVueComponentPropertes (
108+ function extractVueComponentProperties (
112109 vueNode : AST . ESLintObjectExpression ,
113110 context : RuleContext
114111) : Properties {
@@ -123,9 +120,15 @@ function extractVueComponentPropertes(
123120 }
124121 const keyName = getPropertyOrIdentifierName ( p ) ;
125122 if ( keyName === "data" ) {
126- result . data = extractVueComponentData ( p . value , context ) ;
123+ result . data = extractVueComponentData (
124+ p . value as AST . ESLintExpression ,
125+ context
126+ ) ;
127127 } else if ( keyName === "computed" ) {
128- result . computed = extractVueComponentComputed ( p . value , context ) ;
128+ result . computed = extractVueComponentComputed (
129+ p . value as AST . ESLintExpression ,
130+ context
131+ ) ;
129132 }
130133 }
131134 return result ;
@@ -135,11 +138,11 @@ function extractVueComponentPropertes(
135138 * Extract data, of Vue component.
136139 */
137140function extractVueComponentData (
138- dataNode : AST . ESLintExpression | AST . ESLintPattern ,
141+ dataNode : AST . ESLintExpression ,
139142 context : RuleContext
140143) :
141144 | {
142- [ key : string ] : DataPropertyNode [ ] ;
145+ [ key : string ] : AST . ESLintExpression [ ] ;
143146 [ UNKNOWN ] ?: true ;
144147 }
145148 | typeof UNKNOWN {
@@ -171,7 +174,7 @@ function extractVueComponentData(
171174 return UNKNOWN ;
172175 }
173176 const data : {
174- [ key : string ] : DataPropertyNode [ ] ;
177+ [ key : string ] : AST . ESLintExpression [ ] ;
175178 [ UNKNOWN ] ?: true ;
176179 } = { } ;
177180 for ( const dataObj of dataNodes ) {
@@ -188,7 +191,7 @@ function extractVueComponentData(
188191 data [ UNKNOWN ] = true ;
189192 } else {
190193 const values = data [ keyName ] || ( data [ keyName ] = [ ] ) ;
191- values . push ( prop . value ) ;
194+ values . push ( prop . value as AST . ESLintExpression ) ;
192195 }
193196 } else {
194197 // Can not identify the key name.
@@ -203,11 +206,11 @@ function extractVueComponentData(
203206 * Extract computed properties, of Vue component.
204207 */
205208function extractVueComponentComputed (
206- computedNode : AST . ESLintExpression | AST . ESLintPattern ,
209+ computedNode : AST . ESLintExpression ,
207210 context : RuleContext
208211) :
209212 | {
210- [ key : string ] : ComputedPropertyNode [ ] ;
213+ [ key : string ] : AST . ESLintExpression [ ] ;
211214 [ UNKNOWN ] ?: true ;
212215 }
213216 | typeof UNKNOWN {
@@ -217,7 +220,7 @@ function extractVueComponentComputed(
217220 }
218221
219222 const computed : {
220- [ key : string ] : ComputedPropertyNode [ ] ;
223+ [ key : string ] : AST . ESLintExpression [ ] ;
221224 [ UNKNOWN ] ?: true ;
222225 } = { } ;
223226 for ( const p of computedNode . properties ) {
@@ -233,15 +236,15 @@ function extractVueComponentComputed(
233236 continue ;
234237 }
235238 const values = computed [ keyName ] || ( computed [ keyName ] = [ ] ) ;
236- const { value } = p ;
237- let func : AST . ESLintExpression | AST . ESLintPattern = value ;
239+ const value = p . value as AST . ESLintExpression ;
240+ let func : AST . ESLintExpression = value ;
238241
239242 if ( value . type === "ObjectExpression" ) {
240243 const get = value . properties
241244 . filter ( isProperty )
242245 . find ( ( prop ) => getPropertyOrIdentifierName ( prop ) === "get" ) ;
243246 if ( get ) {
244- func = get . value ;
247+ func = get . value as AST . ESLintExpression ;
245248 }
246249 }
247250 if (
0 commit comments