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:
1 parent
1ef90acb38
commit
4f6045a94e
4 files changed
+1092
-1057
No files matched your search
@@ -357,6 +357,9 @@ Term "as" Patterns '|' Exp {
|
||||
"if" Exp "then" Exp ElseBody {
|
||||
$$ = gen_cond($2, $4, $5);
|
||||
} |
|
||||
"if" Exp "then" Exp "end" {
|
||||
$$ = gen_cond($2, $4, gen_noop());
|
||||
} |
|
||||
"if" Exp "then" error {
|
||||
FAIL(@$, "Possibly unterminated 'if' statement");
|
||||
$$ = $2;
|
||||
|
||||
Reference in new issue
Block a user