-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
path: refactor path.format() repeated code #5673
Conversation
} | ||
return dir + posix.sep + base; | ||
}, | ||
format: (obj) => { return format('/', obj); }, |
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.
I think the function name will be lost in stack traces with the arrow function?
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.
Ah, then...will go back to the declaration style used in the rest of the object...
...and done!
return dir + base; | ||
} | ||
return dir + win32.sep + base; | ||
format: function(pathObject) { |
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.
nit: missing function name here also
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.
Whoops. Fixed.
Minor fixup pushed. New CI: https://ci.nodejs.org/job/node-test-pull-request/1908/ |
LGTM, nice. |
nit: wouldn't it make more sense to use |
@@ -140,6 +140,24 @@ function normalizeStringPosix(path, allowAboveRoot) { | |||
return res; | |||
} | |||
|
|||
function _format(sep, pathObject) { | |||
if (pathObject === null || typeof pathObject !== 'object') { | |||
throw new TypeError( |
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.
Maybe keep the throws directly in path.format
for better stack traces?
That would also avoid polymorphism in _format
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.
+1 ... moving the throw up would be best.
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.
Oh, good points about the stack trace and polymorphism as well. Rebased against master, changed according to these comments, and force pushed.
LGTM with a couple nits |
8627d44
to
bc36ea2
Compare
I had the same thought but went with the string literals because |
LGTM |
PR-URL: nodejs#5673 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: James Snell <jasnell@gmail.com> Reviewed-By: Brian White <mscdex@mscdex.net>
Landed in 9de9a08 |
PR-URL: #5673 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: James Snell <jasnell@gmail.com> Reviewed-By: Brian White <mscdex@mscdex.net> Conflicts: lib/path.js
This is blocked by other path changes /cc @nodejs/lts |
make -j8 test
(UNIX) orvcbuild test nosign
(Windows) pass withthis change (including linting)?
test (or a benchmark) included?
existing APIs, or introduces new ones)?
Affected core subsystem(s)
path
Description of change
Refactor repeated code into a separate function.