Skip to content

Commit 38a38f1

Browse files
authored
Update index.js
1 parent 8788bc8 commit 38a38f1

File tree

1 file changed

+31
-10
lines changed

1 file changed

+31
-10
lines changed

Diff for: lib/utils/index.js

+31-10
Original file line numberDiff line numberDiff line change
@@ -1553,6 +1553,12 @@ module.exports = {
15531553
const left = getLeftOfDefineProps(node)
15541554
return left?.type === 'ObjectPattern'
15551555
},
1556+
/**
1557+
* Gets the props destructure property nodes for defineProp.
1558+
* @param {CallExpression} node The node of defineProps
1559+
* @returns { Record<string, AssignmentProperty | undefined> }
1560+
*/
1561+
getPropsDestructure,
15561562

15571563
getVueObjectType,
15581564
/**
@@ -3161,30 +3167,45 @@ function getWithDefaultsProps(node) {
31613167
}
31623168

31633169
/**
3164-
* Gets the default definition nodes for defineProp
3165-
* using the props destructure with assignment pattern.
3170+
* Gets the props destructure property nodes for defineProp.
31663171
* @param {CallExpression} node The node of defineProps
3167-
* @returns { Record<string, {prop: AssignmentProperty , expression: Expression} | undefined> }
3172+
* @returns { Record<string, AssignmentProperty | undefined> }
31683173
*/
3169-
function getDefaultPropExpressionsForPropsDestructure(node) {
3174+
function getPropsDestructure(node) {
3175+
/** @type {ReturnType<typeof getPropsDestructure>} */
3176+
const result = Object.create(null)
31703177
const left = getLeftOfDefineProps(node)
31713178
if (!left || left.type !== 'ObjectPattern') {
3172-
return {}
3179+
return result
31733180
}
3174-
/** @type {ReturnType<typeof getDefaultPropExpressionsForPropsDestructure>} */
3175-
const result = Object.create(null)
31763181
for (const prop of left.properties) {
31773182
if (prop.type !== 'Property') continue
3178-
const value = prop.value
3179-
if (value.type !== 'AssignmentPattern') continue
31803183
const name = getStaticPropertyName(prop)
31813184
if (name != null) {
3182-
result[name] = { prop, expression: value.right }
3185+
result[name] = prop
31833186
}
31843187
}
31853188
return result
31863189
}
31873190

3191+
/**
3192+
* Gets the default definition nodes for defineProp
3193+
* using the props destructure with assignment pattern.
3194+
* @param {CallExpression} node The node of defineProps
3195+
* @returns { Record<string, {prop: AssignmentProperty , expression: Expression} | undefined> }
3196+
*/
3197+
function getDefaultPropExpressionsForPropsDestructure(node) {
3198+
/** @type {ReturnType<typeof getDefaultPropExpressionsForPropsDestructure>} */
3199+
const result = Object.create(null)
3200+
for (const [name, prop] of Object.entries(getPropsDestructure(node))) {
3201+
if (!prop) continue
3202+
const value = prop.value
3203+
if (value.type !== 'AssignmentPattern') continue
3204+
result[name] = { prop, expression: value.right }
3205+
}
3206+
return result
3207+
}
3208+
31883209
/**
31893210
* Gets the pattern of the left operand of defineProps.
31903211
* @param {CallExpression} node The node of defineProps

0 commit comments

Comments
 (0)