toJsPath
Returns the JavaScript access path string representation of this pointer.
This is the inverse of Companion.fromJsPath. The canonical form is dot-preferred: a numeric segment is emitted in bracket form ([0]); a segment that is a safe dot identifier (non-empty, containing none of ., [, ], ', ", or \) is emitted in dot form (.key, with no leading dot on the first segment); any other segment is emitted bracket-quoted (['…']) with ' and \ backslash-escaped, preferred over dot-form escaping for readability. The empty string is not a safe dot identifier, so an empty segment is also bracket-quoted (['']).
Unlike the dot-notation serializer this replaces, this function is lossless for every segment and therefore never throws. The root pointer is emitted as "", so that the round-trip fromJsPath(p.toJsPath()) == p holds for every pointer, including ROOT.
Return
The JavaScript access path string; "" for the root pointer.