Skip to content

Commit a41a5f8

Browse files
committed
fix debug/1 function to be available only when debug/0 is defined
1 parent f694c1b commit a41a5f8

File tree

5 files changed

+17
-4
lines changed

5 files changed

+17
-4
lines changed

builtin.go

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

builtin.jq

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ def sub($re; str; $flags):
160160
def gsub($re; str): sub($re; str; "g");
161161
def gsub($re; str; $flags): sub($re; str; $flags + "g");
162162

163-
def debug(f): (f | debug | empty), .;
164163
def inputs:
165164
try
166165
repeat(input)

compiler.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -993,6 +993,22 @@ func (c *compiler) compileFunc(e *Func) error {
993993
true,
994994
-1,
995995
)
996+
case "debug":
997+
setfork := c.lazy(func() *code {
998+
return &code{op: opfork, v: len(c.codes)}
999+
})
1000+
if err := c.compileQuery(e.Args[0]); err != nil {
1001+
return err
1002+
}
1003+
if err := c.compileFunc(&Func{Name: "debug"}); err != nil {
1004+
if _, ok := err.(*funcNotFoundError); ok {
1005+
err = &funcNotFoundError{e}
1006+
}
1007+
return err
1008+
}
1009+
c.append(&code{op: opbacktrack})
1010+
setfork()
1011+
return nil
9961012
default:
9971013
return c.compileCall(e.Name, e.Args)
9981014
}

compiler_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,6 @@ func BenchmarkCompile(b *testing.B) {
353353
_, err := gojq.Compile(
354354
query,
355355
gojq.WithInputIter(gojq.NewIter()),
356-
gojq.WithFunction("debug", 0, 0,
357-
func(v any, _ []any) any { return v }),
358356
)
359357
if err != nil {
360358
b.Fatal(err)

func.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ func init() {
5151
"builtins": argFunc0(nil),
5252
"input": argFunc0(nil),
5353
"modulemeta": argFunc0(nil),
54+
"debug": argFunc1(nil),
5455
"abs": argFunc0(funcAbs),
5556
"length": argFunc0(funcLength),
5657
"utf8bytelength": argFunc0(funcUtf8ByteLength),

0 commit comments

Comments
 (0)