@@ -12,9 +12,27 @@ const utils = require('../utils')
1212const eslintUtils = require ( 'eslint-utils' )
1313
1414/**
15- * @typedef {import('../utils').ComponentPropertyData } ComponentPropertyData
15+ * @typedef {import('../utils').GroupName } GroupName
1616 * @typedef {import('../utils').VueObjectData } VueObjectData
1717 */
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+
1836/**
1937 * @typedef {object } TemplatePropertiesContainer
2038 * @property {UsedProperties } usedProperties
@@ -256,7 +274,7 @@ class ParamsUsedProperties {
256274 return param
257275 }
258276 if ( this . node . params [ index ] ) {
259- return ( this . params [ index ] = extractParamProperties (
277+ return ( this . params [ index ] = extractParamOrVerProperties (
260278 this . node . params [ index ] ,
261279 this . context
262280 ) )
@@ -270,7 +288,7 @@ class ParamsUsedProperties {
270288 * @param {RuleContext } context
271289 * @returns {UsedProperties }
272290 */
273- function extractParamProperties ( node , context ) {
291+ function extractParamOrVerProperties ( node , context ) {
274292 const result = new UsedProperties ( )
275293
276294 while ( node . type === 'AssignmentPattern' ) {
@@ -826,7 +844,58 @@ module.exports = {
826844 }
827845
828846 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+ } ) ,
830899 utils . defineVueVisitor ( context , {
831900 onVueObjectEnter ( node ) {
832901 const container = getVueComponentPropertiesContainer ( node )
0 commit comments