Adds regression tests for issue 2056 (#2124)

Summary:
Release notes: none

It turns out that the tests in https://github.com/facebook/prepack/issues/2056 now pass on master, so this adds regression tests for them. Fixes #2056.
Closes https://github.com/facebook/prepack/pull/2124

Differential Revision: D8432504

Pulled By: trueadm

fbshipit-source-id: fce78b4ecfc9cee55cf70868557a3eacac635867
This commit is contained in:
Dominic Gannaway 2018-06-14 15:44:20 -07:00 committed by Facebook Github Bot
parent 9732112204
commit 491ec2ad26
4 changed files with 126 additions and 0 deletions

View File

@ -2139,6 +2139,23 @@ ReactStatistics {
}
`;
exports[`Test React with JSX input, JSX output Functional component folding Handle mapped arrays from Array.from 1`] = `
ReactStatistics {
"componentsEvaluated": 1,
"evaluatedRootNodes": Array [
Object {
"children": Array [],
"message": "",
"name": "App",
"status": "ROOT",
},
],
"inlinedComponents": 0,
"optimizedNestedClosures": 1,
"optimizedTrees": 1,
}
`;
exports[`Test React with JSX input, JSX output Functional component folding Havocing of ReactElements should not result in property assignments 1`] = `
ReactStatistics {
"componentsEvaluated": 1,
@ -7072,6 +7089,23 @@ ReactStatistics {
}
`;
exports[`Test React with JSX input, create-element output Functional component folding Handle mapped arrays from Array.from 1`] = `
ReactStatistics {
"componentsEvaluated": 1,
"evaluatedRootNodes": Array [
Object {
"children": Array [],
"message": "",
"name": "App",
"status": "ROOT",
},
],
"inlinedComponents": 0,
"optimizedNestedClosures": 1,
"optimizedTrees": 1,
}
`;
exports[`Test React with JSX input, create-element output Functional component folding Havocing of ReactElements should not result in property assignments 1`] = `
ReactStatistics {
"componentsEvaluated": 1,
@ -12005,6 +12039,23 @@ ReactStatistics {
}
`;
exports[`Test React with create-element input, JSX output Functional component folding Handle mapped arrays from Array.from 1`] = `
ReactStatistics {
"componentsEvaluated": 1,
"evaluatedRootNodes": Array [
Object {
"children": Array [],
"message": "",
"name": "App",
"status": "ROOT",
},
],
"inlinedComponents": 0,
"optimizedNestedClosures": 1,
"optimizedTrees": 1,
}
`;
exports[`Test React with create-element input, JSX output Functional component folding Havocing of ReactElements should not result in property assignments 1`] = `
ReactStatistics {
"componentsEvaluated": 1,
@ -16953,6 +17004,23 @@ ReactStatistics {
}
`;
exports[`Test React with create-element input, create-element output Functional component folding Handle mapped arrays from Array.from 1`] = `
ReactStatistics {
"componentsEvaluated": 1,
"evaluatedRootNodes": Array [
Object {
"children": Array [],
"message": "",
"name": "App",
"status": "ROOT",
},
],
"inlinedComponents": 0,
"optimizedNestedClosures": 1,
"optimizedTrees": 1,
}
`;
exports[`Test React with create-element input, create-element output Functional component folding Havocing of ReactElements should not result in property assignments 1`] = `
ReactStatistics {
"componentsEvaluated": 1,

View File

@ -421,6 +421,10 @@ function runTestSuite(outputJsx, shouldTranspileSource) {
await runTest(directory, "array-map2.js");
});
it("Handle mapped arrays from Array.from", async () => {
await runTest(directory, "array-from.js");
});
it("Simple fragments", async () => {
await runTest(directory, "simple-fragments.js");
});

View File

@ -0,0 +1,35 @@
var React = require('react');
// the JSX transform converts to React, so we need to add it back in
this['React'] = React;
function App(props) {
var _ref8;
var value = (_ref8 = props.feedback) != null
? (_ref8 = _ref8.display_comments) != null
? _ref8.ordering_mode
: _ref8
: _ref8;
var items = props.items;
var collection = Array.from(items).map(function() {
return <span>{value}</span>
});
return <div>{collection}</div>
}
App.getTrials = function(renderer, Root) {
let items = [
{ title: "Hello world 1", id: 0 },
{ title: "Hello world 2", id: 1 },
{ title: "Hello world 3", id: 2 },
];
renderer.update(<Root items={items} feedback={{display_comments: { ordering_mode: 10 }}} />);
return [['simple render array map', renderer.toJSON()]];
};
if (this.__optimizeReactComponentTree) {
__optimizeReactComponentTree(App);
}
module.exports = App;

View File

@ -0,0 +1,19 @@
function fn(arg) {
var value = arg.x !== null ? arg.x : 0;
function fn2() {
return value;
}
global.__optimize && __optimize(fn2);
return Array.from(arg.arr).map(fn2);
}
global.__optimize && __optimize(fn);
global.inspect = function() {
return JSON.stringify([
fn({arr: [1, 2, 3], x: 1}),
fn({arr: [1, 2, 3], x: null}),
])
};