mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Throw if a reserved property is defined in 'statics'
This commit is contained in:
@@ -555,6 +555,16 @@ function mixStaticSpecIntoComponent(Constructor, statics) {
|
||||
continue;
|
||||
}
|
||||
|
||||
var isReserved = name in RESERVED_SPEC_KEYS;
|
||||
invariant(
|
||||
!isReserved,
|
||||
'ReactCompositeComponent: You are attempting to define a reserved ' +
|
||||
'property, `%s`, that shouldn\'t be on the "statics" key. Define it ' +
|
||||
'as an instance property instead; it will still be accessible on the ' +
|
||||
'constructor.',
|
||||
name
|
||||
);
|
||||
|
||||
var isInherited = name in Constructor;
|
||||
invariant(
|
||||
!isInherited,
|
||||
|
||||
@@ -1272,6 +1272,29 @@ describe('ReactCompositeComponent', function() {
|
||||
expect(Component.pqr()).toBe(Component.type);
|
||||
});
|
||||
|
||||
it('should throw if a reserved property is in statics', function() {
|
||||
expect(function() {
|
||||
React.createClass({
|
||||
statics: {
|
||||
getDefaultProps: function() {
|
||||
return {
|
||||
foo: 0
|
||||
};
|
||||
}
|
||||
},
|
||||
|
||||
render: function() {
|
||||
return <span />;
|
||||
}
|
||||
});
|
||||
}).toThrow(
|
||||
'Invariant Violation: ReactCompositeComponent: You are attempting to ' +
|
||||
'define a reserved property, `getDefaultProps`, that shouldn\'t be on ' +
|
||||
'the "statics" key. Define it as an instance property instead; it ' +
|
||||
'will still be accessible on the constructor.'
|
||||
);
|
||||
});
|
||||
|
||||
it('should support statics in mixins', function() {
|
||||
var Mixin = {
|
||||
statics: {
|
||||
|
||||
Reference in New Issue
Block a user