Skip to content
This repository was archived by the owner on Sep 9, 2025. It is now read-only.

Commit 9108b89

Browse files
authored
Merge branch 'github:main' into fix/python-nested-function-declaration
2 parents 3f1ebc2 + ea70811 commit 9108b89

5 files changed

Lines changed: 67 additions & 60 deletions

File tree

languages/tree-sitter-stack-graphs-python/src/stack-graphs.tsg

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -759,32 +759,39 @@ inherit .parent_module
759759

760760
(with_clause) {}
761761

762-
(function_definition
763-
name: (identifier) @name) {
764-
attr (@name.def) node_definition = @name
765-
}
766-
767-
(function_definition
768-
name: (identifier) @name
769-
parameters: (parameters) @params
770-
body: (block) @body) @func
771-
{
772-
node call
773-
node drop_scope
762+
[
763+
(function_definition
764+
parameters: (_) @params
765+
body: (_) @body
766+
) @func
767+
(lambda
768+
parameters: (_) @params
769+
body: (_) @body
770+
)@func
771+
] {
772+
node @func.call
774773
node return_value
774+
node drop_scope
775775

776-
attr (@name.def) definiens_node = @func
777-
edge @func.after_scope -> @name.def
778-
edge @name.def -> call
779-
edge call -> return_value
776+
edge @func.call -> return_value
780777
edge @body.before_scope -> @params.after_scope
781778
edge @body.before_scope -> drop_scope
782779
edge drop_scope -> @func.bottom
783780
attr (drop_scope) type = "drop_scopes"
784-
attr (call) pop_scoped_symbol = "()"
781+
attr (@func.call) pop_scoped_symbol = "()"
785782
edge @params.before_scope -> JUMP_TO_SCOPE_NODE
786783
attr (return_value) is_exported
787784
let @func.function_returns = return_value
785+
}
786+
787+
(function_definition
788+
name: (identifier) @name
789+
body: (_) @body
790+
) @func {
791+
attr (@name.def) node_definition = @name
792+
attr (@name.def) definiens_node = @func
793+
edge @func.after_scope -> @name.def
794+
edge @name.def -> @func.call
788795

789796
; Prevent functions defined inside of method bodies from being treated like methods
790797
let @body.class_self_scope = #null
@@ -802,8 +809,10 @@ inherit .parent_module
802809
attr (@param.output) push_node = @param
803810
}
804811

805-
(parameters
806-
(_) @param) @params
812+
[
813+
(parameters (_) @param) @params
814+
(lambda_parameters (_) @param) @params
815+
]
807816
{
808817
node @param.param_index
809818
node @param.param_name
@@ -954,6 +963,18 @@ inherit .parent_module
954963
;;
955964
;; Expressions
956965

966+
(lambda
967+
body: (_) @body
968+
)@lam {
969+
;; TODO Unify .before_scope, .local_scope, and .input to simplify
970+
;; uniform treatment of lambdas and function definitions.
971+
node @body.before_scope
972+
let @body.local_scope = @body.before_scope
973+
edge @body.input -> @body.before_scope
974+
975+
edge @lam.output -> @lam.call
976+
}
977+
957978
(conditional_expression) {}
958979

959980
(named_expression) {}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
sorted([1, 2, 3], key=lambda x: x)
2+
# ^ defined: 1

languages/tree-sitter-stack-graphs-typescript/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## v0.3.0 -- unreleased
9+
10+
### Added
11+
12+
- Support for TSX. A new language configuration for TSX is available, and TSX is enabled in the CLI next to TypeScript.
13+
814
## v0.2.0 -- 2024-03-06
915

1016
The `tree-sitter-stack-graphs` is updated to `v0.8`.

languages/tree-sitter-stack-graphs-typescript/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
[package]
22
name = "tree-sitter-stack-graphs-typescript"
3-
version = "0.2.0"
4-
description = "Stack graphs definition for TypeScript using tree-sitter-typescript"
3+
version = "0.3.0"
4+
description = "Stack graphs definition for TypeScript & TSX using tree-sitter-typescript"
55
readme = "README.md"
6-
keywords = ["tree-sitter", "stack-graphs", "typescript"]
6+
keywords = ["tree-sitter", "stack-graphs", "typescript", "tsx"]
77
authors = ["Hendrik van Antwerpen <hendrikvanantwerpen@github.com>"]
88
license = "MIT OR Apache-2.0"
99
edition = "2018"

languages/tree-sitter-stack-graphs-typescript/rust/bin.rs

Lines changed: 16 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6,56 +6,34 @@
66
// ------------------------------------------------------------------------------------------------
77

88
use anyhow::anyhow;
9-
use clap::{Parser, ValueEnum};
9+
use clap::Parser;
1010
use tree_sitter_stack_graphs::cli::database::default_user_database_path_for_crate;
1111
use tree_sitter_stack_graphs::cli::provided_languages::Subcommands;
12-
use tree_sitter_stack_graphs::loader::{LanguageConfiguration, LoadError};
1312
use tree_sitter_stack_graphs::NoCancellation;
1413

15-
/// Flag to select the dialect of the language
16-
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum)]
17-
pub enum Dialect {
18-
Typescript,
19-
TSX,
20-
}
21-
2214
fn main() -> anyhow::Result<()> {
2315
let cli = Cli::parse();
24-
let lc = match language_configuration(cli.dialect) {
25-
Ok(lc) => lc,
26-
Err(err) => {
27-
eprintln!("{}", err.display_pretty());
28-
return Err(anyhow!("Language configuration error"));
29-
}
30-
};
31-
let default_db_path = default_user_database_path_for_crate(env!("CARGO_PKG_NAME"))?;
32-
cli.subcommand.run(default_db_path, vec![lc])
33-
}
34-
35-
fn language_configuration<'a>(dialect: Dialect) -> Result<LanguageConfiguration, LoadError<'a>> {
36-
match dialect {
37-
Dialect::Typescript => {
38-
tree_sitter_stack_graphs_typescript::try_language_configuration_typescript(
39-
&NoCancellation,
40-
)
41-
}
42-
Dialect::TSX => {
43-
tree_sitter_stack_graphs_typescript::try_language_configuration_tsx(&NoCancellation)
44-
}
16+
let mut lcs = Vec::new();
17+
for r in [
18+
tree_sitter_stack_graphs_typescript::try_language_configuration_typescript(&NoCancellation),
19+
tree_sitter_stack_graphs_typescript::try_language_configuration_tsx(&NoCancellation),
20+
] {
21+
let lc = match r {
22+
Ok(lc) => lc,
23+
Err(err) => {
24+
eprintln!("{}", err.display_pretty());
25+
return Err(anyhow!("Language configuration error"));
26+
}
27+
};
28+
lcs.push(lc);
4529
}
30+
let default_db_path = default_user_database_path_for_crate(env!("CARGO_PKG_NAME"))?;
31+
cli.subcommand.run(default_db_path, lcs)
4632
}
4733

4834
#[derive(Parser)]
4935
#[clap(about, version)]
5036
pub struct Cli {
51-
#[clap(
52-
short,
53-
long,
54-
value_enum,
55-
default_value_t = Dialect::Typescript,
56-
)]
57-
dialect: Dialect,
58-
5937
#[clap(subcommand)]
6038
subcommand: Subcommands,
6139
}

0 commit comments

Comments
 (0)