optimisation.react.inlineElements: move children into props and leave children out if the element has none - @spicyj
This commit is contained in:
parent
6bc2bfce7d
commit
1ef41b6f32
@ -36,15 +36,19 @@ export function JSXElement(node, parent, scope, file) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function pushElemProp(key, value) {
|
function pushElemProp(key, value) {
|
||||||
obj.properties.push(t.property("init", t.identifier(key), value));
|
pushProp(obj.properties, t.identifier(key), value);
|
||||||
|
}
|
||||||
|
|
||||||
|
function pushProp(objProps, key, value) {
|
||||||
|
objProps.push(t.property("init", key, value));
|
||||||
}
|
}
|
||||||
|
|
||||||
// metadata
|
// metadata
|
||||||
pushElemProp("type", type);
|
pushElemProp("type", type);
|
||||||
pushElemProp("ref", t.literal(null));
|
pushElemProp("ref", t.literal(null));
|
||||||
|
|
||||||
if (!open.selfClosing) {
|
if (node.children.length) {
|
||||||
pushElemProp("children", t.arrayExpression(react.buildChildren(node)));
|
pushProp(props.properties, t.identifier("children"), t.arrayExpression(react.buildChildren(node)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// props
|
// props
|
||||||
@ -53,7 +57,7 @@ export function JSXElement(node, parent, scope, file) {
|
|||||||
if (isJSXAttributeOfName(attr, "key")) {
|
if (isJSXAttributeOfName(attr, "key")) {
|
||||||
key = attr.value;
|
key = attr.value;
|
||||||
} else {
|
} else {
|
||||||
props.properties.push(t.property("init", attr.name, attr.value));
|
pushProp(props.properties, attr.name, attr.value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -15,8 +15,9 @@ function render() {
|
|||||||
var _ref = {
|
var _ref = {
|
||||||
type: "foo",
|
type: "foo",
|
||||||
ref: null,
|
ref: null,
|
||||||
children: [text],
|
props: {
|
||||||
props: {},
|
children: [text]
|
||||||
|
},
|
||||||
key: null
|
key: null
|
||||||
};
|
};
|
||||||
return function () {
|
return function () {
|
||||||
|
|||||||
@ -3,7 +3,6 @@
|
|||||||
({
|
({
|
||||||
type: Baz,
|
type: Baz,
|
||||||
ref: null,
|
ref: null,
|
||||||
children: [],
|
|
||||||
props: babelHelpers.defaultProps(Baz.defaultProps, {
|
props: babelHelpers.defaultProps(Baz.defaultProps, {
|
||||||
foo: "bar"
|
foo: "bar"
|
||||||
}),
|
}),
|
||||||
|
|||||||
@ -3,7 +3,6 @@
|
|||||||
({
|
({
|
||||||
type: Baz,
|
type: Baz,
|
||||||
ref: null,
|
ref: null,
|
||||||
children: [],
|
|
||||||
props: babelHelpers.defaultProps(Baz.defaultProps, {}),
|
props: babelHelpers.defaultProps(Baz.defaultProps, {}),
|
||||||
key: null
|
key: null
|
||||||
});
|
});
|
||||||
@ -3,7 +3,6 @@
|
|||||||
({
|
({
|
||||||
type: "foo",
|
type: "foo",
|
||||||
ref: null,
|
ref: null,
|
||||||
children: [],
|
|
||||||
props: {
|
props: {
|
||||||
bar: "foo"
|
bar: "foo"
|
||||||
},
|
},
|
||||||
|
|||||||
@ -3,7 +3,6 @@
|
|||||||
({
|
({
|
||||||
type: "foo",
|
type: "foo",
|
||||||
ref: null,
|
ref: null,
|
||||||
children: [],
|
|
||||||
props: {},
|
props: {},
|
||||||
key: null
|
key: null
|
||||||
});
|
});
|
||||||
@ -3,13 +3,13 @@
|
|||||||
({
|
({
|
||||||
type: Foo,
|
type: Foo,
|
||||||
ref: null,
|
ref: null,
|
||||||
|
props: babelHelpers.defaultProps(Foo.defaultProps, {
|
||||||
children: [bar, {
|
children: [bar, {
|
||||||
type: Baz,
|
type: Baz,
|
||||||
ref: null,
|
ref: null,
|
||||||
props: babelHelpers.defaultProps(Baz.defaultProps, {}),
|
props: babelHelpers.defaultProps(Baz.defaultProps, {}),
|
||||||
key: "baz"
|
key: "baz"
|
||||||
}],
|
}],
|
||||||
props: babelHelpers.defaultProps(Foo.defaultProps, {
|
|
||||||
className: "foo"
|
className: "foo"
|
||||||
}),
|
}),
|
||||||
key: null
|
key: null
|
||||||
|
|||||||
@ -3,8 +3,8 @@
|
|||||||
({
|
({
|
||||||
type: "div",
|
type: "div",
|
||||||
ref: null,
|
ref: null,
|
||||||
children: [bar],
|
|
||||||
props: {
|
props: {
|
||||||
|
children: [bar],
|
||||||
className: "foo"
|
className: "foo"
|
||||||
},
|
},
|
||||||
key: null
|
key: null
|
||||||
|
|||||||
@ -3,13 +3,13 @@
|
|||||||
({
|
({
|
||||||
type: "div",
|
type: "div",
|
||||||
ref: null,
|
ref: null,
|
||||||
|
props: {
|
||||||
children: [bar, {
|
children: [bar, {
|
||||||
type: Baz,
|
type: Baz,
|
||||||
ref: null,
|
ref: null,
|
||||||
props: babelHelpers.defaultProps(Baz.defaultProps, {}),
|
props: babelHelpers.defaultProps(Baz.defaultProps, {}),
|
||||||
key: "baz"
|
key: "baz"
|
||||||
}],
|
}],
|
||||||
props: {
|
|
||||||
className: "foo"
|
className: "foo"
|
||||||
},
|
},
|
||||||
key: null
|
key: null
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user