fix(js/ts) Do not duplicate @return (#79)

This commit is contained in:
danymat
2022-03-11 10:21:54 +01:00
parent 26d9289e7e
commit f2aeb078f0
2 changed files with 23 additions and 14 deletions

View File

@@ -8,14 +8,14 @@ local function_tree = {
retrieve = "first", retrieve = "first",
node_type = "formal_parameters", node_type = "formal_parameters",
subtree = { subtree = {
{ retrieve = "all", node_type = "identifier", extract = true }, { retrieve = "all", node_type = "identifier", extract = true, as = i.Parameter },
}, },
}, },
{ {
retrieve = "first", retrieve = "first",
node_type = "statement_block", node_type = "statement_block",
subtree = { subtree = {
{ retrieve = "first", node_type = "return_statement", extract = true }, { retrieve = "first", node_type = "return_statement", extract = true, as = i.Return },
}, },
}, },
} }
@@ -40,42 +40,42 @@ return {
["0"] = { ["0"] = {
extract = function(node) extract = function(node)
local results = {}
local tree = function_tree local tree = function_tree
local nodes = nodes_utils:matching_nodes_from(node, tree) local nodes = nodes_utils:matching_nodes_from(node, tree)
local res = extractors:extract_from_matched(nodes) local res = extractors:extract_from_matched(nodes)
results.parameters = res.identifier if res[i.Return] then
results.return_statement = res.return_statement res[i.Return] = { true }
return results end
return res
end, end,
}, },
}, },
["expression_statement|variable_declaration"] = { ["expression_statement|variable_declaration"] = {
["0"] = { ["0"] = {
extract = function(node) extract = function(node)
local results = {}
local tree = { { retrieve = "all", node_type = "function", subtree = function_tree } } local tree = { { retrieve = "all", node_type = "function", subtree = function_tree } }
local nodes = nodes_utils:matching_nodes_from(node, tree) local nodes = nodes_utils:matching_nodes_from(node, tree)
local res = extractors:extract_from_matched(nodes) local res = extractors:extract_from_matched(nodes)
results.parameters = res.identifier if res[i.Return] then
results.return_statement = res.return_statement res[i.Return] = { true }
return results end
return res
end, end,
}, },
}, },
["lexical_declaration"] = { ["lexical_declaration"] = {
["1"] = { ["1"] = {
extract = function(node) extract = function(node)
local results = {}
local tree = { { retrieve = "all", node_type = "arrow_function", subtree = function_tree } } local tree = { { retrieve = "all", node_type = "arrow_function", subtree = function_tree } }
local nodes = nodes_utils:matching_nodes_from(node, tree) local nodes = nodes_utils:matching_nodes_from(node, tree)
local res = extractors:extract_from_matched(nodes) local res = extractors:extract_from_matched(nodes)
results.parameters = res.identifier if res[i.Return] then
results.return_statement = res.return_statement res[i.Return] = { true }
return results end
return res
end, end,
}, },
}, },

View File

@@ -85,6 +85,9 @@ return {
local nodes = nodes_utils:matching_nodes_from(node, tree) local nodes = nodes_utils:matching_nodes_from(node, tree)
local res = extractors:extract_from_matched(nodes) local res = extractors:extract_from_matched(nodes)
res[i.Tparam] = construct_type_annotation(nodes[i.Tparam]) res[i.Tparam] = construct_type_annotation(nodes[i.Tparam])
if res[i.Return] then
res[i.Return] = { true }
end
return res return res
end, end,
}, },
@@ -96,6 +99,9 @@ return {
local nodes = nodes_utils:matching_nodes_from(node, tree) local nodes = nodes_utils:matching_nodes_from(node, tree)
local res = extractors:extract_from_matched(nodes) local res = extractors:extract_from_matched(nodes)
res[i.Tparam] = construct_type_annotation(nodes[i.Tparam]) res[i.Tparam] = construct_type_annotation(nodes[i.Tparam])
if res[i.Return] then
res[i.Return] = { true }
end
return res return res
end, end,
}, },
@@ -107,6 +113,9 @@ return {
local nodes = nodes_utils:matching_nodes_from(node, tree) local nodes = nodes_utils:matching_nodes_from(node, tree)
local res = extractors:extract_from_matched(nodes) local res = extractors:extract_from_matched(nodes)
res[i.Tparam] = construct_type_annotation(nodes[i.Tparam]) res[i.Tparam] = construct_type_annotation(nodes[i.Tparam])
if res[i.Return] then
res[i.Return] = { true }
end
return res return res
end, end,
}, },