Babel: JSX allows elements as attribute values, but the transform throws

Created on 24 Jul 2017  路  3Comments  路  Source: babel/babel

Input:

<div attr=<div /> />

should become

React.createElement(
  "div",
  { attr: React.createElement("div", null) }
);

but Babel currently throws

Property value of JSXAttribute expected node to be of a type ["JSXElement","StringLiteral","JSXExpressionContainer"] but instead got "CallExpression"

I assume because we're going through the intermediate

<div attr=React.createElement("div", null) />

which is indeed invalid. Probably the easiest fix would be to wrap it, e.g.

<div attr={React.createElement("div", null)} />
react claimed good first issue outdated

All 3 comments

This means:

I'm interested in taking a crack at this if no one else has started on it yet!

@kedromelon all yours!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hzoo picture hzoo  路  3Comments

nicolo-ribaudo picture nicolo-ribaudo  路  3Comments

hzoo picture hzoo  路  3Comments

catamphetamine picture catamphetamine  路  3Comments

tleunen picture tleunen  路  3Comments