-
-
Notifications
You must be signed in to change notification settings - Fork 252
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
fix(vanilla): respect property enumetrability #800
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit df29f66:
|
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.
Please also check CI errors.
src/vanilla.ts
Outdated
const { enumerable = true } = | ||
Reflect.getOwnPropertyDescriptor(target, key) ?? {} |
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 we are sure that it's not undefined.
const { enumerable = true } = | |
Reflect.getOwnPropertyDescriptor(target, key) ?? {} | |
const desc = Object.getOwnPropertyDescriptor( | |
target, | |
key | |
) as PropertyDescriptor |
Do we want to make it true
if it's 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.
-
As for getting property descriptor.
We do not expectundefined
and all we need is to make TypeScript happy.
For thisas PropertyDescriptor
is indeed clearer than?? {}
-
As for using the descriptor just got instead of creating a new one from scratch.
No, this messesvalue
,get
,set
and fails some tests. -
As for
enumerable
default value.
It looks likegetOwnPropertyDescriptor
always returnsenumerable
set.
I don't know if this is guaranteed by the spec.
At the same timedefineProperty
has its own defaults.
I think we can assume that passing whatever is returned bygetOwnPropertyDescriptor
todefineProperty
will do.
So, we don't actually need to provide any default.
Again, we only need to make TypeScript happy.
I'm not familiar with TypeScript enough to propose a type-only solution.
Maybe, using the same default asdefineProperty
is OK:
const { enumerable = false } = ...
src/vanilla.ts
Outdated
@@ -125,9 +125,13 @@ const buildProxyFunction = ( | |||
return | |||
} | |||
const value = Reflect.get(target, key) | |||
const { enumerable = false } = Reflect.getOwnPropertyDescriptor( |
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.
If undefined
is acceptable by TypeScript, let's go with it. (We just avoid using the knowledge what is the default.)
const { enumerable = false } = Reflect.getOwnPropertyDescriptor( | |
const { enumerable } = Reflect.getOwnPropertyDescriptor( |
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 not? #800 (comment) seems to say so.
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 { enumerable } = Reflect.getOwnPropertyDescriptor(
target,
key
) as PropertyDescriptor
const desc: PropertyDescriptor = {
value,
enumerable: enumerable as boolean,
// This is intentional to avoid copying with proxy-compare.
// It's still non-writable, so it avoids assigning a value.
configurable: true,
}
As I understand, this is correct from JavaScript view and doesn't rely on defineProperty
defaults.
as boolean
silences TypeScript (although, is not strictly correct type-wise)
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. I think the TS hack is reasonable.
Related Issues or Discussions
Fixes #726
Summary
Check List
yarn run prettier
for formatting code and docs