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
Remove 'includes' API, fix CI build failure #2574
Conversation
lib/utils.js
Outdated
@@ -26,7 +26,8 @@ function isArray(val) { | |||
* @returns {boolean} True if value is a Buffer, otherwise false | |||
*/ | |||
function isBuffer(val) { | |||
return ![undefined, null].includes(val) && val.constructor === Buffer; | |||
if (val === null || val === void 0 || val.constructor === null || val.constructor === void 0 ) return false; |
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.
what's the difference between using void 0
and undefined?
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.
undefined
is not a reserved word in javascript, so it can be rewritten. void 0
is stricter.
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.
we rely on type of x === 'undefined'
throughout the file, might be better to be consistent, also are there cases where the constructor can be null? could it be sufficient to just check !isUndefined(val.constructor)
, also we can just use our own helper? isUndefined
, what do you think?
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 agree to use isUndefined
, and I suggest to replace all the other undefined
judgement with our own helper function isUndefined
, if you agree, then I will submit a PR.
if constructor
has been overwriten with null
(extreme paticular case), then typeof val.constructor.isBuffer === 'function'
will report an error.
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.
@chinesedfan because we have to obey the 3 rules of eslint:
|
Changes:
Error message: "Object doesn't support property or method 'includes' to equal."
Reason: 'includes' belongs to the API of
ES7
,ie11
does not support it.https://github.com/axios/axios/blob/master/lib/utils.js#L29
Related PR Remove dependency on is-buffer #1816