File tree Expand file tree Collapse file tree 7 files changed +35
-16
lines changed
typings/eslint-plugin-vue/util-types/ast Expand file tree Collapse file tree 7 files changed +35
-16
lines changed Original file line number Diff line number Diff line change @@ -116,16 +116,14 @@ module.exports = {
116
116
utils . compositingVisitors (
117
117
utils . defineVueVisitor ( context , {
118
118
onSetupFunctionEnter ( node , { node : vueNode } ) {
119
- const contextParam = node . params [ 1 ]
119
+ const contextParam = utils . unwrapAssignmentPattern ( node . params [ 1 ] )
120
120
if ( ! contextParam ) {
121
121
// no arguments
122
122
return
123
123
}
124
124
if (
125
125
contextParam . type === 'RestElement' ||
126
- contextParam . type === 'ArrayPattern' ||
127
- contextParam . type === 'MemberExpression' ||
128
- contextParam . type === 'AssignmentPattern'
126
+ contextParam . type === 'ArrayPattern'
129
127
) {
130
128
// cannot check
131
129
return
Original file line number Diff line number Diff line change @@ -179,7 +179,6 @@ module.exports = {
179
179
}
180
180
} ,
181
181
onSetupFunctionEnter ( node ) {
182
- /** @type {Pattern } */
183
182
const propsParam = node . params [ 0 ]
184
183
if ( ! propsParam ) {
185
184
// no arguments
Original file line number Diff line number Diff line change @@ -81,16 +81,12 @@ module.exports = {
81
81
scopeStack = { upper : scopeStack , functionNode : node }
82
82
} ,
83
83
onSetupFunctionEnter ( node ) {
84
- const propsParam = node . params [ 0 ]
84
+ const propsParam = utils . unwrapAssignmentPattern ( node . params [ 0 ] )
85
85
if ( ! propsParam ) {
86
86
// no arguments
87
87
return
88
88
}
89
- if (
90
- propsParam . type === 'RestElement' ||
91
- propsParam . type === 'MemberExpression' ||
92
- propsParam . type === 'AssignmentPattern'
93
- ) {
89
+ if ( propsParam . type === 'RestElement' ) {
94
90
// cannot check
95
91
return
96
92
}
Original file line number Diff line number Diff line change @@ -330,7 +330,7 @@ class ParamUsedProps extends UsedProps {
330
330
*/
331
331
constructor ( paramNode , context ) {
332
332
super ( )
333
- if ( paramNode . type === 'AssignmentPattern' ) {
333
+ while ( paramNode . type === 'AssignmentPattern' ) {
334
334
paramNode = paramNode . left
335
335
}
336
336
if ( paramNode . type === 'RestElement' || paramNode . type === 'ArrayPattern' ) {
Original file line number Diff line number Diff line change @@ -1418,6 +1418,7 @@ module.exports = {
1418
1418
* @return {T }
1419
1419
*/
1420
1420
unwrapTypes,
1421
+ unwrapAssignmentPattern,
1421
1422
1422
1423
/**
1423
1424
* Check whether the given node is `this` or variable that stores `this`.
@@ -1566,6 +1567,22 @@ function unwrapTypes(node) {
1566
1567
return node
1567
1568
}
1568
1569
1570
+ /**
1571
+ * Unwrap AssignmentPattern like "(a = 1) => ret"
1572
+ * @param { AssignmentPattern | RestElement | ArrayPattern | ObjectPattern | Identifier } node
1573
+ * @return { RestElement | ArrayPattern | ObjectPattern | Identifier }
1574
+ */
1575
+ function unwrapAssignmentPattern ( node ) {
1576
+ if ( ! node ) {
1577
+ return node
1578
+ }
1579
+ if ( node . type === 'AssignmentPattern' ) {
1580
+ // @ts -ignore
1581
+ return unwrapAssignmentPattern ( node . left )
1582
+ }
1583
+ return node
1584
+ }
1585
+
1569
1586
/**
1570
1587
* Gets the property name of a given node.
1571
1588
* @param {Property|AssignmentProperty|MethodDefinition|MemberExpression } node - The node to get.
Original file line number Diff line number Diff line change @@ -159,7 +159,7 @@ export interface FunctionDeclaration extends HasParentNode {
159
159
async : boolean
160
160
generator : boolean
161
161
id : Identifier | null
162
- params : Pattern [ ]
162
+ params : _FunctionParameter [ ]
163
163
body : BlockStatement
164
164
}
165
165
export interface VariableDeclaration extends HasParentNode {
@@ -305,7 +305,7 @@ export interface FunctionExpression extends HasParentNode {
305
305
async : boolean
306
306
generator : boolean
307
307
id : Identifier | null
308
- params : Pattern [ ]
308
+ params : _FunctionParameter [ ]
309
309
body : BlockStatement
310
310
}
311
311
@@ -314,7 +314,7 @@ interface ArrowFunctionExpressionHasBlock extends HasParentNode {
314
314
async : boolean
315
315
generator : boolean
316
316
id : Identifier | null
317
- params : Pattern [ ]
317
+ params : _FunctionParameter [ ]
318
318
body : BlockStatement
319
319
expression : false
320
320
}
@@ -324,7 +324,7 @@ interface ArrowFunctionExpressionNoBlock extends HasParentNode {
324
324
async : boolean
325
325
generator : boolean
326
326
id : Identifier | null
327
- params : Pattern [ ]
327
+ params : _FunctionParameter [ ]
328
328
body : Expression
329
329
expression : true
330
330
}
@@ -503,3 +503,11 @@ export interface AssignmentPattern extends HasParentNode {
503
503
left : Pattern
504
504
right : Expression
505
505
}
506
+
507
+ type _FunctionParameter =
508
+ | AssignmentPattern
509
+ | RestElement
510
+ | ArrayPattern
511
+ | ObjectPattern
512
+ | Identifier
513
+ // | TSParameterProperty;
Original file line number Diff line number Diff line change 1
1
import { HasParentNode } from '../node'
2
2
import * as ES from './es-ast'
3
3
export type TSNode = TSAsExpression
4
+
4
5
export interface TSAsExpression extends HasParentNode {
5
6
type : 'TSAsExpression'
6
7
expression : ES . Expression
You can’t perform that action at this time.
0 commit comments