- additional types: bigint
- can serialize/deserialize without reading source code
- no function serialization/deserialization
A DJS module parses into ast/module.f.mjs; the types in ast/types.ts carry the shape and its invariants.
Why a flat list of constants with index references, rather than a value tree:
a DJS module denotes a graph, and import and const are how it names
the shared parts. Deserializing has to preserve that sharing — two properties
holding the same reference must yield the same object, not two equal copies —
so the AST keeps the constants addressable and refers to them by index
instead of inlining them. That is also what makes serialization a real
choice: a value referenced more than once is emitted as a const and reused.
See examples/input.f.mjs.
- use JS tokenizer
- identifiers
{a:5} - computed keys
{["a"]:5}, the only spelling of a__proto__key (spec: the__proto__key) - big int
-
export default ... - constants
Serialization
const a = [3] export default = { a: a, b: a }
const _0=[3] export default {a:_0,b:_0}
- import
import a from 'c.f.js' export default { a: a, b: a}
- short form
const a = 5; export default { a }
Optional, for fun, syntax sugar:
- comments. Ignore them. Not an error.
- double/single quote strings
- using operator and functions
const a = 2+2+Math.abs(5) export default { a: a }
- decidable functions?
const f = a => b => a + b export default f(1)(2)