Skip to content

Commit 4198550

Browse files
committed
feat: improve stringify
1 parent 9afbb38 commit 4198550

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

test/utils/serialize-javascript.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ function serializeJavascriptRecursively(obj: any, options: InternalStringifyOpti
6565
console.log('-------------- serializeJavascriptRecursively --------------', parentPath, obj);
6666
}
6767
const sourceStr = JSON.stringify(fullObj, (_key, value) => {
68+
console.log([...parentPath, `${_key}`]);
6869
parentPath.push(_key);
6970
if (value === null) {
7071
parentPath.pop();
@@ -92,8 +93,7 @@ function serializeJavascriptRecursively(obj: any, options: InternalStringifyOpti
9293
parentPath.pop();
9394
return `${ST}new Error('${value.message}')${ET}`;
9495
} else if (typeof value === 'object') {
95-
console.log(_key);
96-
console.log('ssssssssssss', parentPath);
96+
console.log('value === object');
9797
// Save the symbol keys to a string property, because symbol keys are not serializable.
9898
// They will be restored in the deserialization process.
9999
for (const symbol of Object.getOwnPropertySymbols(value)) {
@@ -133,6 +133,9 @@ function serializeJavascriptRecursively(obj: any, options: InternalStringifyOpti
133133
}
134134
value[symbolKey] = symbolValue;
135135
}
136+
while (parentPath.length > 0 && parentPath[parentPath.length - 1] === '') {
137+
parentPath.pop();
138+
}
136139
parentPath.pop();
137140
return value;
138141
} else if (typeof value === 'function') {
@@ -157,8 +160,10 @@ function serializeJavascriptRecursively(obj: any, options: InternalStringifyOpti
157160
funcStr = funcStr.replace(/"/g, "'");
158161
parentPath.pop();
159162
return `${ST}(${funcStr})${ET}`;
163+
} else {
164+
parentPath.pop();
165+
return value;
160166
}
161-
return value;
162167
});
163168

164169
let prevPatches: Patch[] = [];

0 commit comments

Comments
 (0)