Skip to content
Open
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
10 changes: 8 additions & 2 deletions ast/src/lang/queries/react_ts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,10 @@ impl Stack for TypeScriptReact {
)

(method_definition
name: (property_identifier) @{FUNCTION_NAME} (#not-eq? @{FUNCTION_NAME} "render")
name: [
(property_identifier)
(private_property_identifier)
] @{FUNCTION_NAME} (#not-eq? @{FUNCTION_NAME} "render")
parameters: (formal_parameters)? @{ARGUMENTS}
return_type: (type_annotation)? @{RETURN_TYPES}
) @{FUNCTION_DEFINITION}
Expand All @@ -359,7 +362,10 @@ impl Stack for TypeScriptReact {
) @{FUNCTION_DEFINITION}

(public_field_definition
name: (property_identifier) @{FUNCTION_NAME}
name: [
(property_identifier)
(private_property_identifier)
] @{FUNCTION_NAME}
value: [
(function_expression
parameters: (formal_parameters)? @{ARGUMENTS}
Expand Down
14 changes: 7 additions & 7 deletions ast/src/testing/coverage/typescript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ async fn test_btreemap_graph_structure() -> Result<()> {
assert_eq!(endpoints.len(), 22);

let functions = graph.find_nodes_by_type(NodeType::Function);
assert_eq!(functions.len(), 68);
assert_eq!(functions.len(), 75);

let unit_tests = graph.find_nodes_by_type(NodeType::UnitTest);
assert_eq!(unit_tests.len(), 8);
Expand All @@ -86,7 +86,7 @@ async fn test_btreemap_graph_structure() -> Result<()> {
assert_eq!(e2e_tests.len(), 3);

let classes = graph.find_nodes_by_type(NodeType::Class);
assert_eq!(classes.len(), 11);
assert_eq!(classes.len(), 13);

let data_models = graph.find_nodes_by_type(NodeType::DataModel);
assert_eq!(data_models.len(), 27);
Expand Down Expand Up @@ -116,7 +116,7 @@ async fn test_btreemap_test_to_function_edges() -> Result<()> {
assert_eq!(calls_edges, 18);

let contains_edges = graph.count_edges_of_type(EdgeType::Contains);
assert_eq!(contains_edges, 231);
assert_eq!(contains_edges, 241);

let handler_edges = graph.count_edges_of_type(EdgeType::Handler);
assert_eq!(handler_edges, 22);
Expand All @@ -133,8 +133,8 @@ async fn test_typescript_graph_upload() -> Result<()> {
let graph_ops = setup_typescript_graph().await?;
let (nodes, edges) = graph_ops.get_graph_size().await?;

assert_eq!(nodes, 231);
assert_eq!(edges, 320, "Expected 320 edges, got {}", edges);
assert_eq!(nodes, 241);
assert_eq!(edges, 337, "Expected 337 edges, got {}", edges);

Ok(())
}
Expand Down Expand Up @@ -341,8 +341,8 @@ async fn test_nodes_class_type() -> Result<()> {
)
.await?;

assert_eq!(count, 11);
assert_eq!(results.len(), 11);
assert_eq!(count, 13);
assert_eq!(results.len(), 13);

Ok(())
}
Expand Down
53 changes: 53 additions & 0 deletions ast/src/testing/typescript/src/private-methods.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Deep coverage for private (#-prefixed) class members.
// Every private-method FORM should be captured as a Function node whose name
// keeps the leading '#'. A private field with a non-function value must NOT
// become a Function. Calls through a `this` receiver (this.#x()) are a separate
// limitation and are intentionally not asserted as Calls edges here.

// @ast node: Class "TokenVault"
export class TokenVault {
// non-function private field — must NOT be captured as a Function
#secret = "seed";

// @ast node: Function "unlock"
unlock(challenge: string): boolean {
return this.#derive(challenge) === this.#secret;
}

// private instance method
// @ast node: Function "#derive"
#derive(salt: string): string {
return salt + this.#secret;
}

// async private method
// @ast node: Function "#rotate"
async #rotate(): Promise<void> {
this.#secret = await Promise.resolve(this.#derive("next"));
}

// static private method
// @ast node: Function "#hash"
static #hash(input: string): string {
return input.split("").reverse().join("");
}

// private arrow-function field
// @ast node: Function "#onChange"
#onChange = (value: string): void => {
this.#secret = value;
};
}

// @ast node: Class "RequestSigner"
export class RequestSigner {
// @ast node: Function "sign"
sign(payload: string): string {
return this.#compute(payload);
}

// @ast node: Function "#compute"
#compute(payload: string): string {
return payload.length.toString();
}
}
Loading