Skip to content

Conversation

alangpierce
Copy link
Contributor

JSX uses capitalization to determine what type of React.createElement call to
produce: if the name starts with a lower-case letter, React.createElement is
called with the name as a string. Otherwise, it is called with the name as an
identifier. This means that an expression like React.createElement(componentClass)
cannot be converted to JSX, since <componentClass /> would transform to the
string form. This commit changes the script to detect and skip these cases so
that the script does not introduce correctness issues.

JSX uses capitalization to determine what type of `React.createElement` call to produce: if the name starts with a lower-case letter, `React.createElement` is called with the name as a string. Otherwise, it is called with the name as an identifier. This means that an expression like `React.createElement(componentClass)` cannot be converted to JSX, since `<componentClass />` would transform to the string form. This commit changes the script to detect and skip these cases so that the script does not introduce correctness issues.
@cpojer cpojer merged commit 83efb64 into reactjs:master Sep 24, 2016
@cpojer
Copy link
Member

cpojer commented Sep 24, 2016

thank you!

@alangpierce alangpierce deleted the ignore-invalid-jsx-capitalization branch September 25, 2016 02:54
alangpierce added a commit to alangpierce/react-codemod that referenced this pull request Sep 25, 2016
In reactjs#79, I made it so the transformation is skipped in some cases, in particular when the capitalization is invalid. This broke an assumption elsewhere in the code that `convertNodeToJSX` always returns a `JSXElement`, so there was a crash if a skipped element was used as a child. To fix, we can just wrap in a `JSXExpressionContainer` for that case.
cpojer pushed a commit that referenced this pull request Sep 26, 2016
In #79, I made it so the transformation is skipped in some cases, in particular when the capitalization is invalid. This broke an assumption elsewhere in the code that `convertNodeToJSX` always returns a `JSXElement`, so there was a crash if a skipped element was used as a child. To fix, we can just wrap in a `JSXExpressionContainer` for that case.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants