mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-11 19:37:49 +00:00
Ensure shortcut fusion works for _.at with no indexes specified.
This commit is contained in:
@@ -13895,8 +13895,11 @@
|
|||||||
|
|
||||||
LazyWrapper.prototype.at = rest(function(paths) {
|
LazyWrapper.prototype.at = rest(function(paths) {
|
||||||
paths = baseFlatten(paths);
|
paths = baseFlatten(paths);
|
||||||
return (paths.length == 1 && isIndex(paths[0]))
|
var length = paths.length,
|
||||||
? this.slice(paths[0], +paths[0] + 1)
|
start = length ? paths[0] : 0;
|
||||||
|
|
||||||
|
return (length < 2 && isIndex(start))
|
||||||
|
? this.slice(start, length ? (+start + 1) : start)
|
||||||
: new LazyWrapper(this);
|
: new LazyWrapper(this);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
12
test/test.js
12
test/test.js
@@ -1269,7 +1269,7 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test('should support shortcut fusion', function(assert) {
|
QUnit.test('should support shortcut fusion', function(assert) {
|
||||||
assert.expect(4);
|
assert.expect(6);
|
||||||
|
|
||||||
if (!isNpm) {
|
if (!isNpm) {
|
||||||
var array = lodashStable.range(LARGE_ARRAY_SIZE),
|
var array = lodashStable.range(LARGE_ARRAY_SIZE),
|
||||||
@@ -1277,16 +1277,16 @@
|
|||||||
iteratee = function(value) { count++; return square(value); },
|
iteratee = function(value) { count++; return square(value); },
|
||||||
lastIndex = LARGE_ARRAY_SIZE - 1;
|
lastIndex = LARGE_ARRAY_SIZE - 1;
|
||||||
|
|
||||||
_.each([lastIndex, lastIndex + ''], function(index) {
|
_.each([lastIndex, lastIndex + '', []], function(n, index) {
|
||||||
count = 0;
|
count = 0;
|
||||||
var actual = _(array).map(iteratee).at(index).value();
|
var actual = _(array).map(iteratee).at(n).value();
|
||||||
|
|
||||||
assert.strictEqual(count, 1);
|
assert.strictEqual(count, index == 2 ? 0 : 1);
|
||||||
assert.deepEqual(actual, [square(lastIndex)]);
|
assert.deepEqual(actual, index == 2 ? [] : [square(lastIndex)]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
skipTest(assert, 4);
|
skipTest(assert, 6);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user