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

Add JavaScript #315

Merged
merged 205 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
205 commits
Select commit Hold shift + click to select a range
7816c9e
Adds .DS_Store to .gitignore
BekaValentine Apr 25, 2023
0c8cc6b
Adds JS stuff to be added; plus some integrations
BekaValentine Apr 25, 2023
59fcce6
Adds more updated rules and improves tests
BekaValentine Apr 28, 2023
96d3546
Removes test html files
BekaValentine Apr 28, 2023
3a59a56
Adds more JS
BekaValentine May 8, 2023
a147863
Adds more statements
BekaValentine May 9, 2023
1b65b0f
Adds more statements
BekaValentine May 10, 2023
2d8535f
Moves old tests into a dir
BekaValentine May 10, 2023
21caf96
Adds more expression tests and more statements
BekaValentine May 10, 2023
fa9c77e
Adds more section headers
BekaValentine May 10, 2023
a77344d
Update project structure
hendrikvanantwerpen May 10, 2023
b58fdfd
Depend on latest grammar commit
hendrikvanantwerpen May 10, 2023
6cba082
Adds array and object support
BekaValentine May 10, 2023
5ffec2b
Merge remote-tracking branch 'origin/main' into new-js-project-structure
hendrikvanantwerpen May 11, 2023
d71b3c5
Rename unused captures
hendrikvanantwerpen May 11, 2023
34944ad
Merge remote-tracking branch 'origin/main' into new-js-project-structure
hendrikvanantwerpen May 16, 2023
1aee011
Bump clap to v4
hendrikvanantwerpen May 16, 2023
d191811
Pin tree-sitter to v0.20.9 to prevent matching bug in v0.20.10
hendrikvanantwerpen May 16, 2023
d858b8c
Skip old tests
hendrikvanantwerpen May 16, 2023
f324f10
Merge remote-tracking branch 'origin/new_js' into new-js-project-stru…
hendrikvanantwerpen May 16, 2023
828c725
Fix captures and tests
hendrikvanantwerpen May 16, 2023
00aa02c
Merge pull request #268 from github/new-js-project-structure
hendrikvanantwerpen Jun 6, 2023
1bfeffc
[conv] initial
hendrikvanantwerpen Jul 12, 2023
2280a1d
[conv] shorthands
hendrikvanantwerpen Jul 12, 2023
37f4665
[conv] nodes
hendrikvanantwerpen Jul 12, 2023
c2357ed
[conv] global vars
hendrikvanantwerpen Jul 12, 2023
b6d70dd
[conv] nodes
hendrikvanantwerpen Jul 12, 2023
3dcfc56
[conv] attr
hendrikvanantwerpen Jul 12, 2023
efc1a8c
[conv] pop_symbol
hendrikvanantwerpen Jul 12, 2023
fa2a09b
[conv] push_symbol
hendrikvanantwerpen Jul 12, 2023
d467ea3
[conv] prog
hendrikvanantwerpen Jul 12, 2023
d10473c
[conv] empty_source_span
hendrikvanantwerpen Jul 12, 2023
dd57597
[conv] node_definition
hendrikvanantwerpen Jul 12, 2023
336885b
[conv] node_reference
hendrikvanantwerpen Jul 12, 2023
b1fcd45
[conv] ::prog
hendrikvanantwerpen Jul 12, 2023
6618f87
[conv] ::null
hendrikvanantwerpen Jul 12, 2023
6cea20b
[conv] ::string
hendrikvanantwerpen Jul 12, 2023
11d9ebc
[conv] ::exports
hendrikvanantwerpen Jul 12, 2023
99aeabb
[conv] ::number
hendrikvanantwerpen Jul 12, 2023
f75b0f9
[conv] ::number_prototype
hendrikvanantwerpen Jul 12, 2023
f111d75
[conv] ::return_or_yield
hendrikvanantwerpen Jul 12, 2023
d7ec123
[conv] remaining ::
hendrikvanantwerpen Jul 12, 2023
c268a0b
[conv] ::number_prototype
hendrikvanantwerpen Jul 12, 2023
0dfcea7
[conv] push_symbol
hendrikvanantwerpen Jul 12, 2023
f056230
[conv] push_node
hendrikvanantwerpen Jul 12, 2023
a5306f9
[conv] push_node
hendrikvanantwerpen Jul 12, 2023
80cbf2a
[conv] mor epops
hendrikvanantwerpen Jul 12, 2023
e922b1b
[conv] definitions
hendrikvanantwerpen Jul 12, 2023
34ab57a
[conv] refs
hendrikvanantwerpen Jul 12, 2023
b30c605
[conv] definiens
hendrikvanantwerpen Jul 12, 2023
9781ab8
[conv] syntax_type
hendrikvanantwerpen Jul 12, 2023
5d24f67
[conv] drop
hendrikvanantwerpen Jul 12, 2023
6d165dd
[conv] jump-to
hendrikvanantwerpen Jul 12, 2023
7424c0d
[conv] scoped
hendrikvanantwerpen Jul 12, 2023
a58d0be
[conv] endpoints
hendrikvanantwerpen Jul 12, 2023
a34ce9f
[conv] typos
hendrikvanantwerpen Jul 12, 2023
6be8243
[conv] unused captures
hendrikvanantwerpen Jul 12, 2023
c1418b3
[conv] align with other TSG
hendrikvanantwerpen Jul 12, 2023
b316d9a
[conv] use .builtins_
hendrikvanantwerpen Jul 12, 2023
20fc950
[conv] comment
hendrikvanantwerpen Jul 12, 2023
5e8bdfc
[conv] statements
hendrikvanantwerpen Jul 12, 2023
3fd0a98
[conv] align with existing
hendrikvanantwerpen Jul 12, 2023
72455a8
[conv] cleanup attrs
hendrikvanantwerpen Jul 12, 2023
419fd0c
[conv] child-index
hendrikvanantwerpen Jul 12, 2023
c9a30ad
[conv] is_endpoint
hendrikvanantwerpen Jul 12, 2023
515d6bb
[conv] attributes
hendrikvanantwerpen Jul 12, 2023
643b0dd
[conv] nodes
hendrikvanantwerpen Jul 12, 2023
cb7ac1d
[conv] fix array_pat duplicate edge
hendrikvanantwerpen Jul 12, 2023
a1591c1
[conv] source texts
hendrikvanantwerpen Jul 12, 2023
2a47553
move converted spec in place
hendrikvanantwerpen Jul 12, 2023
4422f4a
[conv] source-text
hendrikvanantwerpen Jul 12, 2023
82e1f6f
Merge remote-tracking branch 'origin/main' into new_js
hendrikvanantwerpen Jul 12, 2023
c0668e3
Update dependency versions
hendrikvanantwerpen Jul 12, 2023
e42a1e9
Do not create inherited .exports for every node
hendrikvanantwerpen Jul 12, 2023
f766d37
Reenable old tests
hendrikvanantwerpen Jul 12, 2023
2c16b0a
Fix test expectation
hendrikvanantwerpen Jul 12, 2023
9e04e60
Fix test expectation
hendrikvanantwerpen Jul 12, 2023
dc7f042
Revert `GUARD:MEMBER` to `.`
hendrikvanantwerpen Jul 12, 2023
be944ea
Don't make indices definitions
hendrikvanantwerpen Jul 12, 2023
a2145cf
Connect exports to existing @name.pop nodes
hendrikvanantwerpen Jul 12, 2023
ff5fce9
adjust test expectations
hendrikvanantwerpen Jul 12, 2023
297feec
adjust test expectations
hendrikvanantwerpen Jul 12, 2023
f8009e1
Add definiens_node and syntax_type attributes
hendrikvanantwerpen Jul 12, 2023
9465fbc
Re-adds organizational whitespace
BekaValentine Jul 12, 2023
8622de8
Pushes after_scope down into lower positions
BekaValentine Jul 13, 2023
dc6d646
Adds before_scope
BekaValentine Jul 17, 2023
a006cb7
Fix some issues with after/before_scopes
BekaValentine Jul 18, 2023
fa721b8
Lowers values
BekaValentine Jul 18, 2023
2fbd99c
Lowers covalues
BekaValentine Jul 18, 2023
c38d8fa
Removes lowered vars
BekaValentine Jul 18, 2023
482dc98
Lowers pop vars
BekaValentine Jul 18, 2023
139b48f
Lowers pop_dot
BekaValentine Jul 18, 2023
cb54a98
Removes old pop_dot
BekaValentine Jul 18, 2023
a86ab1b
Lowers push and push_dot
BekaValentine Jul 18, 2023
221a9c6
Lowers various arg vars
BekaValentine Jul 18, 2023
ad5d5fc
Lowers arguments nodes
BekaValentine Jul 19, 2023
0233f98
Lowers constructor vars
BekaValentine Jul 19, 2023
36bf6f3
Lowers call var
BekaValentine Jul 19, 2023
33fc0b7
Lowers drop var
BekaValentine Jul 19, 2023
f1b286a
Lowers element vars
BekaValentine Jul 19, 2023
31a45ed
Lowers index vars
BekaValentine Jul 19, 2023
cc09405
Lower member vars
BekaValentine Jul 19, 2023
95abdb0
Lowers this vars
BekaValentine Jul 19, 2023
fc58b4d
Lower key vars
BekaValentine Jul 19, 2023
23920bb
Lower label vars
BekaValentine Jul 19, 2023
1c79f94
Lower new_bindings
BekaValentine Jul 19, 2023
b1997b8
Lower return guard
BekaValentine Jul 19, 2023
91dbef5
Remove unused string prototype var
BekaValentine Jul 19, 2023
4552bfe
Remove unused rhsvar vars
BekaValentine Jul 19, 2023
d1ef86d
Lowers remainder of scoped vars
BekaValentine Jul 20, 2023
d4d2ca6
Documents more guard nodes
BekaValentine Jul 20, 2023
ff591b0
Renames "." to "GUARD:MEMBER" and documents it
BekaValentine Jul 20, 2023
dc1019e
Sorts guard docs
BekaValentine Jul 20, 2023
af19a18
Lowers return_or_yield
BekaValentine Jul 20, 2023
b45d455
Fixes minor bug
BekaValentine Jul 20, 2023
2742965
Removes external visibility of many vars
BekaValentine Jul 21, 2023
2a3fc6d
Merge pull request #294 from github/convert-more-js-tsg
BekaValentine Jul 24, 2023
73e72de
Adds some missing tests, fixes naming error
BekaValentine Jul 25, 2023
1fa3e5a
Reorgs
BekaValentine Jul 25, 2023
9b1f5e6
Adds some missing tests
BekaValentine Jul 25, 2023
5823da7
Adds class expression and class declaration tests
BekaValentine Jul 27, 2023
62944fd
Adds import tests
BekaValentine Jul 27, 2023
b2af299
Adds export statement tests
BekaValentine Jul 27, 2023
3e6450a
Add argument return/yield flow tests
BekaValentine Aug 3, 2023
a3561c1
Add constant return/yield tests
BekaValentine Aug 3, 2023
a4350ce
Add arguments var return/yield tests plus bug fix
BekaValentine Aug 3, 2023
5b67320
Adds this keyword flow tests
BekaValentine Aug 3, 2023
5388d86
Add closure flow tests
BekaValentine Aug 3, 2023
585d15a
Reorgs
BekaValentine Aug 3, 2023
da1a05b
Adds many class tests, including some failing TODO tests
BekaValentine Aug 7, 2023
bb3a246
Fixes minor test bug
BekaValentine Aug 8, 2023
81d7616
Merge branch 'main' into new_js
BekaValentine Aug 10, 2023
d0a31d7
Updates version for newest Stack Graph support
BekaValentine Aug 10, 2023
641fb54
Adds pattern tests
BekaValentine Aug 10, 2023
da45bcc
Moves .TODO files to officially supported .skip
BekaValentine Aug 11, 2023
f15237a
Fixes method arguments variable flow bug
BekaValentine Aug 15, 2023
3953a88
Fixes field and method visibility bug
BekaValentine Aug 16, 2023
1a0fc62
Fixes with statement shadowing bug
BekaValentine Aug 16, 2023
bff7fb1
Merge remote-tracking branch 'origin/main' into new_js
hendrikvanantwerpen Oct 4, 2023
936abec
Add tests
hendrikvanantwerpen Oct 4, 2023
fe94270
Add package.json analyzer
hendrikvanantwerpen Oct 4, 2023
1665551
Stack graph rule changes
hendrikvanantwerpen Oct 4, 2023
9419a52
Merge package test into single file
hendrikvanantwerpen Oct 5, 2023
f470da0
Make all package.json fields optional
hendrikvanantwerpen Oct 5, 2023
2b8618c
Port more stack graph changes
hendrikvanantwerpen Oct 5, 2023
38919a3
A few more changes
hendrikvanantwerpen Oct 5, 2023
0505878
cargo fmt
hendrikvanantwerpen Oct 5, 2023
efeab79
A few more changes
hendrikvanantwerpen Oct 5, 2023
2849522
Fix unrealistic expectations
hendrikvanantwerpen Oct 5, 2023
a887a28
Merge remote-tracking branch 'origin/main' into new_js
hendrikvanantwerpen Oct 5, 2023
34c4c52
Merge branch 'new_js' into new_js_port_recent_changes
hendrikvanantwerpen Oct 5, 2023
d0754f7
Ensure all default guards are references/definitions
hendrikvanantwerpen Oct 5, 2023
36c24aa
Merge pull request #316 from github/new_js_port_recent_changes
BekaValentine Oct 5, 2023
90f8af4
Merge remote-tracking branch 'origin/main' into new_js
hendrikvanantwerpen Oct 10, 2023
0afdd2a
Adds missing syntax types
hendrikvanantwerpen Oct 9, 2023
a352c39
Adds class to definiens rules for assignments etc
hendrikvanantwerpen Oct 9, 2023
46dde3e
Excludes CommonJS exports from definiens
hendrikvanantwerpen Oct 9, 2023
e53474a
Adds test case and fix
hendrikvanantwerpen Oct 9, 2023
f3bb1d8
Fix test assertion
hendrikvanantwerpen Oct 9, 2023
0ffa7b4
Adds fix for default CommonJS default imports
hendrikvanantwerpen Oct 9, 2023
1bce687
Adds current versions of tests, etc.
hendrikvanantwerpen Oct 9, 2023
5e978ce
Reorgs
hendrikvanantwerpen Oct 10, 2023
664772e
Reorg (cont.)
hendrikvanantwerpen Oct 10, 2023
ecba922
Adds default import test & Fixes bugs
hendrikvanantwerpen Oct 10, 2023
3525306
Adds CJS versions of tests
hendrikvanantwerpen Oct 10, 2023
37ef4a2
Removes some commented out queries
hendrikvanantwerpen Oct 10, 2023
a595055
Adds first vea test
hendrikvanantwerpen Oct 10, 2023
8b4bfee
Fixes small bug
hendrikvanantwerpen Oct 10, 2023
c4f5b45
Adds bug fixes for transitive callers
hendrikvanantwerpen Oct 10, 2023
050a6cb
Adds some new tests and fixes
hendrikvanantwerpen Oct 10, 2023
f6a6b08
Removes no-longer-needed definition baselines
hendrikvanantwerpen Oct 11, 2023
b2f5370
Adds more tests and some bug fixes
hendrikvanantwerpen Oct 11, 2023
5c817dc
Reorgs and fixes some bugs
hendrikvanantwerpen Oct 11, 2023
fec4e45
Add remaining tests and bug fixes
hendrikvanantwerpen Oct 12, 2023
2f582a9
Adds more tests and testing info
hendrikvanantwerpen Oct 12, 2023
e0f66aa
Fixes definiens syntax types
hendrikvanantwerpen Oct 12, 2023
310995d
Remove unnecessary patterns
hendrikvanantwerpen Oct 12, 2023
9b13fc1
Adds empty statement block bug fix
hendrikvanantwerpen Oct 12, 2023
a543dbd
Hoisting changes:
hendrikvanantwerpen Oct 12, 2023
182ab99
Adds support for `import`'s default field
hendrikvanantwerpen Oct 12, 2023
b9d5119
Adds tests for module.exports.foo pattern
hendrikvanantwerpen Oct 12, 2023
6c33f75
Adds fix for ES6 default exports
hendrikvanantwerpen Oct 12, 2023
83a470c
Add comment explaining import & export specifier rules
hendrikvanantwerpen Oct 10, 2023
03d755d
Fix definiens warning
hendrikvanantwerpen Oct 10, 2023
2e2e221
Drop explicit tree-sitter version dependency
hendrikvanantwerpen Oct 10, 2023
d8e6c28
Remove unconditional scope pass-throughs for empty elements
hendrikvanantwerpen Oct 11, 2023
4be77c5
Fix bug when main is unset in package.json and clarify behavior
hendrikvanantwerpen Oct 12, 2023
80d73ca
Make subscripts proper references
hendrikvanantwerpen Oct 13, 2023
00ea067
Add definiens for CommonJS exports
hendrikvanantwerpen Oct 13, 2023
271df51
Fix some default guard definiens
hendrikvanantwerpen Oct 13, 2023
a25b9c4
Use statement as definiens like the old code
hendrikvanantwerpen Oct 13, 2023
84015cc
Consolidate syntax type rules
hendrikvanantwerpen Oct 13, 2023
1178fc2
Port detour nodes
hendrikvanantwerpen Oct 13, 2023
2a81b45
Add missing expression
hendrikvanantwerpen Oct 13, 2023
769d984
Fix scope after member assignment
hendrikvanantwerpen Oct 14, 2023
1475444
Add exponential blowup tests (but skipped)
hendrikvanantwerpen Oct 16, 2023
8835141
Add reference for ES6/CommonJS interop.
hendrikvanantwerpen Oct 16, 2023
2a22ad2
Fix bug with string property keys
hendrikvanantwerpen Oct 16, 2023
5607681
Merge remote-tracking branch 'origin/main' into new_js
hendrikvanantwerpen Oct 17, 2023
e8feb26
Merge branch 'new_js' into new_js_more_changes
hendrikvanantwerpen Oct 17, 2023
a342c0d
Prefer higher-priority similar paths
hendrikvanantwerpen Oct 17, 2023
6fd2a98
Renable exponential blowup tests
hendrikvanantwerpen Oct 17, 2023
2c6de63
Merge remote-tracking branch 'origin/main' into new_js
hendrikvanantwerpen Oct 17, 2023
d067d27
Merge branch 'new_js' into new_js_more_changes
hendrikvanantwerpen Oct 17, 2023
169c94f
Merge pull request #320 from github/new_js_more_changes
BekaValentine Oct 19, 2023
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Publish tree-sitter-stack-graphs-javascript release

on:
push:
tags:
- tree-sitter-stack-graphs-javascript-v*

jobs:
publish-crate:
runs-on: ubuntu-latest
env:
CARGO_TERM_COLOR: always
CARGO_INCREMENTAL: 0
CRATE_DIR: './languages/tree-sitter-stack-graphs-javascript'
steps:
- name: Install Rust environment
uses: hecrj/setup-rust-action@v1
- name: Checkout repository
uses: actions/checkout@v3
# TODO Verify the crate version matches the tag
- name: Test crate
run: cargo test --all-features
working-directory: ${{ env.CRATE_DIR }}
- name: Verify publish crate
run: cargo publish --dry-run
working-directory: ${{ env.CRATE_DIR }}
- name: Publish crate
run: cargo publish
working-directory: ${{ env.CRATE_DIR }}
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
create-release:
needs: publish-crate
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Create GitHub release
uses: ncipollo/release-action@v1
with:
body: |
Find more info on all releases at https://crates.io/crates/tree-sitter-stack-graphs-javascript.
token: ${{ secrets.GITHUB_TOKEN }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ Cargo.lock
/.crates.toml
/.crates2.json
/bin/

# MacOS stuff
.DS_Store
5 changes: 5 additions & 0 deletions languages/tree-sitter-stack-graphs-javascript/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*.html
/Cargo.lock
/node_modules
/package-lock.json
/target
6 changes: 6 additions & 0 deletions languages/tree-sitter-stack-graphs-javascript/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Changelog for tree-sitter-stack-graphs-javascript

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
39 changes: 39 additions & 0 deletions languages/tree-sitter-stack-graphs-javascript/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
[package]
name = "tree-sitter-stack-graphs-javascript"
version = "0.1.0"
description = "Stack graphs definition for JavaScript using tree-sitter-javascript"
readme = "README.md"
keywords = ["tree-sitter", "stack-graphs", "javascript"]
authors = ["Beka Valentine <[email protected]>"]
license = "MIT OR Apache-2.0"
edition = "2018"

[[bin]]
name = "tree-sitter-stack-graphs-javascript"
path = "rust/bin.rs"
required-features = ["cli"]

[lib]
path = "rust/lib.rs"
test = false

[[test]]
name = "test"
path = "rust/test.rs"
harness = false

[features]
cli = ["anyhow", "clap", "tree-sitter-stack-graphs/cli"]

[dependencies]
anyhow = { version = "1.0", optional = true }
clap = { version = "4", optional = true }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
stack-graphs = { version = "0.12", path = "../../stack-graphs" }
tree-sitter-stack-graphs = { version = "0.7", path = "../../tree-sitter-stack-graphs" }
tree-sitter-javascript = { git = "https://github.com/tree-sitter/tree-sitter-javascript", rev = "5720b249490b3c17245ba772f6be4a43edb4e3b7" }

[dev-dependencies]
anyhow = "1.0"
tree-sitter-stack-graphs = { version = "0.7", path = "../../tree-sitter-stack-graphs", features = ["cli"] }
98 changes: 98 additions & 0 deletions languages/tree-sitter-stack-graphs-javascript/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# tree-sitter-stack-graphs definition for JavaScript

This project defines tree-sitter-stack-graphs rules for JavaScript using the [tree-sitter-javascript][] grammar.

[tree-sitter-javascript]: https://crates.io/crates/tree-sitter-javascript

## Usage

To use this library, add the following to your `Cargo.toml`:

``` toml
[dependencies]
tree-sitter-stack-graphs-javascript = "0.0.1"
```

Check out our [documentation](https://docs.rs/tree-sitter-stack-graphs-javascript/*/) for more details on how to use this library.

## Command-line Program

The command-line program for `tree-sitter-stack-graphs-javascript` lets you do stack graph based analysis and lookup from the command line.

Install the program using `cargo install` as follows:

``` sh
$ cargo install --features cli tree-sitter-stack-graphs-javascript
$ tree-sitter-stack-graphs-javascript --help
```

## Development

The project is written in Rust, and requires a recent version installed. Rust can be installed and updated using [rustup][].

[rustup]: https://rustup.rs/

The project is organized as follows:

- The stack graph rules are defined in `src/stack-graphs.tsg`.
- Builtins sources and configuration are defined in `src/builtins.js` and `builtins.cfg` respectively.
- Tests are put into the `test` directory.

### Building and Running Tests

Build the project by running:

``` sh
$ cargo build
```

Run the tests as follows:

``` sh
$ cargo test
```

The project consists of a library and a CLI. By default, running `cargo` only applies to the library. To run `cargo` commands on the CLI as well, add `--features cli` or `--all-features`.

Run the CLI from source as follows:

``` sh
$ cargo run --features cli -- ARGS
```

Sources are formatted using the standard Rust formatted, which is applied by running:

``` sh
$ cargo fmt
```

### Writing TSG

The stack graph rules are written in [tree-sitter-graph][]. Checkout the [examples][],
which contain self-contained TSG rules for specific language features. A VSCode
[extension][] is available that provides syntax highlighting for TSG files.

[tree-sitter-graph]: https://github.com/tree-sitter/tree-sitter-graph
[examples]: https://github.com/github/stack-graphs/blob/main/tree-sitter-stack-graphs/examples/
[extension]: https://marketplace.visualstudio.com/items?itemName=tree-sitter.tree-sitter-graph

Parse and test a single file by executing the following commands:

``` sh
$ cargo run --features cli -- parse FILES...
$ cargo run --features cli -- test TESTFILES...
```

Generate a visualization to debug failing tests by passing the `-V` flag:

``` sh
$ cargo run --features cli -- test -V TESTFILES...
```

To generate the visualization regardless of test outcome, execute:

``` sh
$ cargo run --features cli -- test -V --output-mode=always TESTFILES...
```

Go to https://crates.io/crates/tree-sitter-stack-graphs for links to examples and documentation.
33 changes: 33 additions & 0 deletions languages/tree-sitter-stack-graphs-javascript/rust/bin.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// -*- coding: utf-8 -*-
// ------------------------------------------------------------------------------------------------
// Copyright © 2023, stack-graphs authors.
// Licensed under either of Apache License, Version 2.0, or MIT license, at your option.
// Please see the LICENSE-APACHE or LICENSE-MIT files in this distribution for license details.
// ------------------------------------------------------------------------------------------------

use anyhow::anyhow;
use clap::Parser;
use tree_sitter_stack_graphs::cli::database::default_user_database_path_for_crate;
use tree_sitter_stack_graphs::cli::provided_languages::Subcommands;
use tree_sitter_stack_graphs::NoCancellation;

fn main() -> anyhow::Result<()> {
let lc = match tree_sitter_stack_graphs_javascript::try_language_configuration(&NoCancellation)
{
Ok(lc) => lc,
Err(err) => {
eprintln!("{}", err.display_pretty());
return Err(anyhow!("Language configuration error"));
}
};
let cli = Cli::parse();
let default_db_path = default_user_database_path_for_crate(env!("CARGO_PKG_NAME"))?;
cli.subcommand.run(default_db_path, vec![lc])
}

#[derive(Parser)]
#[clap(about, version)]
pub struct Cli {
#[clap(subcommand)]
subcommand: Subcommands,
}
56 changes: 56 additions & 0 deletions languages/tree-sitter-stack-graphs-javascript/rust/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// -*- coding: utf-8 -*-
// ------------------------------------------------------------------------------------------------
// Copyright © 2023, stack-graphs authors.
// Licensed under either of Apache License, Version 2.0, or MIT license, at your option.
// Please see the LICENSE-APACHE or LICENSE-MIT files in this distribution for license details.
// ------------------------------------------------------------------------------------------------

use tree_sitter_stack_graphs::loader::FileAnalyzers;
use tree_sitter_stack_graphs::loader::LanguageConfiguration;
use tree_sitter_stack_graphs::loader::LoadError;
use tree_sitter_stack_graphs::CancellationFlag;

use crate::npm_package::NpmPackageAnalyzer;

mod npm_package;
mod util;

/// The stack graphs tsg source for this language.
pub const STACK_GRAPHS_TSG_PATH: &str = "src/stack-graphs.tsg";
/// The stack graphs tsg source for this language.
pub const STACK_GRAPHS_TSG_SOURCE: &str = include_str!("../src/stack-graphs.tsg");

/// The stack graphs builtins configuration for this language.
pub const STACK_GRAPHS_BUILTINS_CONFIG: &str = include_str!("../src/builtins.cfg");
/// The stack graphs builtins path for this language
pub const STACK_GRAPHS_BUILTINS_PATH: &str = "src/builtins.js";
/// The stack graphs builtins source for this language.
pub const STACK_GRAPHS_BUILTINS_SOURCE: &str = include_str!("../src/builtins.js");

/// The name of the file path global variable.
pub const FILE_PATH_VAR: &str = "FILE_PATH";
pub const PROJECT_NAME_VAR: &str = "PROJECT_NAME";

pub fn language_configuration(cancellation_flag: &dyn CancellationFlag) -> LanguageConfiguration {
try_language_configuration(cancellation_flag).unwrap_or_else(|err| panic!("{}", err))
}

pub fn try_language_configuration(
cancellation_flag: &dyn CancellationFlag,
) -> Result<LanguageConfiguration, LoadError> {
LanguageConfiguration::from_sources(
tree_sitter_javascript::language(),
Some(String::from("source.js")),
None,
vec![String::from("js")],
STACK_GRAPHS_TSG_PATH.into(),
STACK_GRAPHS_TSG_SOURCE,
Some((
STACK_GRAPHS_BUILTINS_PATH.into(),
STACK_GRAPHS_BUILTINS_SOURCE,
)),
Some(STACK_GRAPHS_BUILTINS_CONFIG),
FileAnalyzers::new().add("package.json".to_string(), NpmPackageAnalyzer {}),
cancellation_flag,
)
}
Loading
Loading