dillon1000/react
Commit
Browse files Reassign variable of rendered component
The component that gets passed into renderComponent isn't guaranteed to be the instance that gets mounted. We want to clone the instance. Unit tests need to reason about the mounted instance. The first code mod changes: ReactTestUtils.renderIntoDocument(<identifier>) into <identifier> = ReactTestUtils.renderIntoDocument(<identifier>) Using this scripts: scripts/bin/codemod -m -d ~/www --extensions js \ '^(\s*)ReactTestUtils\.renderIntoDocument\(\s*([$a-zA-Z0-9_]+)\s*\)' \ '\1\2 = ReactTestUtils.renderIntoDocument(\2)' In the second case I do the same for React.renderComponent. However, there are alot more unnecessary matches so I only codemod if the same identifier occurs later in the file. scripts/bin/codemod -m -d ~/www --extensions js \ '^(\s*)React.renderComponent\(\s*([$a-zA-Z0-9_]+)\s*?,(.*?\n?.*?\s\2\b)' \ '\1\2 = React.renderComponent(\2,\3' And one more for ReactMount.renderComponent used by internals. scripts/bin/codemod -m -d ~/www --extensions js \ '^(\s*)ReactMount.renderComponent\(\s*([$a-zA-Z0-9_]+)\s*?,(.*?\n?.*?\s\2\b)' \ '\1\2 = ReactMount.renderComponent(\2,\3' This still matches many unnecessary cases where the second occurance of the identifier is a redeclaration or comment. But this code mod doesn't hurt in those cases. Finally I have to do the same for: this.<identifier> = React.renderComponent(this.<identifier>, This is a common pattern for production code but not tests. Some of these call sites will likely break when we move to true descriptors. scripts/bin/codemod -m -d ~/www --extensions js \ '^(\s*)React.renderComponent\((\s*)this\.([$a-zA-Z0-9\_\.]+)\s*?,' \ '\1this.\3 = React.renderComponent(\2this.\3,'
Changed paths15 files
First-parent comparisonsrc/browser/ui/__tests__/ReactDOMComponent-test.js ModifiedM src/browser/ui/__tests__/ReactEventTopLevelCallback-test.js ModifiedM src/browser/ui/dom/__tests__/CSSPropertyOperations-test.js ModifiedM src/browser/ui/dom/components/__tests__/ReactDOMButton-test.js ModifiedM src/core/__tests__/ReactComponent-test.js ModifiedM src/core/__tests__/ReactCompositeComponentDOMMinimalism-test.js ModifiedM src/core/__tests__/ReactCompositeComponentError-test.js ModifiedM src/core/__tests__/ReactCompositeComponentMixin-test.js ModifiedM src/core/__tests__/ReactCompositeComponentState-test.js ModifiedM src/core/__tests__/ReactIdentity-test.js ModifiedM src/core/__tests__/ReactPropTransferer-test.js ModifiedM src/core/__tests__/ReactPropTypes-test.js ModifiedM src/core/__tests__/ReactStateSetters-test.js ModifiedM src/core/__tests__/ReactUpdates-test.js ModifiedM src/utils/__tests__/sliceChildren-test.js ModifiedPatch
Files changed
Rendering syntax-highlighted changes…