Skip to content

Commit

Permalink
fix(typescript): exclude member expressions that dont have a function…
Browse files Browse the repository at this point in the history
… value
  • Loading branch information
kkoomen committed Jul 9, 2023
1 parent 7cde9be commit 82e7c9a
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 16 deletions.
2 changes: 1 addition & 1 deletion helper/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 12 additions & 1 deletion helper/src/typescript/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,14 @@ impl<'a> TypescriptParser<'a> {
"generator_function_declaration" |
"method_definition" => Some(self.parse_function(&child_node)),

"member_expression" => Some(self.parse_member_expression(&child_node)),
"member_expression" => {
let tokens = self.parse_member_expression(&child_node).unwrap();
if tokens.is_empty() {
None
} else {
Some(Ok(tokens))
}
},

"class" | "class_declaration" => Some(self.parse_class(&child_node)),

Expand Down Expand Up @@ -169,6 +176,10 @@ impl<'a> TypescriptParser<'a> {
}
}

if tokens.get("function_name").is_none() {
return Ok(Map::new());
}

if let Some(parent) = node.parent() {
let func_node = parent.children(&mut parent.walk()).last();
match self.parse_function(&func_node.unwrap()) {
Expand Down
2 changes: 0 additions & 2 deletions scripts/run-vader-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ function filter-vader-output() {
local force_echo=0

while read -r; do
echo "$REPLY"

# Search for the first Vader output line.
if ((!hit_first_vader_line)); then
if [[ "$REPLY" = *'Starting Vader:'* ]]; then
Expand Down
12 changes: 0 additions & 12 deletions test/filetypes/javascript/functions.vader
Original file line number Diff line number Diff line change
Expand Up @@ -447,15 +447,3 @@ Expect javascript (generated comments with a description, @param and @returns ta
* @returns [TODO:description]
*/
function foo(a, b: str, c = 3, d: int = 5): Promise<int> {}

# ==============================================================================
# Function calls that should not generate documentation
# ==============================================================================
Given javascript (function call):
AdminPermissionModel.create(item);

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

Expect javascript (to not have generated a docblock):
AdminPermissionModel.create(item);
26 changes: 26 additions & 0 deletions test/filetypes/javascript/ignored-expressions.vader
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# ==============================================================================
# Function calls that should not generate documentation
# ==============================================================================
Given javascript (function call):
AdminPermissionModel.create(item);

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

Expect javascript (to not have generated a docblock):
AdminPermissionModel.create(item);

# ==============================================================================
# Member expressions with no function_name
# ==============================================================================
Given javascript (member expression with no function name):
class Foo {}
Foo.propTypes = {};

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

Expect javascript (to not have generated a docblock):
class Foo {}
Foo.propTypes = {};

0 comments on commit 82e7c9a

Please sign in to comment.