Skip to content

Commit

Permalink
Shorten code for serializing Sets + Maps [refactor]
Browse files Browse the repository at this point in the history
  • Loading branch information
overlookmotel committed Dec 16, 2023
1 parent c445992 commit abe6bec
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions lib/serialize/setsMaps.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,7 @@ module.exports = {
const entryNodes = [];
entries.forEach((val, index) => {
const valRecord = this.serializeValue(val, `${varName}_${index}`, `<Set value ${index}>`);
if (isUnordered) {
isCircular = recordIsCircular(valRecord);
} else if (!isCircular && recordIsCircular(valRecord)) {
isCircular = true;
}
if (isUnordered || !isCircular) isCircular = recordIsCircular(valRecord);

if (isCircular) {
const arr = [valRecord.varNode];
Expand Down Expand Up @@ -91,10 +87,8 @@ module.exports = {
entries.forEach(([key, val], index) => {
const keyRecord = this.serializeValue(key, `${varName}Keys_${index}`, `<Map key ${index}>`);
const valRecord = this.serializeValue(val, `${varName}Values_${index}`, `<Map value ${index}>`);
if (isUnordered) {
if (isUnordered || !isCircular) {
isCircular = recordIsCircular(keyRecord) || recordIsCircular(valRecord);
} else if (!isCircular && (recordIsCircular(keyRecord) || recordIsCircular(valRecord))) {
isCircular = true;
}

const pair = [keyRecord.varNode, valRecord.varNode];
Expand Down

0 comments on commit abe6bec

Please sign in to comment.