Skip to content

Commit

Permalink
Add "isWritable" before writing to properties
Browse files Browse the repository at this point in the history
  • Loading branch information
scagood committed Mar 1, 2024
1 parent 18c32c5 commit f370f75
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ var hasOwnProperty = Object.prototype.hasOwnProperty || function (obj, key) {
return key in obj;
};

function isWritable(object, key) {
var descriptor = Object.getOwnPropertyDescriptor(object, key);
return descriptor && !descriptor.writable;
}

function copy(src) {
if (typeof src === 'object' && src !== null) {
var dst;
Expand Down Expand Up @@ -196,7 +201,11 @@ function walk(root, cb, immutable) {
if (modifiers.pre) { modifiers.pre.call(state, state.node[key], key); }

var child = walker(state.node[key]);
if (immutable && hasOwnProperty.call(state.node, key)) {
if (
immutable
&& hasOwnProperty.call(state.node, key)
&& !isWritable(state.node, key)
) {
state.node[key] = child.node;
}

Expand Down

0 comments on commit f370f75

Please sign in to comment.