A reference ID is a unique identifier stored in a serialized reference object. It replaces a JavaScript object reference so an AST reference can survive JSON serialization. section 7.2
Implement reference IDs by:
- Assigning every AST object an id property containing a unique string. section 7.2
- Replacing ref: targetObject with refId: targetObject.id during serialization. section 7.2
- Generating ten-character IDs with nanoid; collisions are unlikely enough for the example, though real ASTs should use longer IDs. section 7.2
Serialized reference
An AST object may have id "id1". A second object referring to it serializes its reference as { "refId": "id1" }, rather than embedding the JavaScript object. section 7.2
{
id: "<unique-ID>", #1
concept: "<concept>",
settings: {
// ...
}
}
Use the AST object shape to see where the identifier is stored before references are converted to refId values. section 7.2
