Skip to content

Commit

Permalink
Change RegExp output
Browse files Browse the repository at this point in the history
  • Loading branch information
lxsmnsyc committed Mar 16, 2023
1 parent 8263427 commit 3493180
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
6 changes: 3 additions & 3 deletions packages/seroval/src/tree/primitives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,10 @@ export function createRegExpNode(id: number, current: RegExp): SerovalRegExpNode
return {
t: SerovalNodeType.RegExp,
i: id,
s: String(current),
s: undefined,
l: undefined,
c: undefined,
m: undefined,
c: current.source,
m: current.flags,
d: undefined,
a: undefined,
n: undefined,
Expand Down
2 changes: 1 addition & 1 deletion packages/seroval/src/tree/serialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ export default function serializeTree(
case SerovalNodeType.Date:
return assignRef(ctx, node.i, 'new Date("' + node.s + '")');
case SerovalNodeType.RegExp:
return assignRef(ctx, node.i, node.s);
return assignRef(ctx, node.i, '/' + node.c + '/' + node.m);
case SerovalNodeType.Set:
return serializeSet(ctx, node);
case SerovalNodeType.Map:
Expand Down
5 changes: 4 additions & 1 deletion packages/seroval/src/tree/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,10 @@ export interface SerovalDateNode extends SerovalBaseNode {
export interface SerovalRegExpNode extends SerovalBaseNode {
t: SerovalNodeType.RegExp;
i: number;
s: string;
// source
c: string;
// flags
m: string;
}

export interface SerovalTypedArrayNode extends SerovalBaseNode {
Expand Down
4 changes: 2 additions & 2 deletions packages/seroval/test/__snapshots__/regexp.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ exports[`RegExp > serialize > supports RegExp 1`] = `"/[a-z0-9]+/i"`;

exports[`RegExp > serializeAsync > supports RegExp 1`] = `"Promise.resolve(/[a-z0-9]+/i)"`;

exports[`RegExp > toJSON > supports RegExp 1`] = `"{\\"t\\":{\\"t\\":12,\\"i\\":0,\\"s\\":\\"/[a-z0-9]+/i\\"},\\"r\\":0,\\"i\\":false,\\"f\\":8191,\\"m\\":[]}"`;
exports[`RegExp > toJSON > supports RegExp 1`] = `"{\\"t\\":{\\"t\\":12,\\"i\\":0,\\"c\\":\\"[a-z0-9]+\\",\\"m\\":\\"i\\"},\\"r\\":0,\\"i\\":false,\\"f\\":8191,\\"m\\":[]}"`;

exports[`RegExp > toJSONAsync > supports RegExp 1`] = `"{\\"t\\":{\\"t\\":18,\\"i\\":0,\\"n\\":{\\"t\\":12,\\"i\\":1,\\"s\\":\\"/[a-z0-9]+/i\\"}},\\"r\\":0,\\"i\\":false,\\"f\\":8191,\\"m\\":[]}"`;
exports[`RegExp > toJSONAsync > supports RegExp 1`] = `"{\\"t\\":{\\"t\\":18,\\"i\\":0,\\"n\\":{\\"t\\":12,\\"i\\":1,\\"c\\":\\"[a-z0-9]+\\",\\"m\\":\\"i\\"}},\\"r\\":0,\\"i\\":false,\\"f\\":8191,\\"m\\":[]}"`;

0 comments on commit 3493180

Please sign in to comment.