Strip type wrappers and `Object.freeze(...)` from a constant's value. */
| 299 | |
| 300 | /* Strip type wrappers and `Object.freeze(...)` from a constant's value. */ |
| 301 | static TSNode unwrap_value(CBMExtractCtx *ctx, TSNode v) { |
| 302 | for (int i = 0; i < FOLD_MAX_OBJ_DEPTH && !ts_node_is_null(v); i++) { |
| 303 | const char *k = ts_node_type(v); |
| 304 | if (is_transparent_wrapper(k) && ts_node_named_child_count(v) > 0) { |
| 305 | v = ts_node_named_child(v, 0); |
| 306 | continue; |
| 307 | } |
| 308 | if (strcmp(k, "call_expression") != 0) { |
| 309 | break; |
| 310 | } |
| 311 | TSNode fn = ts_node_child_by_field_name(v, TS_FIELD("function")); |
| 312 | TSNode args = ts_node_child_by_field_name(v, TS_FIELD("arguments")); |
| 313 | const char *ft = ts_node_is_null(fn) ? NULL : cbm_node_text(ctx->arena, fn, ctx->source); |
| 314 | if (!ft || strcmp(ft, "Object.freeze") != 0 || ts_node_is_null(args) || |
| 315 | ts_node_named_child_count(args) != SKIP_ONE) { |
| 316 | break; |
| 317 | } |
| 318 | v = ts_node_named_child(args, 0); |
| 319 | } |
| 320 | return v; |
| 321 | } |
| 322 | |
| 323 | static void record_value(CBMExtractCtx *ctx, const char *name, TSNode value, int depth); |
| 324 |
no test coverage detected