Skip to content

Commit

Permalink
fix: set prototyped/undefined properties in mergeProps
Browse files Browse the repository at this point in the history
  • Loading branch information
juanrgm committed Jun 6, 2023
1 parent ea5810a commit 272b138
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions packages/solid/src/render/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ export function mergeProps<T extends unknown[]>(...sources: T): MergeProps<T> {
}
const target: Record<string, any> = {};
const sourcesMap: Record<string, any[]> = {};
const defined = new Set<string>()
//let someNonTargetKey = false;

for (let i = sources.length - 1; i >= 0; i--) {
Expand All @@ -233,24 +234,25 @@ export function mergeProps<T extends unknown[]>(...sources: T): MergeProps<T> {
//someNonTargetKey = someNonTargetKey || (i !== 0 && !!sourceKeys.length);
for (let i = 0, length = sourceKeys.length; i < length; i++) {
const key = sourceKeys[i];
if (key === "__proto__" || key === "constructor") {
if (key === "__proto__" || key === "constructor")
continue;
} else if (!(key in target)) {
const desc = Object.getOwnPropertyDescriptor(source, key)!;
const desc = Object.getOwnPropertyDescriptor(source, key)!;
if (!defined.has(key)) {
if (desc.get) {
defined.add(key);
Object.defineProperty(target, key, {
enumerable: true,
// [breaking && performance]
// configurable: false,
configurable: true,
get: resolveSources.bind(
(sourcesMap[key] = [desc.get.bind(source)])
),
});
} else target[key] = desc.value;
} else {
if (desc.value !== undefined) defined.add(key);
target[key] = desc.value;
}
} else {
const sources = sourcesMap[key];
const desc = Object.getOwnPropertyDescriptor(source, key)!;
if (sources) {
if (desc.get) {
sources.push(desc.get.bind(source));
Expand Down

0 comments on commit 272b138

Please sign in to comment.