Skip to content

Commit

Permalink
fix: exception with frozen object
Browse files Browse the repository at this point in the history
  • Loading branch information
r37r0m0d3l committed Jan 4, 2021
1 parent 386d814 commit af789c9
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 17 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

---

## 1.4.10

- ⬇️ Fixed exception with frozen object

## 1.4.9

- ⬇️ The minimum required Node JS version is now 8.0.0.
Expand Down
2 changes: 1 addition & 1 deletion dist/consono.browser.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/consono.browser.cjs.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/consono.browser.mjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/consono.browser.mjs.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/consono.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/consono.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/consono.node.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/consono.node.cjs.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/consono.node.mjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/consono.node.mjs.map

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
"@babel/core": "7.12.10",
"@babel/plugin-proposal-class-properties": "7.12.1",
"@babel/plugin-proposal-private-methods": "7.12.1",
"@babel/preset-env": "7.12.10",
"@babel/preset-env": "7.12.11",
"@rollup/plugin-commonjs": "17.0.0",
"@rollup/plugin-node-resolve": "11.0.0",
"@rollup/plugin-node-resolve": "11.0.1",
"babel-core": "7.0.0-bridge.0",
"babel-eslint": "10.1.0",
"eslint": "7.15.0",
"eslint-config-prettier": "7.0.0",
"eslint": "7.17.0",
"eslint-config-prettier": "7.1.0",
"eslint-plugin-prettier": "3.3.0",
"jest": "26.6.3",
"npm-check": "5.9.2",
Expand All @@ -33,7 +33,7 @@
"remark-preset-lint-consistent": "4.0.0",
"remark-preset-lint-markdown-style-guide": "4.0.0",
"remark-preset-lint-recommended": "5.0.0",
"rollup": "2.35.0",
"rollup": "2.35.1",
"rollup-plugin-auto-external": "2.0.0",
"rollup-plugin-babel": "4.4.0",
"rollup-plugin-terser": "7.0.2"
Expand Down Expand Up @@ -105,5 +105,5 @@
},
"type": "module",
"types": "./dist/consono.d.ts",
"version": "1.4.9"
"version": "1.4.10"
}
17 changes: 16 additions & 1 deletion src/utils/objectDeCycle.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
import TAG from "../const/tag.js";
import prototypeName from "./prototypeName.js";

function looseClone(object) {
if (object == null || typeof object !== "object") {
return object;
}
const inExactInstance = new object.constructor();
for (let key in object) {
inExactInstance[key] = looseClone(object[key]);
}
return inExactInstance;
}

export default function objectDeCycle(object) {
const objects = [];
const paths = [];
Expand Down Expand Up @@ -30,7 +41,11 @@ export default function objectDeCycle(object) {
newIterable[index] = deReCycle(value[index], `${path}["${index}"]`);
}
} else {
newIterable = Object.create(object);
if (Object.isFrozen(object)) {
newIterable = looseClone(object);
} else {
newIterable = Object.create(object);
}
for (name in value) {
if (Object.prototype.hasOwnProperty.call(value, name)) {
newIterable[name] = deReCycle(value[name], `${path}[${JSON.stringify(name)}]`);
Expand Down

0 comments on commit af789c9

Please sign in to comment.