Skip to content

Commit 32af2cb

Browse files
authored
Merge pull request #652 from kkoomen/feature/js-member-expression-param
Ignore member expressions as function param in JS/TS
2 parents aa449a3 + c875221 commit 32af2cb

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

Diff for: helper/src/typescript/parser.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,13 @@ impl<'a> TypescriptParser<'a> {
177177
fn parse_member_expression(&self, node: &Node) -> Result<Map<String, Value>, String> {
178178
let mut tokens = Map::new();
179179

180+
// If a member expression is part of a function parameter, ignore it.
181+
if let Some(parent_node) = node.parent() {
182+
if ["required_parameter", "rest_parameter", "optional_parameter"].contains(&parent_node.kind()) {
183+
return Ok(tokens);
184+
}
185+
}
186+
180187
for child_node in node.children(&mut node.walk()) {
181188
match child_node.kind() {
182189
"member_expression" => {
@@ -301,7 +308,7 @@ impl<'a> TypescriptParser<'a> {
301308
tokens.insert("params".to_string(), Value::Array(params));
302309
}
303310
}
304-
}
311+
},
305312
_ => {},
306313
}
307314
}
@@ -372,7 +379,7 @@ impl<'a> TypescriptParser<'a> {
372379
subparam.insert("name".to_string(), Value::String(subparam_name));
373380
subparam.insert("optional".to_string(), Value::Bool(true));
374381
},
375-
"pair_pattern" =>{
382+
"pair_pattern" => {
376383
let subparam_name = node
377384
.children(&mut node.walk())
378385
.next()

Diff for: test/filetypes/javascript/functions.vader

+22
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,28 @@ Expect javascript (generated comments with a description, @param and @returns ta
366366
*/
367367
function foo({ a, b: str, c = 3, d: int = 5 }) {}
368368

369+
# ==============================================================================
370+
# Test function references as default values
371+
# ==============================================================================
372+
Given javascript (functions with destructuring_props):
373+
function foo(bar = import.meta.url) {
374+
return true;
375+
}
376+
377+
Do (trigger doge):
378+
\<C-d>
379+
380+
Expect javascript (generated comments with a description, @param and @returns tags):
381+
/**
382+
* [TODO:description]
383+
*
384+
* @param {[TODO:type]} [bar] - [TODO:description]
385+
* @returns {[TODO:type]} [TODO:description]
386+
*/
387+
function foo(bar = import.meta.url) {
388+
return true;
389+
}
390+
369391
# ==============================================================================
370392
# Test the 'omit_redundant_param_types' option
371393
# ==============================================================================

0 commit comments

Comments
 (0)