add possibility to skip variable definition

This commit is contained in:
Dmitriy Pleshevskiy 2024-05-20 13:42:48 +03:00
parent 00364dee14
commit 61cd06db30
Signed by: pleshevskiy
GPG key ID: 17041163DA10A9A2
2 changed files with 7 additions and 1 deletions

View file

@ -127,7 +127,9 @@ let
if isJoin expr && expr.sep == "." then expr
else if isRaw expr then expr
else raw (validString expr);
set = var: val: join " = " [ (validSetVariable var) val ];
set = var: val:
if val == null then null
else join " = " [ (validSetVariable var) val ];
# Type: validBlockBody :: a -> [b]
validBlockBody = body:

View file

@ -193,6 +193,10 @@ with nix2lua; pkgs.lib.runTests {
expr = toLua (lset "parser_config.d2" { });
expected = "local parser_config.d2 = { }";
};
"test skips a var definition if value is null" = {
expr = toLua (set "vim.opt.number" null);
expected = null;
};
"test returns all operations" = {
expr = toLua (spaceBetween [
(set "a" (eq (mul (add 1 2) (sub 2 1)) 3))