(js) Add support for functions in statements

This commit is contained in:
Daniel Mathiot
2021-08-24 12:44:33 +02:00
parent 3a40a1d111
commit 14424a0887

View File

@@ -1,18 +1,37 @@
local function_tree = {
{ retrieve = "first", node_type = "formal_parameters", subtree = {
{ retrieve = "all", node_type = "identifier", extract = true }
} },
{ retrieve = "first", node_type = "statement_block", subtree = {
{ retrieve = "first", node_type = "return_statement", extract = true }
} }
}
return { return {
parent = { "function_declaration" }, parent = { "function_declaration", "expression_statement" },
data = { data = {
["function_declaration"] = { ["function_declaration"] = {
["0"] = { ["0"] = {
extract = function (node)
local results = {}
local tree = function_tree
local nodes = neogen.utilities.nodes:matching_nodes_from(node, tree)
local res = neogen.utilities.extractors:extract_from_matched(nodes)
results.parameters = res.identifier
results.return_statement = res.return_statement
return results
end
}
},
["expression_statement"] = {
["0"] = {
extract = function (node) extract = function (node)
local results = {} local results = {}
local tree = { local tree = {
{ retrieve = "first", node_type = "formal_parameters", subtree = { { retrieve = "all", node_type = "assignment_expression", subtree = {
{ retrieve = "all", node_type = "identifier", extract = true } { retrieve = "all", node_type = "function", subtree = function_tree }
} },
{ retrieve = "first", node_type = "statement_block", subtree = {
{ retrieve = "first", node_type = "return_statement", extract = true }
} } } }
} }
local nodes = neogen.utilities.nodes:matching_nodes_from(node, tree) local nodes = neogen.utilities.nodes:matching_nodes_from(node, tree)