JSXSpreadChildren, throw in transform-react-jsx (#4988)

This commit is contained in:
Justin Ridgewell 2016-12-16 15:30:00 -05:00 committed by Henry Zhu
parent 670ee996c8
commit 2bbc36d25e
7 changed files with 28 additions and 1 deletions

View File

@ -35,6 +35,13 @@ export function JSXExpressionContainer(node: Object) {
this.token("}");
}
export function JSXSpreadChild(node: Object) {
this.token("{");
this.token("...");
this.print(node.expression, node);
this.token("}");
}
export function JSXText(node: Object) {
this.token(node.value);
}

View File

@ -0,0 +1 @@
<div>{...this.props.children}</div>;

View File

@ -0,0 +1 @@
<div>{...this.props.children}</div>;

View File

@ -17,6 +17,10 @@ export default function (opts) {
throw path.buildCodeFrameError("Namespace tags are not supported. ReactJSX is not XML.");
};
visitor.JSXSpreadChild = function(path) {
throw path.buildCodeFrameError("Spread children are not supported.");
};
visitor.JSXElement = {
exit(path, file) {
let callExpr = buildElementCall(path.get("openingElement"), file);

View File

@ -0,0 +1 @@
<div>{...children}</div>;

View File

@ -0,0 +1,3 @@
{
"throws": "Spread children are not supported."
}

View File

@ -39,7 +39,7 @@ defineType("JSXElement", {
children: {
validate: chain(
assertValueType("array"),
assertEach(assertNodeType("JSXText", "JSXExpressionContainer", "JSXElement"))
assertEach(assertNodeType("JSXText", "JSXExpressionContainer", "JSXSpreadChild", "JSXElement"))
)
}
}
@ -59,6 +59,16 @@ defineType("JSXExpressionContainer", {
}
});
defineType("JSXSpreadChild", {
visitor: ["expression"],
aliases: ["JSX", "Immutable"],
fields: {
expression: {
validate: assertNodeType("Expression")
}
}
});
defineType("JSXIdentifier", {
builder: ["name"],
aliases: ["JSX", "Expression"],