serialize-javascript icon indicating copy to clipboard operation
serialize-javascript copied to clipboard

Symbols

Open thatjessicakelly opened this issue 8 years ago • 5 comments

I'm not sure if you want to have symbols as part of this or not

{
  [Symbol('foo')]: Symbol('bar')
}

thatjessicakelly avatar Mar 08 '16 00:03 thatjessicakelly

The current implementation uses JSON.stringify() with a replacer function, which doesn't support Symbol keys.

It could "work" for Symbol values, but I'm curious to know how you are thinking of using this feature…

ericf avatar Mar 08 '16 00:03 ericf

We're planning to use something like serialize-javascript to deduplicate calls with the same arguments, by storing a serialized representation of the arguments and checking future calls against that.

fregante avatar May 18 '19 14:05 fregante

I was trying to serialize code that was referencing library using symbols..

Here's the sample

const { Op } = require('sequelize');
const s = require('serialize-javascript')

const result = s( { [Op.eq]: 123 });

it produces {} because Op.eq is a Symbol :(

karpikpl avatar Sep 16 '20 18:09 karpikpl

Symbols could be serialized in memory (by having a Map of symbols and their random stringified representation) but this will not work if you plan to save/restore the serialization on disk.

fregante avatar Sep 16 '20 19:09 fregante

unfortunately, I'm saving/restoring on disk.

what's kind of interesting is that serialize({ foo: () => console.info(Op.eq) }); works, but I guess that's just how [Op.eq] behaves...

karpikpl avatar Sep 16 '20 20:09 karpikpl