Skip to content

Commit ada3fb8

Browse files
author
Keyan Zhang
committed
fixed incorrect behavior when mixins is a non-array value
1 parent 3936f55 commit ada3fb8

File tree

4 files changed

+38
-11
lines changed

4 files changed

+38
-11
lines changed

transforms/__testfixtures__/class-test2.input.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,24 @@ var ComponentWithInconvertibleMixins = React.createClass({
6666
},
6767
});
6868

69+
var listOfInconvertibleMixins = [ReactComponentWithPureRenderMixin, FooBarMixin];
70+
71+
var ComponentWithInconvertibleMixins2 = React.createClass({
72+
mixins: listOfInconvertibleMixins,
73+
74+
getInitialState: function() {
75+
return {
76+
counter: this.props.initialNumber + 1,
77+
};
78+
},
79+
80+
render: function() {
81+
return (
82+
<div>{this.state.counter}</div>
83+
);
84+
},
85+
});
86+
6987
// taken from https://facebook.github.io/react/docs/context.html#updating-context
7088
var MediaQuery = React.createClass({
7189
childContextTypes: {

transforms/__testfixtures__/class-test2.output.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,24 @@ var ComponentWithInconvertibleMixins = React.createClass({
6464
},
6565
});
6666

67+
var listOfInconvertibleMixins = [ReactComponentWithPureRenderMixin, FooBarMixin];
68+
69+
var ComponentWithInconvertibleMixins2 = React.createClass({
70+
mixins: listOfInconvertibleMixins,
71+
72+
getInitialState: function() {
73+
return {
74+
counter: this.props.initialNumber + 1,
75+
};
76+
},
77+
78+
render: function() {
79+
return (
80+
<div>{this.state.counter}</div>
81+
);
82+
},
83+
});
84+
6785
// taken from https://facebook.github.io/react/docs/context.html#updating-context
6886
class MediaQuery extends React.Component {
6987
static childContextTypes = {

transforms/class.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ module.exports = (file, api, options) => {
558558
// no mixins found on the classPath -> true
559559
// pure mixin identifier not found -> (has mixins) -> false
560560
// found pure mixin identifier ->
561-
// class mixins only contain the identifier -> true
561+
// class mixins is an array and only contains the identifier -> true
562562
// otherwise -> false
563563
const mixinsFilter = (classPath) => {
564564
if (!ReactUtils.hasMixins(classPath)) {

transforms/utils/ReactUtils.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -142,16 +142,7 @@ module.exports = function(j) {
142142

143143
// ---------------------------------------------------------------------------
144144
// Checks if the React class has mixins
145-
const isMixinProperty = property => {
146-
const key = property.key;
147-
const value = property.value;
148-
return (
149-
key.name === 'mixins' &&
150-
value.type === 'ArrayExpression' &&
151-
Array.isArray(value.elements) &&
152-
value.elements.length
153-
);
154-
};
145+
const isMixinProperty = property => property.key.name === 'mixins';
155146

156147
const hasMixins = classPath => {
157148
const spec = getReactCreateClassSpec(classPath);

0 commit comments

Comments
 (0)