diff --git a/lib.nix b/lib.nix index 44de581..92901d1 100644 --- a/lib.nix +++ b/lib.nix @@ -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: diff --git a/lib.test.nix b/lib.test.nix index 8854a59..9b815c6 100644 --- a/lib.test.nix +++ b/lib.test.nix @@ -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))