-
Notifications
You must be signed in to change notification settings - Fork 30k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
repl: small refactoring #17919
repl: small refactoring #17919
Conversation
lib/repl.js
Outdated
@@ -1136,15 +1125,14 @@ function complete(line, callback) { | |||
} | |||
} | |||
} catch (e) { | |||
//console.log("completion error walking prototype chain:" + e); | |||
// console.log("completion error walking prototype chain:" + e); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just remove this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
} | ||
// We're given a duplex readable/writable Stream, like a `net.Socket` | ||
// or a custom object with 2 streams, or the `process` object | ||
input = stream.stdin || stream; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It probably doesn't make a difference, but this has the potential to be a behavior change if only one of stream.stdin
or stream.stdout
were passed in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, do you want me to change it to the way it was before? I personally do not feel like this is ever going to matter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM except for @cjihrig's 2 comments.
lib/repl.js
Outdated
return expr + '.' + member; | ||
})); | ||
completionGroups.push( | ||
memberGroups[i].map((member) => expr + '.' + member)); | ||
} | ||
if (filter) { | ||
filter = expr + '.' + filter; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
filter = expr + '.' + filter;
This can be changed to
filter = `${ expr }.${ filter }`;
Since it removes access usage of +
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
lib/repl.js
Outdated
return expr + '.' + member; | ||
})); | ||
completionGroups.push( | ||
memberGroups[i].map((member) => expr + '.' + member)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const foo = memberGroups.reduce(( acc, memberGroup ) => {
acc.push(memberGroup.map((member) => `${ expr }.${ member }`));
return acc;
}, []);
completionGroups.concat(foo);
Don't mind the name foo as could not think of some descent name but this will make the code immutable. Although we are mutating completionGroups array but in next change we can convert it also to immutability
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is not necessary out of my perspective. I personally feel the current code is more expressive than using reduce
.
PR-URL: nodejs#17919 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Weijia Wang <[email protected]> Reviewed-By: Khaidi Chu <[email protected]> Reviewed-By: Jon Moss <[email protected]> Reviewed-By: Lance Ball <[email protected]>
PR-URL: nodejs#17919 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Weijia Wang <[email protected]> Reviewed-By: Khaidi Chu <[email protected]> Reviewed-By: Jon Moss <[email protected]> Reviewed-By: Lance Ball <[email protected]>
this does not land cleanly on v9.x, could you please backport? as an aside @BridgeAR it appears you are listing the commits in the reverse order they landed... which can make things confusing when landing on release branches. In future could you post the commits in chronological order, or alternatively using the range syntax [headbefore]...[headafter] |
Backported in #19244 (about the order: I fixed that a while ago in my script. It is always in chronological order again). |
PR-URL: nodejs#17919 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Weijia Wang <[email protected]> Reviewed-By: Khaidi Chu <[email protected]> Reviewed-By: Jon Moss <[email protected]> Reviewed-By: Lance Ball <[email protected]>
PR-URL: nodejs#17919 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Weijia Wang <[email protected]> Reviewed-By: Khaidi Chu <[email protected]> Reviewed-By: Jon Moss <[email protected]> Reviewed-By: Lance Ball <[email protected]>
Backport-PR-URL: #19244 PR-URL: #17919 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Weijia Wang <[email protected]> Reviewed-By: Khaidi Chu <[email protected]> Reviewed-By: Jon Moss <[email protected]> Reviewed-By: Lance Ball <[email protected]>
Backport-PR-URL: #19244 PR-URL: #17919 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Weijia Wang <[email protected]> Reviewed-By: Khaidi Chu <[email protected]> Reviewed-By: Jon Moss <[email protected]> Reviewed-By: Lance Ball <[email protected]>
Backport requested for 8.x in #19244 |
Just a minor refactoring to make the code more pleasant.
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
repl