airbnb-prop-types
Advanced tools
Comparing version 2.13.0 to 2.13.1
@@ -8,2 +8,4 @@ "use strict"; | ||
var _react = require("react"); | ||
var _isPlainObject = _interopRequireDefault(require("./helpers/isPlainObject")); | ||
@@ -24,6 +26,10 @@ | ||
function isCallbackRef(prop) { | ||
return typeof prop === 'function' && !Object.prototype.isPrototypeOf.call(_react.Component, prop) && (!_react.PureComponent || !Object.prototype.isPrototypeOf.call(_react.PureComponent, prop)) && prop.length === 1; | ||
} | ||
function requiredRef(props, propName, componentName) { | ||
var propValue = props[propName]; | ||
if (typeof propValue === 'function' || isNewRef(propValue)) { | ||
if (isCallbackRef(propValue) || isNewRef(propValue)) { | ||
return null; | ||
@@ -30,0 +36,0 @@ } |
@@ -0,1 +1,5 @@ | ||
2.13.1 / 2019-04-06 | ||
================== | ||
* [Fix] `ref`: ensure that the prop value is not a component (#55) | ||
2.13.0 / 2019-04-04 | ||
@@ -2,0 +6,0 @@ ================== |
{ | ||
"name": "airbnb-prop-types", | ||
"version": "2.13.0", | ||
"version": "2.13.1", | ||
"description": "Custom React PropType validators that we use at Airbnb.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -0,1 +1,2 @@ | ||
import { Component, PureComponent } from 'react'; | ||
import isPlainObject from './helpers/isPlainObject'; | ||
@@ -12,6 +13,13 @@ import wrapValidator from './helpers/wrapValidator'; | ||
function isCallbackRef(prop) { | ||
return typeof prop === 'function' | ||
&& !Object.prototype.isPrototypeOf.call(Component, prop) | ||
&& (!PureComponent || !Object.prototype.isPrototypeOf.call(PureComponent, prop)) | ||
&& prop.length === 1; | ||
} | ||
function requiredRef(props, propName, componentName) { | ||
const propValue = props[propName]; | ||
if (typeof propValue === 'function' || isNewRef(propValue)) { | ||
if (isCallbackRef(propValue) || isNewRef(propValue)) { | ||
return null; | ||
@@ -18,0 +26,0 @@ } |
@@ -34,3 +34,3 @@ import { expect } from 'chai'; | ||
it('passes with legacy refs', () => { | ||
assertPasses(validator, <div someRef={() => {}} />, 'someRef'); | ||
assertPasses(validator, <div someRef={(node) => {}} />, 'someRef'); // eslint-disable-line no-unused-vars | ||
}); | ||
@@ -42,3 +42,21 @@ | ||
it('fails with non-refs', () => { | ||
it('fails with React components', () => { | ||
class A extends React.Component { | ||
constructor(props) {} // eslint-disable-line | ||
} | ||
assertFails(validator, <div someRef={A} />, 'someRef'); | ||
}); | ||
it('fails with React pure components', () => { | ||
class B extends React.PureComponent { | ||
constructor(props) {} // eslint-disable-line | ||
} | ||
assertFails(validator, <div someRef={B} />, 'someRef'); | ||
}); | ||
it('fails with non-ref functions', () => { | ||
assertFails(validator, <div someRef={() => {}} />, 'someRef'); | ||
}); | ||
it('fails with other non-refs', () => { | ||
assertFails(validator, <div someRef={666} />, 'someRef'); | ||
@@ -61,3 +79,3 @@ }); | ||
it('passes with legacy refs', () => { | ||
assertPasses(validator, <div someRef={() => {}} />, 'someRef'); | ||
assertPasses(validator, <div someRef={(node) => {}} />, 'someRef'); // eslint-disable-line no-unused-vars | ||
}); | ||
@@ -69,3 +87,21 @@ | ||
it('fails with non-refs', () => { | ||
it('fails with React components', () => { | ||
class A extends React.Component { | ||
constructor(props) {} // eslint-disable-line | ||
} | ||
assertFails(validator, <div someRef={A} />, 'someRef'); | ||
}); | ||
it('fails with React pure components', () => { | ||
class B extends React.PureComponent { | ||
constructor(props) {} // eslint-disable-line | ||
} | ||
assertFails(validator, <div someRef={B} />, 'someRef'); | ||
}); | ||
it('fails with non-ref functions', () => { | ||
assertFails(validator, <div someRef={() => {}} />, 'someRef'); | ||
}); | ||
it('fails with other non-refs', () => { | ||
assertFails(validator, <div someRef={666} />, 'someRef'); | ||
@@ -72,0 +108,0 @@ }); |
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
423476
7255
0