-
Notifications
You must be signed in to change notification settings - Fork 27
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
feat: add codemod for is-plain-object
#55
Conversation
c001c07
to
430d87e
Compare
// Test cases | ||
assert.strictEqual((typeof Object.create({}) === "object" && (Object.create({}).constructor === Object || Object.create({}).constructor === undefined)), true); | ||
assert.strictEqual((typeof Object.create(Object.prototype) === "object" && (Object.create(Object.prototype).constructor === Object || Object.create(Object.prototype).constructor === undefined)), true); | ||
assert.strictEqual((typeof { foo: 'bar' } === "object" && ({ foo: 'bar' }.constructor === Object || { foo: 'bar' }.constructor === undefined)), true); |
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.
Cashing should be applied, for example, for object literals too. They could have some logic like computed properties.
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.
Ahh, I get what you mean. We should add some sort of caching into the codemod itself, right?
866805d
to
27692b9
Compare
Updated this to:
Also, it seems that there is a bit of different behavior from the const { isPlainObject } = require('is-plain-object')
const arg = Object.create({});
console.log(isPlainObject(arg));
//=> true
console.log(arg && typeof arg === "object" && (Object.getPrototypeOf(arg) === null || Object.getPrototypeOf(arg) === Object.prototype))
//=> false It appears to me that the suggested replacement from the module-replacements repo creates the "correct" output, so maybe down the road as this package matures we will need to be clear that this codemod (and possibly some others) could change the behavior of the code they are replacing. |
27692b9
to
77314b7
Compare
This LGTM, @zloirock 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.
👍
Nice work and great collaboration guys! |
Codemod for
is-plain-object
using a slightly modified replacement from the module-replacements repo. I left an issue over there to address an edge case I encountered while creating this codemod. I am 99% confident in my variation, which matches the package's original behavior.