Skip to content

Commit d6fca8f

Browse files
jaredhobbsmichalsnik
authored andcommitted
Fix eslint crash when using object spread inside prop definition (#295)
* add test for prop default with object spread * fixes #287: check for key
1 parent e681dfe commit d6fca8f

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

lib/rules/require-default-prop.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ module.exports = {
4343
}
4444

4545
/**
46-
* Checks if the passed prop has a defualt value
46+
* Checks if the passed prop has a default value
4747
* @param {Property} prop - Property AST node for a single prop
4848
* @return {boolean}
4949
*/
5050
function propHasDefault (prop) {
5151
const propDefaultNode = prop.value.properties
52-
.find(p => p.key.name === 'default')
52+
.find(p => p.key && p.key.name === 'default')
5353

5454
return Boolean(propDefaultNode)
5555
}

tests/lib/rules/require-default-prop.js

+28
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,34 @@ ruleTester.run('require-default-prop', rule, {
6868
}
6969
`,
7070
parserOptions
71+
},
72+
{
73+
filename: 'test.vue',
74+
code: `
75+
const x = {
76+
type: Object,
77+
default() {
78+
return {
79+
foo: 1,
80+
bar: 2
81+
}
82+
}
83+
}
84+
export default {
85+
props: {
86+
a: {
87+
...x,
88+
default() {
89+
return {
90+
...x.default(),
91+
baz: 3
92+
}
93+
}
94+
}
95+
}
96+
}
97+
`,
98+
parserOptions
7199
}
72100
],
73101

0 commit comments

Comments
 (0)