From adfac399b1815731de6f12af1fc3e38516969dc7 Mon Sep 17 00:00:00 2001 From: fesily Date: Wed, 21 Feb 2024 15:02:35 +0800 Subject: add infer function param type --- script/json-edit.lua | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'script/json-edit.lua') diff --git a/script/json-edit.lua b/script/json-edit.lua index 30a55250..efa1216f 100644 --- a/script/json-edit.lua +++ b/script/json-edit.lua @@ -384,6 +384,7 @@ end local JsonEmpty = function () end +---@return {s: integer, d:integer, f:integer, v: any} local function decode_ast(str) if type(str) ~= "string" then error("expected argument of type string, got " .. type(str)) @@ -607,7 +608,11 @@ function OP.add(str, option, path, value) end local ast = decode_ast(str) if ast.v == JsonEmpty then - local pathlst = split_path(path) + local pathlst, err = split_path(path) + if not pathlst then + error(err) + return + end value = add_prefix(value, pathlst) return json.beautify(value, option) end @@ -674,7 +679,11 @@ function OP.replace(str, option, path, value) end local ast = decode_ast(str) if ast.v == JsonEmpty then - local pathlst = split_path(path) + local pathlst, err = split_path(path) + if not pathlst then + error(err) + return + end value = add_prefix(value, pathlst) return json.beautify(value, option) end -- cgit v1.2.3