From 7a9c1340843f960bf041164359574bc7190f8697 Mon Sep 17 00:00:00 2001 From: Burak Yigit Kaya Date: Thu, 5 Oct 2017 17:00:14 +0100 Subject: [PATCH 1/2] chore(resolver): Minor improvements in resolver code and tests **Summary** This is a follow up to #4484 and #4478 which improves the code around those areas a bit and removes a now-unnecessary `while` loop. **Test plan** Existing tests should pass. --- __tests__/package-request.js | 4 ++-- src/package-reference.js | 8 +------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/__tests__/package-request.js b/__tests__/package-request.js index eff63f86c3..814ceede92 100644 --- a/__tests__/package-request.js +++ b/__tests__/package-request.js @@ -19,8 +19,8 @@ async function prepareRequest(pattern: string, version: string, resolved: string }; if (parentRequest) { depRequestPattern.parentRequest = parentRequest; - depRequestPattern.parentNames = parentRequest.parentNames.slice(0); - depRequestPattern.parentNames.push(parentRequest.pattern); + depRequestPattern.parentNames = [...parentRequest.parentNames, parentRequest.pattern]; + const lock = parentRequest.getLocked(); privateDepCache[parentRequest.pattern] = {version: lock.version, resolved: lock._remote.resolved}; } diff --git a/src/package-reference.js b/src/package-reference.js index bf37a93899..3b860d3361 100644 --- a/src/package-reference.js +++ b/src/package-reference.js @@ -66,13 +66,7 @@ export default class PackageReference { addRequest(request: PackageRequest) { this.requests.push(request); - let requestLevel = -1; - let currentRequest = request; - while (currentRequest && requestLevel < this.level) { - requestLevel += 1; - currentRequest = currentRequest.parentRequest; - } - this.level = requestLevel; + this.level = request.parentNames.length; } prune() { From 90b72ed9f6bd0e38347bd7bcf3dc419269b310e4 Mon Sep 17 00:00:00 2001 From: Burak Yigit Kaya Date: Thu, 5 Oct 2017 17:19:33 +0100 Subject: [PATCH 2/2] Fix logic --- src/package-reference.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/package-reference.js b/src/package-reference.js index 3b860d3361..06995d978c 100644 --- a/src/package-reference.js +++ b/src/package-reference.js @@ -66,7 +66,7 @@ export default class PackageReference { addRequest(request: PackageRequest) { this.requests.push(request); - this.level = request.parentNames.length; + this.level = Math.min(this.level, request.parentNames.length); } prune() {