mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Throw an error when functions on statics clash due to duplicate keys
This commit is contained in:
@@ -556,22 +556,14 @@ function mixStaticSpecIntoComponent(Constructor, statics) {
|
||||
}
|
||||
|
||||
var isInherited = name in Constructor;
|
||||
var result = property;
|
||||
if (isInherited) {
|
||||
var existingProperty = Constructor[name];
|
||||
var existingType = typeof existingProperty;
|
||||
var propertyType = typeof property;
|
||||
invariant(
|
||||
existingType === 'function' && propertyType === 'function',
|
||||
'ReactCompositeComponent: You are attempting to define ' +
|
||||
'`%s` on your component more than once, but that is only supported ' +
|
||||
'for functions, which are chained together. This conflict may be ' +
|
||||
'due to a mixin.',
|
||||
name
|
||||
);
|
||||
result = createChainedFunction(existingProperty, property);
|
||||
}
|
||||
Constructor[name] = result;
|
||||
invariant(
|
||||
!isInherited,
|
||||
'ReactCompositeComponent: You are attempting to define ' +
|
||||
'`%s` on your component more than once. This conflict may be ' +
|
||||
'due to a mixin.',
|
||||
name
|
||||
);
|
||||
Constructor[name] = property;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1317,9 +1317,33 @@ describe('ReactCompositeComponent', function() {
|
||||
});
|
||||
}).toThrow(
|
||||
'Invariant Violation: ReactCompositeComponent: You are attempting to ' +
|
||||
'define `abc` on your component more than once, but that is only ' +
|
||||
'supported for functions, which are chained together. This conflict ' +
|
||||
'may be due to a mixin.'
|
||||
'define `abc` on your component more than once. This conflict may be ' +
|
||||
'due to a mixin.'
|
||||
);
|
||||
});
|
||||
|
||||
it("should throw if mixins override functions in statics", function() {
|
||||
expect(function() {
|
||||
var Mixin = {
|
||||
statics: {
|
||||
abc: function() { console.log('foo'); }
|
||||
}
|
||||
};
|
||||
React.createClass({
|
||||
mixins: [Mixin],
|
||||
|
||||
statics: {
|
||||
abc: function() { console.log('bar'); }
|
||||
},
|
||||
|
||||
render: function() {
|
||||
return <span />;
|
||||
}
|
||||
});
|
||||
}).toThrow(
|
||||
'Invariant Violation: ReactCompositeComponent: You are attempting to ' +
|
||||
'define `abc` on your component more than once. This conflict may be ' +
|
||||
'due to a mixin.'
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user