Skip to content

Commit

Permalink
Expose the names of a module's defined function via modulemeta
Browse files Browse the repository at this point in the history
This reuses the existing `block_list_funcs` capability and adds an extra field on the `modulemeta` output, called `defs`, containing that list of functions.
  • Loading branch information
mrwilson authored and nicowilliams committed Aug 13, 2023
1 parent fdab39b commit 65ed95c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/linker.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 7 additions & 3 deletions tests/jq.test
Original file line number Diff line number Diff line change
Expand Up @@ -1624,11 +1624,15 @@ jq: error: Import path must be constant at <top-level>, 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; .
Expand Down

0 comments on commit 65ed95c

Please # to comment.