Support "if" without "else" clause

Defaults the else clause to the identity filter "." if an else clause is
missing.

The following two jq programs are considered equivalent:

```
if .foo then
    .foo = "bar"
else
    .
end
```

```
if .foo then
    .foo = "bar"
end
```
This commit is contained in:
Chance Zibolski authored and Nico Williams committed 2019-02-20 20:03:26 -06:00
1 parent 1ef90acb38
commit 4f6045a94e
4 files changed
+1092 -1057

No files matched your search

+13
View File
@@ -1036,6 +1036,19 @@ null
null
[5,6]
[if true then 3 end]
7
[3]
[if false then 3 end]
7
[7]
[if false then 3 else . end]
7
[7]
[.[] | [.foo[] // .bar]]
[{"foo":[1,2], "bar": 42}, {"foo":[1], "bar": null}, {"foo":[null,false,3], "bar": 18}, {"foo":[], "bar":42}, {"foo": [null,false,null], "bar": 41}]
[[1,2], [1], [3], [42], [41]]