@@ -12,9 +12,27 @@ const utils = require('../utils')
12
12
const eslintUtils = require ( 'eslint-utils' )
13
13
14
14
/**
15
- * @typedef {import('../utils').ComponentPropertyData } ComponentPropertyData
15
+ * @typedef {import('../utils').GroupName } GroupName
16
16
* @typedef {import('../utils').VueObjectData } VueObjectData
17
17
*/
18
+
19
+ /**
20
+ * @typedef {object } ComponentObjectPropertyData
21
+ * @property {string } name
22
+ * @property {GroupName } groupName
23
+ * @property {'object' } type
24
+ * @property {ASTNode } node
25
+ * @property {Property } property
26
+ *
27
+ * @typedef {object } ComponentNonObjectPropertyData
28
+ * @property {string } name
29
+ * @property {GroupName } groupName
30
+ * @property {'array' | 'type' } type
31
+ * @property {ASTNode } node
32
+ *
33
+ * @typedef { ComponentNonObjectPropertyData | ComponentObjectPropertyData } ComponentPropertyData
34
+ */
35
+
18
36
/**
19
37
* @typedef {object } TemplatePropertiesContainer
20
38
* @property {UsedProperties } usedProperties
@@ -256,7 +274,7 @@ class ParamsUsedProperties {
256
274
return param
257
275
}
258
276
if ( this . node . params [ index ] ) {
259
- return ( this . params [ index ] = extractParamProperties (
277
+ return ( this . params [ index ] = extractParamOrVerProperties (
260
278
this . node . params [ index ] ,
261
279
this . context
262
280
) )
@@ -270,7 +288,7 @@ class ParamsUsedProperties {
270
288
* @param {RuleContext } context
271
289
* @returns {UsedProperties }
272
290
*/
273
- function extractParamProperties ( node , context ) {
291
+ function extractParamOrVerProperties ( node , context ) {
274
292
const result = new UsedProperties ( )
275
293
276
294
while ( node . type === 'AssignmentPattern' ) {
@@ -826,7 +844,58 @@ module.exports = {
826
844
}
827
845
828
846
const scriptVisitor = utils . compositingVisitors (
829
- { } ,
847
+ utils . defineScriptSetupVisitor ( context , {
848
+ onDefinePropsEnter ( node , props ) {
849
+ if ( ! groups . has ( 'props' ) ) {
850
+ return
851
+ }
852
+ const container = getVueComponentPropertiesContainer ( node )
853
+
854
+ for ( const prop of props ) {
855
+ if ( ! prop . propName ) {
856
+ continue
857
+ }
858
+ if ( prop . type === 'object' ) {
859
+ container . properties . push ( {
860
+ type : prop . type ,
861
+ name : prop . propName ,
862
+ groupName : 'props' ,
863
+ node : prop . key ,
864
+ property : prop . node
865
+ } )
866
+ } else {
867
+ container . properties . push ( {
868
+ type : prop . type ,
869
+ name : prop . propName ,
870
+ groupName : 'props' ,
871
+ node : prop . key
872
+ } )
873
+ }
874
+ }
875
+ let target = node
876
+ if (
877
+ target . parent &&
878
+ target . parent . type === 'CallExpression' &&
879
+ target . parent . arguments [ 0 ] === target &&
880
+ target . parent . callee . type === 'Identifier' &&
881
+ target . parent . callee . name === 'withDefaults'
882
+ ) {
883
+ target = target . parent
884
+ }
885
+
886
+ if (
887
+ ! target . parent ||
888
+ target . parent . type !== 'VariableDeclarator' ||
889
+ target . parent . init !== target
890
+ ) {
891
+ return
892
+ }
893
+
894
+ const pattern = target . parent . id
895
+ const usedProps = extractParamOrVerProperties ( pattern , context )
896
+ container . usedPropertiesForProps . merge ( usedProps )
897
+ }
898
+ } ) ,
830
899
utils . defineVueVisitor ( context , {
831
900
onVueObjectEnter ( node ) {
832
901
const container = getVueComponentPropertiesContainer ( node )
0 commit comments