@samitouri / QOS-React-2 / commits / a70db003db

Throw if a reserved property is defined in 'statics'

Charles Marsh committed Aug 13, 2014 at 21:34 UTC a70db003dbdba83f04e2480e4a97cc9fbc7d147c
2 files changed +33
src/core/ReactCompositeComponent.js
+10
@@ -555,6 +555,16 @@ function mixStaticSpecIntoComponent(Constructor, statics) {
555 continue;
556 }
557
558 + var isReserved = name in RESERVED_SPEC_KEYS;
559 + invariant(
560 + !isReserved,
561 + 'ReactCompositeComponent: You are attempting to define a reserved ' +
562 + 'property, `%s`, that shouldn\'t be on the "statics" key. Define it ' +
563 + 'as an instance property instead; it will still be accessible on the ' +
564 + 'constructor.',
565 + name
566 + );
567 +
568 var isInherited = name in Constructor;
569 invariant(
570 !isInherited,
src/core/__tests__/ReactCompositeComponent-test.js
+23
@@ -1272,6 +1272,29 @@ describe('ReactCompositeComponent', function() {
1272 expect(Component.pqr()).toBe(Component.type);
1273 });
1274
1275 + it('should throw if a reserved property is in statics', function() {
1276 + expect(function() {
1277 + React.createClass({
1278 + statics: {
1279 + getDefaultProps: function() {
1280 + return {
1281 + foo: 0
1282 + };
1283 + }
1284 + },
1285 +
1286 + render: function() {
1287 + return <span />;
1288 + }
1289 + });
1290 + }).toThrow(
1291 + 'Invariant Violation: ReactCompositeComponent: You are attempting to ' +
1292 + 'define a reserved property, `getDefaultProps`, that shouldn\'t be on ' +
1293 + 'the "statics" key. Define it as an instance property instead; it ' +
1294 + 'will still be accessible on the constructor.'
1295 + );
1296 + });
1297 +
1298 it('should support statics in mixins', function() {
1299 var Mixin = {
1300 statics: {