diff --git a/src/react/utils.js b/src/react/utils.js index f10613f18..0828b9c56 100644 --- a/src/react/utils.js +++ b/src/react/utils.js @@ -197,7 +197,7 @@ export function valueIsLegacyCreateClassComponent(realm: Realm, value: Value): b } export function valueIsFactoryClassComponent(realm: Realm, value: Value): boolean { - if (value instanceof ObjectValue) { + if (value instanceof ObjectValue && !ArrayValue.isIntrinsicAndHasWidenedNumericProperty(value)) { return To.ToBooleanPartial(realm, Get(realm, value, "render")); } return false; diff --git a/test/react/FunctionalComponents-test.js b/test/react/FunctionalComponents-test.js index a2e382f28..8ec3003ff 100644 --- a/test/react/FunctionalComponents-test.js +++ b/test/react/FunctionalComponents-test.js @@ -166,6 +166,10 @@ it("Handle mapped arrays 2", () => { runTest(__dirname + "/FunctionalComponents/array-map2.js"); }); +it("Handle mapped arrays 3", () => { + runTest(__dirname + "/FunctionalComponents/array-map3.js"); +}); + it("Handle mapped arrays from Array.from", () => { runTest(__dirname + "/FunctionalComponents/array-from.js"); }); diff --git a/test/react/FunctionalComponents/array-map3.js b/test/react/FunctionalComponents/array-map3.js new file mode 100644 index 000000000..7b5adca79 --- /dev/null +++ b/test/react/FunctionalComponents/array-map3.js @@ -0,0 +1,23 @@ +var React = require("react"); + +function App(props) { + var items = Array.from(props.items); + + var nested = function(item) { + return item; + }; + + return items.map(nested); +} + +App.getTrials = function(renderer, Root) { + let items = [0, 0]; + renderer.update(); + return [["simple render array map", renderer.toJSON()]]; +}; + +if (this.__optimizeReactComponentTree) { + __optimizeReactComponentTree(App); +} + +module.exports = App; diff --git a/test/react/__snapshots__/FunctionalComponents-test.js.snap b/test/react/__snapshots__/FunctionalComponents-test.js.snap index 1fa7e20b1..f310abe0c 100644 --- a/test/react/__snapshots__/FunctionalComponents-test.js.snap +++ b/test/react/__snapshots__/FunctionalComponents-test.js.snap @@ -2616,6 +2616,74 @@ ReactStatistics { } `; +exports[`Handle mapped arrays 3: (JSX => JSX) 1`] = ` +ReactStatistics { + "componentsEvaluated": 1, + "evaluatedRootNodes": Array [ + Object { + "children": Array [], + "message": "", + "name": "App", + "status": "ROOT", + }, + ], + "inlinedComponents": 0, + "optimizedNestedClosures": 1, + "optimizedTrees": 1, +} +`; + +exports[`Handle mapped arrays 3: (JSX => createElement) 1`] = ` +ReactStatistics { + "componentsEvaluated": 1, + "evaluatedRootNodes": Array [ + Object { + "children": Array [], + "message": "", + "name": "App", + "status": "ROOT", + }, + ], + "inlinedComponents": 0, + "optimizedNestedClosures": 1, + "optimizedTrees": 1, +} +`; + +exports[`Handle mapped arrays 3: (createElement => JSX) 1`] = ` +ReactStatistics { + "componentsEvaluated": 1, + "evaluatedRootNodes": Array [ + Object { + "children": Array [], + "message": "", + "name": "App", + "status": "ROOT", + }, + ], + "inlinedComponents": 0, + "optimizedNestedClosures": 1, + "optimizedTrees": 1, +} +`; + +exports[`Handle mapped arrays 3: (createElement => createElement) 1`] = ` +ReactStatistics { + "componentsEvaluated": 1, + "evaluatedRootNodes": Array [ + Object { + "children": Array [], + "message": "", + "name": "App", + "status": "ROOT", + }, + ], + "inlinedComponents": 0, + "optimizedNestedClosures": 1, + "optimizedTrees": 1, +} +`; + exports[`Handle mapped arrays from Array.from: (JSX => JSX) 1`] = ` ReactStatistics { "componentsEvaluated": 1,