Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore member expressions as function param in JS/TS #652

Merged
merged 1 commit into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions helper/src/typescript/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,13 @@ impl<'a> TypescriptParser<'a> {
fn parse_member_expression(&self, node: &Node) -> Result<Map<String, Value>, String> {
let mut tokens = Map::new();

// If a member expression is part of a function parameter, ignore it.
if let Some(parent_node) = node.parent() {
if ["required_parameter", "rest_parameter", "optional_parameter"].contains(&parent_node.kind()) {
return Ok(tokens);
}
}

for child_node in node.children(&mut node.walk()) {
match child_node.kind() {
"member_expression" => {
Expand Down Expand Up @@ -301,7 +308,7 @@ impl<'a> TypescriptParser<'a> {
tokens.insert("params".to_string(), Value::Array(params));
}
}
}
},
_ => {},
}
}
Expand Down Expand Up @@ -372,7 +379,7 @@ impl<'a> TypescriptParser<'a> {
subparam.insert("name".to_string(), Value::String(subparam_name));
subparam.insert("optional".to_string(), Value::Bool(true));
},
"pair_pattern" =>{
"pair_pattern" => {
let subparam_name = node
.children(&mut node.walk())
.next()
Expand Down
22 changes: 22 additions & 0 deletions test/filetypes/javascript/functions.vader
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,28 @@ Expect javascript (generated comments with a description, @param and @returns ta
*/
function foo({ a, b: str, c = 3, d: int = 5 }) {}

# ==============================================================================
# Test function references as default values
# ==============================================================================
Given javascript (functions with destructuring_props):
function foo(bar = import.meta.url) {
return true;
}

Do (trigger doge):
\<C-d>

Expect javascript (generated comments with a description, @param and @returns tags):
/**
* [TODO:description]
*
* @param {[TODO:type]} [bar] - [TODO:description]
* @returns {[TODO:type]} [TODO:description]
*/
function foo(bar = import.meta.url) {
return true;
}

# ==============================================================================
# Test the 'omit_redundant_param_types' option
# ==============================================================================
Expand Down
Loading