-
-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Map and Set iterator methods. (#72)
- Loading branch information
1 parent
23f5188
commit 5045523
Showing
5 changed files
with
247 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
'use strict'; | ||
|
||
module.exports = value => typeof value === 'object' && typeof value.next === 'function'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
'use strict'; | ||
|
||
const {TARGET} = require('./constants'); | ||
|
||
// eslint-disable-next-line max-params | ||
module.exports = (iterator, target, thisArg, applyPath, prepareValue) => { | ||
const originalNext = iterator.next; | ||
|
||
if (target.name === 'entries') { | ||
iterator.next = function () { | ||
const result = originalNext.call(this); | ||
|
||
if (result.done === false) { | ||
result.value[0] = prepareValue( | ||
result.value[0], | ||
target, | ||
result.value[0], | ||
applyPath | ||
); | ||
result.value[1] = prepareValue( | ||
result.value[1], | ||
target, | ||
result.value[0], | ||
applyPath | ||
); | ||
} | ||
|
||
return result; | ||
}; | ||
} else if (target.name === 'values') { | ||
const keyIterator = thisArg[TARGET].keys(); | ||
|
||
iterator.next = function () { | ||
const result = originalNext.call(this); | ||
|
||
if (result.done === false) { | ||
result.value = prepareValue( | ||
result.value, | ||
target, | ||
keyIterator.next().value, | ||
applyPath | ||
); | ||
} | ||
|
||
return result; | ||
}; | ||
} else { | ||
iterator.next = function () { | ||
const result = originalNext.call(this); | ||
|
||
if (result.done === false) { | ||
result.value = prepareValue( | ||
result.value, | ||
target, | ||
result.value, | ||
applyPath | ||
); | ||
} | ||
|
||
return result; | ||
}; | ||
} | ||
|
||
return iterator; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters