"A.B.C" for a JS member chain over identifiers, or false. */
| 238 | |
| 239 | /* "A.B.C" for a JS member chain over identifiers, or false. */ |
| 240 | static bool dotted_name(CBMExtractCtx *ctx, TSNode node, char *out, size_t cap, int depth) { |
| 241 | const char *k = ts_node_type(node); |
| 242 | if (strcmp(k, "identifier") == 0) { |
| 243 | const char *t = cbm_node_text(ctx->arena, node, ctx->source); |
| 244 | return t && snprintf(out, cap, "%s", t) < (int)cap; |
| 245 | } |
| 246 | if (strcmp(k, "member_expression") != 0 || depth >= FOLD_MAX_OBJ_DEPTH) { |
| 247 | return false; |
| 248 | } |
| 249 | TSNode obj = ts_node_child_by_field_name(node, TS_FIELD("object")); |
| 250 | TSNode prop = ts_node_child_by_field_name(node, TS_FIELD("property")); |
| 251 | if (ts_node_is_null(obj) || ts_node_is_null(prop) || |
| 252 | strcmp(ts_node_type(prop), "property_identifier") != 0 || |
| 253 | !dotted_name(ctx, obj, out, cap, depth + SKIP_ONE)) { |
| 254 | return false; |
| 255 | } |
| 256 | const char *p = cbm_node_text(ctx->arena, prop, ctx->source); |
| 257 | size_t used = strlen(out); |
| 258 | return p && snprintf(out + used, cap - used, ".%s", p) < (int)(cap - used); |
| 259 | } |
| 260 | |
| 261 | static const char *fold_reference(CBMExtractCtx *ctx, TSNode node, bool url) { |
| 262 | char name[FOLD_NAME_BUF]; |
no test coverage detected