Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Commit

Permalink
Add test cases from 2358, 2398 that pass from previous PRs (#2410)
Browse files Browse the repository at this point in the history
Summary:
Release Notes: None

Previous PRs fixed these issues, but didn't necessarily add the test case from the issue. This PR adds the exact test cases from the issues.

Closes #2358
Closes #2398
Pull Request resolved: #2410

Differential Revision: D9259118

Pulled By: cblappert

fbshipit-source-id: 3eb347044865a11e2ce5262b2338b7b6e1958c60
  • Loading branch information
cblappert authored and facebook-github-bot committed Aug 10, 2018
1 parent 3503c79 commit 22a55f7
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 0 deletions.
30 changes: 30 additions & 0 deletions test/serializer/optimized-functions/Issue2358-2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
function fn(x, y, obj, cond) {
var arr = x;
var arr2 = y;

var a = obj.a;

var mapper1 = function(item) {
if (cond) {
return a;
}
};
global.__optimize && __optimize(mapper1);
var res = arr.map(mapper1);

var mapper2 = function(item) {
if (cond) {
return a;
}
};
global.__optimize && __optimize(mapper2);
var res2 = arr2.map(mapper2);

return [res, res2];
}

global.__optimize && __optimize(fn);

global.inspect = function() {
return JSON.stringify(fn([1, 2], [3, 4], { a: 5 }, true));
};
26 changes: 26 additions & 0 deletions test/serializer/optimized-functions/Issue2358.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
function fn(x, y, obj, cond) {
var arr = Array.from(x);
var arr2 = Array.from(y);

var a = obj.a;

var res = arr.map(function(item) {
if (cond) {
return a;
}
});

var res2 = arr2.map(function(item) {
if (cond) {
return a;
}
});

return [res, res2];
}

global.__optimize && __optimize(fn);

global.inspect = function() {
return JSON.stringify(fn([1, 2], [3, 4], { a: 5 }, true));
};
42 changes: 42 additions & 0 deletions test/serializer/optimized-functions/Issue2398.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
function fn(props, cond) {
var arr = Array.from(props.x);
var newObj;

if (cond) {
var _ref8;
var value =
(_ref8 = props.feedback) != null
? (_ref8 = _ref8.display_comments) != null
? _ref8.ordering_mode
: _ref8
: _ref8;

var fn2 = function() {
return value;
};

var res = arr.map(function(item) {
return item[value];
});
}

return [res, fn2];
}

global.__optimize && __optimize(fn);

global.inspect = function() {
let [res, fn2] = fn(
{
x: [1, 2],
feedback: {
display_comments: {
ordering_mode: "foo",
},
},
},
true
);
res.push(fn2());
return JSON.stringify(res);
};

0 comments on commit 22a55f7

Please sign in to comment.