From 65ed95c93aeaeea96796eb6af5dfe8870eda0992 Mon Sep 17 00:00:00 2001 From: Alex Wilson Date: Sat, 12 Aug 2023 12:04:00 +0100 Subject: [PATCH] Expose the names of a module's defined function via `modulemeta` This reuses the existing `block_list_funcs` capability and adds an extra field on the `modulemeta` output, called `defs`, containing that list of functions. --- src/linker.c | 1 + tests/jq.test | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/linker.c b/src/linker.c index 32a8f032b1..e86c2b4e77 100644 --- a/src/linker.c +++ b/src/linker.c @@ -390,6 +390,7 @@ jv load_module_meta(jq_state *jq, jv mod_relpath) { if (jv_get_kind(meta) == JV_KIND_NULL) meta = jv_object(); meta = jv_object_set(meta, jv_string("deps"), block_take_imports(&program)); + meta = jv_object_set(meta, jv_string("defs"), block_list_funcs(program, 0)); } locfile_free(src); block_free(program); diff --git a/tests/jq.test b/tests/jq.test index 94dec3fb8f..eff15e0009 100644 --- a/tests/jq.test +++ b/tests/jq.test @@ -1624,11 +1624,15 @@ jq: error: Import path must be constant at , line 1: modulemeta "c" -{"whatever":null,"deps":[{"as":"foo","is_data":false,"relpath":"a"},{"search":"./","as":"d","is_data":false,"relpath":"d"},{"search":"./","as":"d2","is_data":false,"relpath":"d"},{"search":"./../lib/jq","as":"e","is_data":false,"relpath":"e"},{"search":"./../lib/jq","as":"f","is_data":false,"relpath":"f"},{"as":"d","is_data":true,"relpath":"data"}]} +{"whatever":null,"deps":[{"as":"foo","is_data":false,"relpath":"a"},{"search":"./","as":"d","is_data":false,"relpath":"d"},{"search":"./","as":"d2","is_data":false,"relpath":"d"},{"search":"./../lib/jq","as":"e","is_data":false,"relpath":"e"},{"search":"./../lib/jq","as":"f","is_data":false,"relpath":"f"},{"as":"d","is_data":true,"relpath":"data"}],"defs":["a/0","c/0"]} -modulemeta | .deps |= length +modulemeta | .deps | length "c" -{"whatever":null,"deps":6} +6 + +modulemeta | .defs | length +"c" +2 %%FAIL IGNORE MSG import "syntaxerror" as e; .