yahoo / serialize-javascript

Serialize JavaScript to a superset of JSON that includes regular expressions and functions.
Other
2.82k stars 180 forks source link

Symbols #13

Open thatjessicakelly opened 8 years ago

thatjessicakelly commented 8 years ago

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

{
  [Symbol('foo')]: Symbol('bar')
}
ericf commented 8 years ago

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…

fregante commented 5 years ago

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.

karpikpl commented 4 years ago

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 :(

fregante commented 4 years ago

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.

karpikpl commented 4 years ago

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...