Skip to content

Commit

Permalink
[Fix] prop-types: avoid crash when spreading any type
Browse files Browse the repository at this point in the history
Fixes #2605.
  • Loading branch information
golopot committed Mar 25, 2020
1 parent ad18d35 commit a93ef20
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/util/ast.js
Expand Up @@ -155,7 +155,7 @@ function stripQuotes(string) {
* Retrieve the name of a key node
* @param {Context} context The AST node with the key.
* @param {ASTNode} node The AST node with the key.
* @return {string} the name of the key
* @return {string | undefined} the name of the key
*/
function getKeyValue(context, node) {
if (node.type === 'ObjectTypeProperty') {
Expand All @@ -172,6 +172,9 @@ function getKeyValue(context, node) {
return;
}
const key = node.key || node.argument;
if (!key) {
return;
}
return key.type === 'Identifier' ? key.name : key.value;
}

Expand Down
11 changes: 11 additions & 0 deletions tests/lib/rules/prop-types.js
Expand Up @@ -1650,6 +1650,17 @@ ruleTester.run('prop-types', rule, {
'}'
].join('\n'),
parser: parsers.BABEL_ESLINT
}, {
code: `
type FooProps = {
...any,
...42,
}
function Foo(props: FooProps) {
return <p />;
}
`,
parser: parsers.BABEL_ESLINT
}, {
code: [
'type Person = {',
Expand Down

0 comments on commit a93ef20

Please sign in to comment.