Skip to content

Commit

Permalink
Fix eslint crash when using object spread inside prop definition (#295)
Browse files Browse the repository at this point in the history
* add test for prop default with object spread

* fixes #287:

check for key
  • Loading branch information
jaredhobbs authored and michalsnik committed Dec 19, 2017
1 parent e681dfe commit d6fca8f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/rules/require-default-prop.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ module.exports = {
}

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

return Boolean(propDefaultNode)
}
Expand Down
28 changes: 28 additions & 0 deletions tests/lib/rules/require-default-prop.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,34 @@ ruleTester.run('require-default-prop', rule, {
}
`,
parserOptions
},
{
filename: 'test.vue',
code: `
const x = {
type: Object,
default() {
return {
foo: 1,
bar: 2
}
}
}
export default {
props: {
a: {
...x,
default() {
return {
...x.default(),
baz: 3
}
}
}
}
}
`,
parserOptions
}
],

Expand Down

0 comments on commit d6fca8f

Please sign in to comment.