dry up array comprehension for single block
This commit is contained in:
12
test/fixtures/array-comprehension/if/expected.js
vendored
12
test/fixtures/array-comprehension/if/expected.js
vendored
@@ -1,12 +0,0 @@
|
||||
var seattlers = function () {
|
||||
var _arr = [];
|
||||
customers.forEach(function (c) {
|
||||
if (c.city == "Seattle") {
|
||||
_arr.push({
|
||||
name: c.name,
|
||||
age: c.age
|
||||
});
|
||||
}
|
||||
});
|
||||
return _arr;
|
||||
}();
|
||||
1
test/fixtures/array-comprehension/multiple-if/actual.js
vendored
Normal file
1
test/fixtures/array-comprehension/multiple-if/actual.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
var seattlers = [for (customers of countries) for (c of customers) if (c.city == "Seattle") { name: c.name, age: c.age }];
|
||||
14
test/fixtures/array-comprehension/multiple-if/expected.js
vendored
Normal file
14
test/fixtures/array-comprehension/multiple-if/expected.js
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
var seattlers = function () {
|
||||
var _arr = [];
|
||||
countries.forEach(function (customers) {
|
||||
customers.forEach(function (c) {
|
||||
if (c.city == "Seattle") {
|
||||
_arr.push({
|
||||
name: c.name,
|
||||
age: c.age
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
return _arr;
|
||||
}();
|
||||
8
test/fixtures/array-comprehension/single-if/expected.js
vendored
Normal file
8
test/fixtures/array-comprehension/single-if/expected.js
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
var seattlers = customers.filter(function (c) {
|
||||
return c.city == "Seattle";
|
||||
}).map(function (c) {
|
||||
return {
|
||||
name: c.name,
|
||||
age: c.age
|
||||
};
|
||||
});
|
||||
@@ -1,9 +1,3 @@
|
||||
var arr = (function () {
|
||||
var _arr = [];
|
||||
|
||||
[1, 2, 3].forEach(function (i) {
|
||||
_arr.push(i * i);
|
||||
});
|
||||
|
||||
return _arr;
|
||||
})();
|
||||
var arr = [1, 2, 3].map(function (i) {
|
||||
return i * i;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user