We strive to make the generated module as simple as possible while maininting all the behavior from the original code.
Sometimes it is impossible to identify whether some edge cases will happen or not, so the generated code might be more complicated than the original code.
Simple values
Simple values that can fully inspected are serialized with their normal JS syntax. Those include:
Strings
Numbers
Plain objects without nesting
Arrays without nesting
Booleans
BigInts
Symbols
For example the following module declaration:
Generates the following module:
Nested arrays and objects
Generates:
A bit more verbose than the original, but with the same result.
Circular values
Generates:
Sparse arrays
Generates:
Simple functions
Generates:
Classes
Classes in ECMAScript are syntactic sugar for defining values on the prototype chain. At runtime, it is impossible to find the original syntax that generated the values.
For maximum compatibility and to maintain all the minute bahaviors that an implementation might need this library serializes the verbose detailed definition of the class, even if some of those might not be needed.
Generates:
Instances
Serializing an instance implicitly serialize the class that originated them as well as the instance state.
Generates:
Capturing functions
Generates:
Imports of built-in modules
Values that were imported from a native Node module are detected and instead of serialized they are re-imported at runtime.
Generates:
Import of third-party dependencies
Values imported from third-party libraries are also detected and not serialized. But this only works for values that are exported somewhere in the third-party library.