diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index ccbf0af84..03d88d403 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -74,13 +74,15 @@ jobs: env: | NPM_TOKEN=${{ secrets.NPM_TOKEN }} - - name: "infra publish cargo" - if: "${{ steps.runChangesets.outputs.hasChangesets == 'false' }}" - uses: "./.github/actions/devcontainer/run" - with: - runCmd: "./scripts/bin/infra publish cargo" - env: | - CARGO_REGISTRY_TOKEN=${{ secrets.CARGO_REGISTRY_TOKEN }} + # __SLANG_CARGO_PUBLISH_TEMPORARILY_DISABLED__ (keep in sync) + # + # - name: "infra publish cargo" + # if: "${{ steps.runChangesets.outputs.hasChangesets == 'false' }}" + # uses: "./.github/actions/devcontainer/run" + # with: + # runCmd: "./scripts/bin/infra publish cargo" + # env: | + # CARGO_REGISTRY_TOKEN=${{ secrets.CARGO_REGISTRY_TOKEN }} - name: "infra publish github-release" if: "${{ steps.runChangesets.outputs.hasChangesets == 'false' }}" diff --git a/.vscode/settings.json b/.vscode/settings.json index b737e9792..50683b7f8 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -25,6 +25,8 @@ ], "rust-analyzer.server.path": "${workspaceFolder}/scripts/bin/rust-analyzer", "search.exclude": { + // Git Submodules + "submodules/**": true, // Packages and Dependencies "**/.hermit/": true, "**/node_modules/": true, diff --git a/CHANGELOG.md b/CHANGELOG.md index 2cfbd7aef..5608328aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # changelog +## 0.18.3 + +### Patch Changes + +- [#1130](https://github.com/NomicFoundation/slang/pull/1130) [`a97b27d`](https://github.com/NomicFoundation/slang/commit/a97b27d918c9719edddbb2816db3486f43f7ec24) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - fix a bug where CST nodes are invalidated after using AST types + ## 0.18.2 ### Patch Changes diff --git a/CODEOWNERS b/CODEOWNERS index 09347588a..4cc93a008 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -1 +1,2 @@ * @NomicFoundation/slang +* @NomicFoundation/ManasSlang diff --git a/Cargo.lock b/Cargo.lock index 516d81422..769b4194f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -391,7 +391,7 @@ checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce" [[package]] name = "codegen_ebnf" -version = "0.18.2" +version = "0.18.3" dependencies = [ "Inflector", "codegen_language_definition", @@ -401,7 +401,7 @@ dependencies = [ [[package]] name = "codegen_language_definition" -version = "0.18.2" +version = "0.18.3" dependencies = [ "Inflector", "codegen_language_internal_macros", @@ -420,7 +420,7 @@ dependencies = [ [[package]] name = "codegen_language_internal_macros" -version = "0.18.2" +version = "0.18.3" dependencies = [ "itertools 0.13.0", "proc-macro2", @@ -430,14 +430,14 @@ dependencies = [ [[package]] name = "codegen_language_macros" -version = "0.18.2" +version = "0.18.3" dependencies = [ "codegen_language_definition", ] [[package]] name = "codegen_language_tests" -version = "0.18.2" +version = "0.18.3" dependencies = [ "codegen_language_definition", "codegen_language_macros", @@ -449,7 +449,7 @@ dependencies = [ [[package]] name = "codegen_runtime_cargo_crate" -version = "0.18.2" +version = "0.18.3" dependencies = [ "anyhow", "ariadne", @@ -466,7 +466,7 @@ dependencies = [ [[package]] name = "codegen_runtime_cargo_wasm" -version = "0.18.2" +version = "0.18.3" dependencies = [ "anyhow", "codegen_runtime_cargo_crate", @@ -480,7 +480,7 @@ dependencies = [ [[package]] name = "codegen_runtime_generator" -version = "0.18.2" +version = "0.18.3" dependencies = [ "Inflector", "anyhow", @@ -498,7 +498,7 @@ dependencies = [ [[package]] name = "codegen_runtime_npm_package" -version = "0.18.2" +version = "0.18.3" dependencies = [ "anyhow", "codegen_runtime_generator", @@ -507,7 +507,7 @@ dependencies = [ [[package]] name = "codegen_spec" -version = "0.18.2" +version = "0.18.3" dependencies = [ "Inflector", "anyhow", @@ -520,7 +520,7 @@ dependencies = [ [[package]] name = "codegen_testing" -version = "0.18.2" +version = "0.18.3" dependencies = [ "Inflector", "anyhow", @@ -1231,7 +1231,7 @@ checksum = "b248f5224d1d606005e02c97f5aa4e88eeb230488bcc03bc9ca4d7991399f2b5" [[package]] name = "infra_cli" -version = "0.18.2" +version = "0.18.3" dependencies = [ "anyhow", "clap", @@ -1250,7 +1250,7 @@ dependencies = [ [[package]] name = "infra_utils" -version = "0.18.2" +version = "0.18.3" dependencies = [ "Inflector", "anyhow", @@ -1397,7 +1397,7 @@ dependencies = [ [[package]] name = "metaslang_bindings" -version = "0.18.2" +version = "0.18.3" dependencies = [ "metaslang_cst", "metaslang_graph_builder", @@ -1409,7 +1409,7 @@ dependencies = [ [[package]] name = "metaslang_cst" -version = "0.18.2" +version = "0.18.3" dependencies = [ "nom", "serde", @@ -1418,7 +1418,7 @@ dependencies = [ [[package]] name = "metaslang_graph_builder" -version = "0.18.2" +version = "0.18.3" dependencies = [ "env_logger", "indoc", @@ -2204,7 +2204,7 @@ dependencies = [ [[package]] name = "slang_solidity" -version = "0.18.2" +version = "0.18.3" dependencies = [ "anyhow", "ariadne", @@ -2222,7 +2222,7 @@ dependencies = [ [[package]] name = "slang_solidity_cli" -version = "0.18.2" +version = "0.18.3" dependencies = [ "clap", "semver", @@ -2232,7 +2232,7 @@ dependencies = [ [[package]] name = "slang_testlang" -version = "0.18.2" +version = "0.18.3" dependencies = [ "anyhow", "ariadne", @@ -2275,7 +2275,7 @@ dependencies = [ [[package]] name = "solidity_cargo_tests" -version = "0.18.2" +version = "0.18.3" dependencies = [ "Inflector", "anyhow", @@ -2297,7 +2297,7 @@ dependencies = [ [[package]] name = "solidity_cargo_wasm" -version = "0.18.2" +version = "0.18.3" dependencies = [ "anyhow", "codegen_runtime_generator", @@ -2312,7 +2312,7 @@ dependencies = [ [[package]] name = "solidity_language" -version = "0.18.2" +version = "0.18.3" dependencies = [ "codegen_language_definition", "codegen_language_macros", @@ -2321,7 +2321,7 @@ dependencies = [ [[package]] name = "solidity_npm_package" -version = "0.18.2" +version = "0.18.3" dependencies = [ "anyhow", "codegen_runtime_generator", @@ -2331,7 +2331,7 @@ dependencies = [ [[package]] name = "solidity_spec" -version = "0.18.2" +version = "0.18.3" dependencies = [ "anyhow", "codegen_spec", @@ -2341,7 +2341,7 @@ dependencies = [ [[package]] name = "solidity_testing_perf" -version = "0.18.2" +version = "0.18.3" dependencies = [ "iai-callgrind", "infra_utils", @@ -2352,7 +2352,7 @@ dependencies = [ [[package]] name = "solidity_testing_sanctuary" -version = "0.18.2" +version = "0.18.3" dependencies = [ "anyhow", "clap", @@ -2372,11 +2372,11 @@ dependencies = [ [[package]] name = "solidity_testing_snapshots" -version = "0.18.2" +version = "0.18.3" [[package]] name = "solidity_testing_solc" -version = "0.18.2" +version = "0.18.3" dependencies = [ "anyhow", "ariadne", @@ -2585,7 +2585,7 @@ dependencies = [ [[package]] name = "testlang_cargo_tests" -version = "0.18.2" +version = "0.18.3" dependencies = [ "metaslang_graph_builder", "semver", @@ -2594,7 +2594,7 @@ dependencies = [ [[package]] name = "testlang_cargo_wasm" -version = "0.18.2" +version = "0.18.3" dependencies = [ "anyhow", "codegen_runtime_generator", @@ -2609,7 +2609,7 @@ dependencies = [ [[package]] name = "testlang_language" -version = "0.18.2" +version = "0.18.3" dependencies = [ "codegen_language_definition", "codegen_language_macros", @@ -2618,7 +2618,7 @@ dependencies = [ [[package]] name = "testlang_npm_package" -version = "0.18.2" +version = "0.18.3" dependencies = [ "anyhow", "codegen_runtime_generator", diff --git a/Cargo.toml b/Cargo.toml index f4760fb8e..b5a4ba712 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [workspace.package] -version = "0.18.2" +version = "0.18.3" rust-version = "1.79.0" # __RUST_STABLE_VERSION_MARKER__ (keep in sync) edition = "2021" publish = false @@ -49,42 +49,42 @@ members = [ # # Internal # -codegen_ebnf = { path = "crates/codegen/ebnf", version = "0.18.2" } -codegen_language_definition = { path = "crates/codegen/language/definition", version = "0.18.2" } -codegen_language_internal_macros = { path = "crates/codegen/language/internal_macros", version = "0.18.2" } -codegen_language_macros = { path = "crates/codegen/language/macros", version = "0.18.2" } -codegen_language_tests = { path = "crates/codegen/language/tests", version = "0.18.2" } -codegen_runtime_cargo_crate = { path = "crates/codegen/runtime/cargo/crate", version = "0.18.2" } -codegen_runtime_cargo_wasm = { path = "crates/codegen/runtime/cargo/wasm", version = "0.18.2" } -codegen_runtime_generator = { path = "crates/codegen/runtime/generator", version = "0.18.2" } -codegen_runtime_npm_package = { path = "crates/codegen/runtime/npm/package", version = "0.18.2" } -codegen_spec = { path = "crates/codegen/spec", version = "0.18.2" } -codegen_testing = { path = "crates/codegen/testing", version = "0.18.2" } +codegen_ebnf = { path = "crates/codegen/ebnf", version = "0.18.3" } +codegen_language_definition = { path = "crates/codegen/language/definition", version = "0.18.3" } +codegen_language_internal_macros = { path = "crates/codegen/language/internal_macros", version = "0.18.3" } +codegen_language_macros = { path = "crates/codegen/language/macros", version = "0.18.3" } +codegen_language_tests = { path = "crates/codegen/language/tests", version = "0.18.3" } +codegen_runtime_cargo_crate = { path = "crates/codegen/runtime/cargo/crate", version = "0.18.3" } +codegen_runtime_cargo_wasm = { path = "crates/codegen/runtime/cargo/wasm", version = "0.18.3" } +codegen_runtime_generator = { path = "crates/codegen/runtime/generator", version = "0.18.3" } +codegen_runtime_npm_package = { path = "crates/codegen/runtime/npm/package", version = "0.18.3" } +codegen_spec = { path = "crates/codegen/spec", version = "0.18.3" } +codegen_testing = { path = "crates/codegen/testing", version = "0.18.3" } -infra_cli = { path = "crates/infra/cli", version = "0.18.2" } -infra_utils = { path = "crates/infra/utils", version = "0.18.2" } +infra_cli = { path = "crates/infra/cli", version = "0.18.3" } +infra_utils = { path = "crates/infra/utils", version = "0.18.3" } -metaslang_bindings = { path = "crates/metaslang/bindings", version = "0.18.2" } -metaslang_graph_builder = { path = "crates/metaslang/graph_builder", version = "0.18.2" } -metaslang_cst = { path = "crates/metaslang/cst", version = "0.18.2" } +metaslang_bindings = { path = "crates/metaslang/bindings", version = "0.18.3" } +metaslang_graph_builder = { path = "crates/metaslang/graph_builder", version = "0.18.3" } +metaslang_cst = { path = "crates/metaslang/cst", version = "0.18.3" } -slang_solidity = { path = "crates/solidity/outputs/cargo/crate", version = "0.18.2" } -slang_solidity_cli = { path = "crates/solidity/outputs/cargo/cli", version = "0.18.2" } -solidity_cargo_tests = { path = "crates/solidity/outputs/cargo/tests", version = "0.18.2" } -solidity_cargo_wasm = { path = "crates/solidity/outputs/cargo/wasm", version = "0.18.2" } -solidity_language = { path = "crates/solidity/inputs/language", version = "0.18.2" } -solidity_npm_package = { path = "crates/solidity/outputs/npm/package", version = "0.18.2" } -solidity_spec = { path = "crates/solidity/outputs/spec", version = "0.18.2" } -solidity_testing_perf = { path = "crates/solidity/testing/perf", version = "0.18.2" } -solidity_testing_sanctuary = { path = "crates/solidity/testing/sanctuary", version = "0.18.2" } -solidity_testing_snapshots = { path = "crates/solidity/testing/snapshots", version = "0.18.2" } -solidity_testing_solc = { path = "crates/solidity/testing/solc", version = "0.18.2" } +slang_solidity = { path = "crates/solidity/outputs/cargo/crate", version = "0.18.3" } +slang_solidity_cli = { path = "crates/solidity/outputs/cargo/cli", version = "0.18.3" } +solidity_cargo_tests = { path = "crates/solidity/outputs/cargo/tests", version = "0.18.3" } +solidity_cargo_wasm = { path = "crates/solidity/outputs/cargo/wasm", version = "0.18.3" } +solidity_language = { path = "crates/solidity/inputs/language", version = "0.18.3" } +solidity_npm_package = { path = "crates/solidity/outputs/npm/package", version = "0.18.3" } +solidity_spec = { path = "crates/solidity/outputs/spec", version = "0.18.3" } +solidity_testing_perf = { path = "crates/solidity/testing/perf", version = "0.18.3" } +solidity_testing_sanctuary = { path = "crates/solidity/testing/sanctuary", version = "0.18.3" } +solidity_testing_snapshots = { path = "crates/solidity/testing/snapshots", version = "0.18.3" } +solidity_testing_solc = { path = "crates/solidity/testing/solc", version = "0.18.3" } -slang_testlang = { path = "crates/testlang/outputs/cargo/crate", version = "0.18.2" } -testlang_cargo_tests = { path = "crates/testlang/outputs/cargo/tests", version = "0.18.2" } -testlang_cargo_wasm = { path = "crates/testlang/outputs/cargo/wasm", version = "0.18.2" } -testlang_language = { path = "crates/testlang/inputs/language", version = "0.18.2" } -testlang_npm_package = { path = "crates/testlang/outputs/npm/package", version = "0.18.2" } +slang_testlang = { path = "crates/testlang/outputs/cargo/crate", version = "0.18.3" } +testlang_cargo_tests = { path = "crates/testlang/outputs/cargo/tests", version = "0.18.3" } +testlang_cargo_wasm = { path = "crates/testlang/outputs/cargo/wasm", version = "0.18.3" } +testlang_language = { path = "crates/testlang/inputs/language", version = "0.18.3" } +testlang_npm_package = { path = "crates/testlang/outputs/npm/package", version = "0.18.3" } # # External diff --git a/README.md b/README.md index 02becfa07..bfdc505e6 100644 --- a/README.md +++ b/README.md @@ -3,9 +3,12 @@ [![release](https://img.shields.io/github/v/tag/NomicFoundation/slang?label=GitHub%20Release&logo=github&sort=semver&logoColor=white)](https://github.com/NomicFoundation/slang/releases) -[![crate](https://img.shields.io/crates/v/slang_solidity?label=Rust%20Crate&logo=rust&logoColor=white)](https://crates.io/crates/slang_solidity) [![npm](https://img.shields.io/npm/v/@nomicfoundation/slang?label=NPM%20Package&logo=npm&logoColor=white)](https://www.npmjs.com/package/@nomicfoundation/slang) -[![documentation](https://img.shields.io/github/deployments/NomicFoundation/slang/github-pages?label=Documentation&logo=gitbook&logoColor=white)](https://nomicfoundation.github.io/slang) + + ## Solidity compiler tooling by [@NomicFoundation](https://github.com/NomicFoundation) @@ -14,13 +17,17 @@ Written in Rust and distributed in multiple languages. - [Announcement Post](https://medium.com/nomic-foundation-blog/slang-rethnet-2ad465fd7880) - [How to write your own Solidity linter using Slang, in 25 lines of code!](https://blog.nomic.foundation/how-to-write-your-own-solidity-linter-using-slang-356e7565ad1b/) -- [Slang Internals](https://nomicfoundation.github.io/slang/latest/internals/) +- [Slang User Guide](https://nomicfoundation.github.io/slang/latest/user-guide/) This repository maintains the source code and release process for these projects: -- [Slang Rust Crate + CLI](https://nomicfoundation.github.io/slang/latest/user-guide/rust-crate/) -- [Slang TypeScript Package](https://nomicfoundation.github.io/slang/latest/user-guide/npm-package/) - [Solidity Language Specification](https://nomicfoundation.github.io/slang/latest/solidity-specification/) +- [Slang NPM Package](https://www.npmjs.com/package/@nomicfoundation/slang/) + + > ❗ This project is still in alpha, and is under active development. > If you are planning on using it, please [reach out to us on Telegram](https://t.me/+pxApdT-Ssn5hMTFh) so we can help you get started. diff --git a/bin/.sccache-0.8.2.pkg b/bin/.sccache-0.8.2.pkg deleted file mode 120000 index 383f4511d..000000000 --- a/bin/.sccache-0.8.2.pkg +++ /dev/null @@ -1 +0,0 @@ -hermit \ No newline at end of file diff --git a/bin/hermit.hcl b/bin/hermit.hcl index 6f02e0834..aed687281 100644 --- a/bin/hermit.hcl +++ b/bin/hermit.hcl @@ -7,8 +7,6 @@ env = { "RUST_BACKTRACE": "full", "RUST_STABLE_VERSION": "1.79.0", // __RUST_STABLE_VERSION_MARKER__ (keep in sync) "RUST_NIGHTLY_VERSION": "nightly-2024-06-17", // __RUST_NIGHTLY_VERSION_MARKER__ (keep in sync) - "RUSTC_WRAPPER": "${HERMIT_ENV}/bin/sccache", - "SCCACHE_DIR": "${HERMIT_ENV}/.hermit/sccache", // TypeScript: "TS_NODE_PROJECT": "${HERMIT_ENV}/tsconfig.json", diff --git a/bin/sccache b/bin/sccache deleted file mode 120000 index eb49133b0..000000000 --- a/bin/sccache +++ /dev/null @@ -1 +0,0 @@ -.sccache-0.8.2.pkg \ No newline at end of file diff --git a/crates/codegen/runtime/cargo/wasm/src/runtime/interface/ast.wit.jinja2 b/crates/codegen/runtime/cargo/wasm/src/runtime/interface/ast.wit.jinja2 index 2aceef75c..7a63444bd 100644 --- a/crates/codegen/runtime/cargo/wasm/src/runtime/interface/ast.wit.jinja2 +++ b/crates/codegen/runtime/cargo/wasm/src/runtime/interface/ast.wit.jinja2 @@ -2,9 +2,9 @@ interface ast { use cst.{node, nonterminal-node}; resource selectors { - sequence: static func(node: nonterminal-node) -> result>, string>; - choice: static func(node: nonterminal-node) -> result; - repeated: static func(node: nonterminal-node) -> result, string>; - separated: static func(node: nonterminal-node) -> result>, string>; + sequence: static func(node: borrow) -> result>, string>; + choice: static func(node: borrow) -> result; + repeated: static func(node: borrow) -> result, string>; + separated: static func(node: borrow) -> result>, string>; } } diff --git a/crates/codegen/runtime/cargo/wasm/src/runtime/interface/generated/ast.wit b/crates/codegen/runtime/cargo/wasm/src/runtime/interface/generated/ast.wit index 31c6a91f8..16ed17103 100644 --- a/crates/codegen/runtime/cargo/wasm/src/runtime/interface/generated/ast.wit +++ b/crates/codegen/runtime/cargo/wasm/src/runtime/interface/generated/ast.wit @@ -4,9 +4,9 @@ interface ast { use cst.{node, nonterminal-node}; resource selectors { - sequence: static func(node: nonterminal-node) -> result>, string>; - choice: static func(node: nonterminal-node) -> result; - repeated: static func(node: nonterminal-node) -> result, string>; - separated: static func(node: nonterminal-node) -> result>, string>; + sequence: static func(node: borrow) -> result>, string>; + choice: static func(node: borrow) -> result; + repeated: static func(node: borrow) -> result, string>; + separated: static func(node: borrow) -> result>, string>; } } diff --git a/crates/codegen/runtime/cargo/wasm/src/runtime/wrappers/ast/mod.rs b/crates/codegen/runtime/cargo/wasm/src/runtime/wrappers/ast/mod.rs index 1a4b3c6ee..10b4fb6b8 100644 --- a/crates/codegen/runtime/cargo/wasm/src/runtime/wrappers/ast/mod.rs +++ b/crates/codegen/runtime/cargo/wasm/src/runtime/wrappers/ast/mod.rs @@ -8,7 +8,7 @@ mod ffi { Guest, GuestSelectors, }; pub use crate::wasm_crate::bindings::exports::nomic_foundation::slang::cst::{ - Node, NonterminalNode, + Node, NonterminalNodeBorrow, }; } @@ -27,25 +27,25 @@ impl ffi::Guest for crate::wasm_crate::World { pub struct SelectorsWrapper; impl ffi::GuestSelectors for SelectorsWrapper { - fn sequence(node: ffi::NonterminalNode) -> Result>, String> { + fn sequence(node: ffi::NonterminalNodeBorrow<'_>) -> Result>, String> { Ok(selectors::select_sequence(node._borrow_ffi())? .into_iter() .map(|opt| opt.map(|node| node._into_ffi())) .collect()) } - fn choice(node: ffi::NonterminalNode) -> Result { + fn choice(node: ffi::NonterminalNodeBorrow<'_>) -> Result { Ok(selectors::select_choice(node._borrow_ffi())?._into_ffi()) } - fn repeated(node: ffi::NonterminalNode) -> Result, String> { + fn repeated(node: ffi::NonterminalNodeBorrow<'_>) -> Result, String> { Ok(selectors::select_repeated(node._borrow_ffi())? .into_iter() .map(|node| node._into_ffi()) .collect()) } - fn separated(node: ffi::NonterminalNode) -> Result>, String> { + fn separated(node: ffi::NonterminalNodeBorrow<'_>) -> Result>, String> { Ok(selectors::select_separated(node._borrow_ffi())? .into_iter() .map(|vec| vec.into_iter().map(|node| node._into_ffi()).collect()) diff --git a/crates/codegen/runtime/npm/package/CHANGELOG.md b/crates/codegen/runtime/npm/package/CHANGELOG.md index 2cfbd7aef..5608328aa 100644 --- a/crates/codegen/runtime/npm/package/CHANGELOG.md +++ b/crates/codegen/runtime/npm/package/CHANGELOG.md @@ -1,5 +1,11 @@ # changelog +## 0.18.3 + +### Patch Changes + +- [#1130](https://github.com/NomicFoundation/slang/pull/1130) [`a97b27d`](https://github.com/NomicFoundation/slang/commit/a97b27d918c9719edddbb2816db3486f43f7ec24) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - fix a bug where CST nodes are invalidated after using AST types + ## 0.18.2 ### Patch Changes diff --git a/crates/infra/cli/src/commands/perf/benchmark/mod.rs b/crates/infra/cli/src/commands/perf/benchmark/mod.rs index ac661e62d..a832c029f 100644 --- a/crates/infra/cli/src/commands/perf/benchmark/mod.rs +++ b/crates/infra/cli/src/commands/perf/benchmark/mod.rs @@ -77,7 +77,7 @@ impl BenchmarkController { .property("--project", "slang") .property("--adapter", "rust_iai_callgrind") .property("--testbed", testbed) - .env("BENCHER_API_TOKEN", token); + .secret("BENCHER_API_TOKEN", token); if dry_run { command = command.flag("--dry-run"); diff --git a/crates/infra/cli/src/commands/publish/cargo/mod.rs b/crates/infra/cli/src/commands/publish/cargo/mod.rs index 189296eeb..e1d3ddfdb 100644 --- a/crates/infra/cli/src/commands/publish/cargo/mod.rs +++ b/crates/infra/cli/src/commands/publish/cargo/mod.rs @@ -1,7 +1,7 @@ use std::iter::once; use std::path::Path; -use anyhow::Result; +use anyhow::{ensure, Result}; use clap::Parser; use infra_utils::cargo::{CargoWorkspace, UserFacingCrate}; use infra_utils::commands::Command; @@ -20,6 +20,11 @@ pub struct CargoController { impl CargoController { pub fn execute(&self) -> Result<()> { + ensure!( + false, + "__SLANG_CARGO_PUBLISH_TEMPORARILY_DISABLED__ (keep in sync)" + ); + let mut changeset = TemporaryChangeset::new( "infra/cargo-publish", "prepare Cargo packages for publishing", diff --git a/crates/infra/utils/src/cargo/workspace.rs b/crates/infra/utils/src/cargo/workspace.rs index ef56bc801..ca3249f30 100644 --- a/crates/infra/utils/src/cargo/workspace.rs +++ b/crates/infra/utils/src/cargo/workspace.rs @@ -145,5 +145,7 @@ impl CargoWorkspaceCommands for Command { .unwrap(), ), ) + // Print extra logs when build cache is invalidated: + .env("CARGO_LOG", "cargo::core::compiler::fingerprint=info") } } diff --git a/crates/infra/utils/src/commands/mod.rs b/crates/infra/utils/src/commands/mod.rs index f76200771..6ab35ec9c 100644 --- a/crates/infra/utils/src/commands/mod.rs +++ b/crates/infra/utils/src/commands/mod.rs @@ -17,7 +17,10 @@ use crate::paths::{PathExtensions, PrivatePathExtensions}; pub struct Command { name: String, args: Vec, + environment: HashMap, + secrets: HashMap, + current_dir: Option, } @@ -27,7 +30,10 @@ impl Command { Self { name: name.into(), args: vec![], + environment: HashMap::new(), + secrets: HashMap::new(), + current_dir: None, } } @@ -70,6 +76,13 @@ impl Command { self } + #[must_use] + pub fn secret(mut self, key: impl Into, value: impl Into) -> Self { + self.secrets.insert(key.into(), value.into()); + + self + } + #[must_use] pub fn current_dir(mut self, current_dir: impl Into) -> Self { let current_dir = current_dir.into(); @@ -155,6 +168,7 @@ fn spawn_with_defaults(command: &Command, stdio: impl Fn() -> Stdio) -> Result -[![release](https://img.shields.io/github/v/tag/NomicFoundation/slang?label=GitHub%20Release&logo=github&sort=semver&logoColor=white)](https://github.com/NomicFoundation/slang/releases) -[![crate](https://img.shields.io/crates/v/metaslang_bindings?label=Rust%20Crate&logo=rust&logoColor=white)](https://crates.io/crates/metaslang_bindings) - ## Solidity compiler tooling by [@NomicFoundation](https://github.com/NomicFoundation) A modular set of compiler APIs empowering the next generation of Solidity code analysis and developer tooling. @@ -12,7 +9,7 @@ Written in Rust and distributed in multiple languages. - [Announcement Post](https://medium.com/nomic-foundation-blog/slang-rethnet-2ad465fd7880) - [How to write your own Solidity linter using Slang, in 25 lines of code!](https://blog.nomic.foundation/how-to-write-your-own-solidity-linter-using-slang-356e7565ad1b/) -- [User Guide](https://nomicfoundation.github.io/slang/latest/user-guide/rust-crate/) +- [Slang User Guide](https://nomicfoundation.github.io/slang/latest/user-guide/) > ❗ This project is still in alpha, and is under active development. > If you are planning on using it, please [reach out to us on Telegram](https://t.me/+pxApdT-Ssn5hMTFh) so we can help you get started. diff --git a/crates/metaslang/cst/CHANGELOG.md b/crates/metaslang/cst/CHANGELOG.md index 2cfbd7aef..5608328aa 100644 --- a/crates/metaslang/cst/CHANGELOG.md +++ b/crates/metaslang/cst/CHANGELOG.md @@ -1,5 +1,11 @@ # changelog +## 0.18.3 + +### Patch Changes + +- [#1130](https://github.com/NomicFoundation/slang/pull/1130) [`a97b27d`](https://github.com/NomicFoundation/slang/commit/a97b27d918c9719edddbb2816db3486f43f7ec24) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - fix a bug where CST nodes are invalidated after using AST types + ## 0.18.2 ### Patch Changes diff --git a/crates/metaslang/cst/Cargo.toml b/crates/metaslang/cst/Cargo.toml index 9adecf73e..be86cca81 100644 --- a/crates/metaslang/cst/Cargo.toml +++ b/crates/metaslang/cst/Cargo.toml @@ -2,7 +2,8 @@ version.workspace = true rust-version.workspace = true edition.workspace = true -publish = true +# __SLANG_CARGO_PUBLISH_TEMPORARILY_DISABLED__ (keep in sync) +# publish = true name = "metaslang_cst" description = "A generic library for building, navigating and querying concrete syntax trees." diff --git a/crates/metaslang/cst/README.md b/crates/metaslang/cst/README.md index 700a274f4..ea33a49bf 100644 --- a/crates/metaslang/cst/README.md +++ b/crates/metaslang/cst/README.md @@ -2,9 +2,6 @@ -[![release](https://img.shields.io/github/v/tag/NomicFoundation/slang?label=GitHub%20Release&logo=github&sort=semver&logoColor=white)](https://github.com/NomicFoundation/slang/releases) -[![crate](https://img.shields.io/crates/v/metaslang_cst?label=Rust%20Crate&logo=rust&logoColor=white)](https://crates.io/crates/metaslang_cst) - ## Solidity compiler tooling by [@NomicFoundation](https://github.com/NomicFoundation) A modular set of compiler APIs empowering the next generation of Solidity code analysis and developer tooling. @@ -12,7 +9,7 @@ Written in Rust and distributed in multiple languages. - [Announcement Post](https://medium.com/nomic-foundation-blog/slang-rethnet-2ad465fd7880) - [How to write your own Solidity linter using Slang, in 25 lines of code!](https://blog.nomic.foundation/how-to-write-your-own-solidity-linter-using-slang-356e7565ad1b/) -- [User Guide](https://nomicfoundation.github.io/slang/latest/user-guide/rust-crate/) +- [Slang User Guide](https://nomicfoundation.github.io/slang/latest/user-guide/) > ❗ This project is still in alpha, and is under active development. > If you are planning on using it, please [reach out to us on Telegram](https://t.me/+pxApdT-Ssn5hMTFh) so we can help you get started. diff --git a/crates/metaslang/cst/src/query/engine.rs b/crates/metaslang/cst/src/query/engine.rs index 3daff200f..b758f438c 100644 --- a/crates/metaslang/cst/src/query/engine.rs +++ b/crates/metaslang/cst/src/query/engine.rs @@ -668,8 +668,16 @@ impl Matcher for OneOrMoreMatcher { } else { let tail = self.children.last_mut().unwrap(); if let Some(child_matcher_result) = tail.next() { - if !child_matcher_result.cursor.is_completed() { - self.result_for_next_repetition = Some(child_matcher_result.clone()); + // Skip over trivia before saving the result for next repetition + let mut cursor = child_matcher_result.cursor.clone(); + while !cursor.is_completed() && cursor.node().is_trivia() { + cursor.irrevocably_go_to_next_sibling(); + } + if !cursor.is_completed() { + self.result_for_next_repetition = Some(MatcherResult { + cursor, + ..child_matcher_result + }); } return Some(child_matcher_result); } diff --git a/crates/metaslang/graph_builder/CHANGELOG.md b/crates/metaslang/graph_builder/CHANGELOG.md index 2cfbd7aef..5608328aa 100644 --- a/crates/metaslang/graph_builder/CHANGELOG.md +++ b/crates/metaslang/graph_builder/CHANGELOG.md @@ -1,5 +1,11 @@ # changelog +## 0.18.3 + +### Patch Changes + +- [#1130](https://github.com/NomicFoundation/slang/pull/1130) [`a97b27d`](https://github.com/NomicFoundation/slang/commit/a97b27d918c9719edddbb2816db3486f43f7ec24) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - fix a bug where CST nodes are invalidated after using AST types + ## 0.18.2 ### Patch Changes diff --git a/crates/metaslang/graph_builder/Cargo.toml b/crates/metaslang/graph_builder/Cargo.toml index 0626da23a..c1d47a2f3 100644 --- a/crates/metaslang/graph_builder/Cargo.toml +++ b/crates/metaslang/graph_builder/Cargo.toml @@ -2,7 +2,8 @@ version.workspace = true rust-version.workspace = true edition.workspace = true -publish = true +# __SLANG_CARGO_PUBLISH_TEMPORARILY_DISABLED__ (keep in sync) +# publish = true name = "metaslang_graph_builder" description = "Construct graphs from parsed source code" diff --git a/crates/metaslang/graph_builder/README.md b/crates/metaslang/graph_builder/README.md index ab243861b..b02df04b6 100644 --- a/crates/metaslang/graph_builder/README.md +++ b/crates/metaslang/graph_builder/README.md @@ -2,9 +2,6 @@ -[![release](https://img.shields.io/github/v/tag/NomicFoundation/slang?label=GitHub%20Release&logo=github&sort=semver&logoColor=white)](https://github.com/NomicFoundation/slang/releases) -[![crate](https://img.shields.io/crates/v/metaslang_graph_builder?label=Rust%20Crate&logo=rust&logoColor=white)](https://crates.io/crates/metaslang_graph_builder) - ## Solidity compiler tooling by [@NomicFoundation](https://github.com/NomicFoundation) A modular set of compiler APIs empowering the next generation of Solidity code analysis and developer tooling. @@ -12,7 +9,7 @@ Written in Rust and distributed in multiple languages. - [Announcement Post](https://medium.com/nomic-foundation-blog/slang-rethnet-2ad465fd7880) - [How to write your own Solidity linter using Slang, in 25 lines of code!](https://blog.nomic.foundation/how-to-write-your-own-solidity-linter-using-slang-356e7565ad1b/) -- [User Guide](https://nomicfoundation.github.io/slang/latest/user-guide/rust-crate/) +- [Slang User Guide](https://nomicfoundation.github.io/slang/latest/user-guide/) > ❗ This project is still in alpha, and is under active development. > If you are planning on using it, please [reach out to us on Telegram](https://t.me/+pxApdT-Ssn5hMTFh) so we can help you get started. diff --git a/crates/solidity/outputs/cargo/cli/CHANGELOG.md b/crates/solidity/outputs/cargo/cli/CHANGELOG.md index 2cfbd7aef..5608328aa 100644 --- a/crates/solidity/outputs/cargo/cli/CHANGELOG.md +++ b/crates/solidity/outputs/cargo/cli/CHANGELOG.md @@ -1,5 +1,11 @@ # changelog +## 0.18.3 + +### Patch Changes + +- [#1130](https://github.com/NomicFoundation/slang/pull/1130) [`a97b27d`](https://github.com/NomicFoundation/slang/commit/a97b27d918c9719edddbb2816db3486f43f7ec24) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - fix a bug where CST nodes are invalidated after using AST types + ## 0.18.2 ### Patch Changes diff --git a/crates/solidity/outputs/cargo/cli/Cargo.toml b/crates/solidity/outputs/cargo/cli/Cargo.toml index b3249b251..2e94f8d4d 100644 --- a/crates/solidity/outputs/cargo/cli/Cargo.toml +++ b/crates/solidity/outputs/cargo/cli/Cargo.toml @@ -2,7 +2,8 @@ version.workspace = true rust-version.workspace = true edition.workspace = true -publish = true +# __SLANG_CARGO_PUBLISH_TEMPORARILY_DISABLED__ (keep in sync) +# publish = true name = "slang_solidity_cli" description = "This crate contains the 'slang_solidity' CLI/cargo binary. Please see the 'slang_solidity' crate for more information." diff --git a/crates/solidity/outputs/cargo/cli/README.md b/crates/solidity/outputs/cargo/cli/README.md index 36b4fe6a9..2b57193d2 100644 --- a/crates/solidity/outputs/cargo/cli/README.md +++ b/crates/solidity/outputs/cargo/cli/README.md @@ -2,9 +2,6 @@ -[![release](https://img.shields.io/github/v/tag/NomicFoundation/slang?label=GitHub%20Release&logo=github&sort=semver&logoColor=white)](https://github.com/NomicFoundation/slang/releases) -[![crate](https://img.shields.io/crates/v/slang_solidity_cli?label=Rust%20Crate&logo=rust&logoColor=white)](https://crates.io/crates/slang_solidity_cli) - ## Solidity compiler tooling by [@NomicFoundation](https://github.com/NomicFoundation) A modular set of compiler APIs empowering the next generation of Solidity code analysis and developer tooling. @@ -12,7 +9,7 @@ Written in Rust and distributed in multiple languages. - [Announcement Post](https://medium.com/nomic-foundation-blog/slang-rethnet-2ad465fd7880) - [How to write your own Solidity linter using Slang, in 25 lines of code!](https://blog.nomic.foundation/how-to-write-your-own-solidity-linter-using-slang-356e7565ad1b/) -- [User Guide](https://nomicfoundation.github.io/slang/latest/user-guide/rust-crate/) +- [Slang User Guide](https://nomicfoundation.github.io/slang/latest/user-guide/) > ❗ This project is still in alpha, and is under active development. > If you are planning on using it, please [reach out to us on Telegram](https://t.me/+pxApdT-Ssn5hMTFh) so we can help you get started. diff --git a/crates/solidity/outputs/cargo/crate/CHANGELOG.md b/crates/solidity/outputs/cargo/crate/CHANGELOG.md index 2cfbd7aef..5608328aa 100644 --- a/crates/solidity/outputs/cargo/crate/CHANGELOG.md +++ b/crates/solidity/outputs/cargo/crate/CHANGELOG.md @@ -1,5 +1,11 @@ # changelog +## 0.18.3 + +### Patch Changes + +- [#1130](https://github.com/NomicFoundation/slang/pull/1130) [`a97b27d`](https://github.com/NomicFoundation/slang/commit/a97b27d918c9719edddbb2816db3486f43f7ec24) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - fix a bug where CST nodes are invalidated after using AST types + ## 0.18.2 ### Patch Changes diff --git a/crates/solidity/outputs/cargo/crate/Cargo.toml b/crates/solidity/outputs/cargo/crate/Cargo.toml index 9aa011fa5..3519125a2 100644 --- a/crates/solidity/outputs/cargo/crate/Cargo.toml +++ b/crates/solidity/outputs/cargo/crate/Cargo.toml @@ -2,7 +2,8 @@ version.workspace = true rust-version.workspace = true edition.workspace = true -publish = true +# __SLANG_CARGO_PUBLISH_TEMPORARILY_DISABLED__ (keep in sync) +# publish = true name = "slang_solidity" description = "A modular set of compiler APIs empowering the next generation of Solidity code analysis and developer tooling. Written in Rust and distributed in multiple languages." diff --git a/crates/solidity/outputs/cargo/crate/README.md b/crates/solidity/outputs/cargo/crate/README.md index 4f133f53d..6641f3cb6 100644 --- a/crates/solidity/outputs/cargo/crate/README.md +++ b/crates/solidity/outputs/cargo/crate/README.md @@ -2,11 +2,6 @@ -[![release](https://img.shields.io/github/v/tag/NomicFoundation/slang?label=GitHub%20Release&logo=github&sort=semver&logoColor=white)](https://github.com/NomicFoundation/slang/releases) -[![crate](https://img.shields.io/crates/v/slang_solidity?label=Rust%20Crate&logo=rust&logoColor=white)](https://crates.io/crates/slang_solidity) -[![npm](https://img.shields.io/npm/v/@nomicfoundation/slang?label=NPM%20Package&logo=npm&logoColor=white)](https://www.npmjs.com/package/@nomicfoundation/slang) -[![documentation](https://img.shields.io/github/deployments/NomicFoundation/slang/github-pages?label=Documentation&logo=gitbook&logoColor=white)](https://nomicfoundation.github.io/slang) - ## Solidity compiler tooling by [@NomicFoundation](https://github.com/NomicFoundation) A modular set of compiler APIs empowering the next generation of Solidity code analysis and developer tooling. @@ -14,7 +9,7 @@ Written in Rust and distributed in multiple languages. - [Announcement Post](https://medium.com/nomic-foundation-blog/slang-rethnet-2ad465fd7880) - [How to write your own Solidity linter using Slang, in 25 lines of code!](https://blog.nomic.foundation/how-to-write-your-own-solidity-linter-using-slang-356e7565ad1b/) -- [User Guide](https://nomicfoundation.github.io/slang/latest/user-guide/rust-crate/) +- [Slang User Guide](https://nomicfoundation.github.io/slang/latest/user-guide/) > ❗ This project is still in alpha, and is under active development. > If you are planning on using it, please [reach out to us on Telegram](https://t.me/+pxApdT-Ssn5hMTFh) so we can help you get started. diff --git a/crates/solidity/outputs/cargo/wasm/src/generated/interface/generated/ast.wit b/crates/solidity/outputs/cargo/wasm/src/generated/interface/generated/ast.wit index 31c6a91f8..16ed17103 100644 --- a/crates/solidity/outputs/cargo/wasm/src/generated/interface/generated/ast.wit +++ b/crates/solidity/outputs/cargo/wasm/src/generated/interface/generated/ast.wit @@ -4,9 +4,9 @@ interface ast { use cst.{node, nonterminal-node}; resource selectors { - sequence: static func(node: nonterminal-node) -> result>, string>; - choice: static func(node: nonterminal-node) -> result; - repeated: static func(node: nonterminal-node) -> result, string>; - separated: static func(node: nonterminal-node) -> result>, string>; + sequence: static func(node: borrow) -> result>, string>; + choice: static func(node: borrow) -> result; + repeated: static func(node: borrow) -> result, string>; + separated: static func(node: borrow) -> result>, string>; } } diff --git a/crates/solidity/outputs/cargo/wasm/src/generated/wrappers/ast/mod.rs b/crates/solidity/outputs/cargo/wasm/src/generated/wrappers/ast/mod.rs index 5b262a178..cf50ecacd 100644 --- a/crates/solidity/outputs/cargo/wasm/src/generated/wrappers/ast/mod.rs +++ b/crates/solidity/outputs/cargo/wasm/src/generated/wrappers/ast/mod.rs @@ -10,7 +10,7 @@ mod ffi { Guest, GuestSelectors, }; pub use crate::wasm_crate::bindings::exports::nomic_foundation::slang::cst::{ - Node, NonterminalNode, + Node, NonterminalNodeBorrow, }; } @@ -29,25 +29,25 @@ impl ffi::Guest for crate::wasm_crate::World { pub struct SelectorsWrapper; impl ffi::GuestSelectors for SelectorsWrapper { - fn sequence(node: ffi::NonterminalNode) -> Result>, String> { + fn sequence(node: ffi::NonterminalNodeBorrow<'_>) -> Result>, String> { Ok(selectors::select_sequence(node._borrow_ffi())? .into_iter() .map(|opt| opt.map(|node| node._into_ffi())) .collect()) } - fn choice(node: ffi::NonterminalNode) -> Result { + fn choice(node: ffi::NonterminalNodeBorrow<'_>) -> Result { Ok(selectors::select_choice(node._borrow_ffi())?._into_ffi()) } - fn repeated(node: ffi::NonterminalNode) -> Result, String> { + fn repeated(node: ffi::NonterminalNodeBorrow<'_>) -> Result, String> { Ok(selectors::select_repeated(node._borrow_ffi())? .into_iter() .map(|node| node._into_ffi()) .collect()) } - fn separated(node: ffi::NonterminalNode) -> Result>, String> { + fn separated(node: ffi::NonterminalNodeBorrow<'_>) -> Result>, String> { Ok(selectors::select_separated(node._borrow_ffi())? .into_iter() .map(|vec| vec.into_iter().map(|node| node._into_ffi()).collect()) diff --git a/crates/solidity/outputs/npm/package/CHANGELOG.md b/crates/solidity/outputs/npm/package/CHANGELOG.md index 2cfbd7aef..5608328aa 100644 --- a/crates/solidity/outputs/npm/package/CHANGELOG.md +++ b/crates/solidity/outputs/npm/package/CHANGELOG.md @@ -1,5 +1,11 @@ # changelog +## 0.18.3 + +### Patch Changes + +- [#1130](https://github.com/NomicFoundation/slang/pull/1130) [`a97b27d`](https://github.com/NomicFoundation/slang/commit/a97b27d918c9719edddbb2816db3486f43f7ec24) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - fix a bug where CST nodes are invalidated after using AST types + ## 0.18.2 ### Patch Changes diff --git a/crates/solidity/outputs/npm/package/README.md b/crates/solidity/outputs/npm/package/README.md index bf40d9068..ddca92fb4 100644 --- a/crates/solidity/outputs/npm/package/README.md +++ b/crates/solidity/outputs/npm/package/README.md @@ -2,11 +2,6 @@ -[![release](https://img.shields.io/github/v/tag/NomicFoundation/slang?label=GitHub%20Release&logo=github&sort=semver&logoColor=white)](https://github.com/NomicFoundation/slang/releases) -[![crate](https://img.shields.io/crates/v/slang_solidity?label=Rust%20Crate&logo=rust&logoColor=white)](https://crates.io/crates/slang_solidity) -[![npm](https://img.shields.io/npm/v/@nomicfoundation/slang?label=NPM%20Package&logo=npm&logoColor=white)](https://www.npmjs.com/package/@nomicfoundation/slang) -[![documentation](https://img.shields.io/github/deployments/NomicFoundation/slang/github-pages?label=Documentation&logo=gitbook&logoColor=white)](https://nomicfoundation.github.io/slang) - ## Solidity compiler tooling by [@NomicFoundation](https://github.com/NomicFoundation) A modular set of compiler APIs empowering the next generation of Solidity code analysis and developer tooling. @@ -14,7 +9,7 @@ Written in Rust and distributed in multiple languages. - [Announcement Post](https://medium.com/nomic-foundation-blog/slang-rethnet-2ad465fd7880) - [How to write your own Solidity linter using Slang, in 25 lines of code!](https://blog.nomic.foundation/how-to-write-your-own-solidity-linter-using-slang-356e7565ad1b/) -- [User Guide](https://nomicfoundation.github.io/slang/latest/user-guide/npm-package/) +- [Slang User Guide](https://nomicfoundation.github.io/slang/latest/user-guide/) > ❗ This project is still in alpha, and is under active development. > If you are planning on using it, please [reach out to us on Telegram](https://t.me/+pxApdT-Ssn5hMTFh) so we can help you get started. diff --git a/crates/solidity/outputs/npm/package/package.json b/crates/solidity/outputs/npm/package/package.json index 313f77898..a0d800dfc 100644 --- a/crates/solidity/outputs/npm/package/package.json +++ b/crates/solidity/outputs/npm/package/package.json @@ -1,6 +1,6 @@ { "name": "@nomicfoundation/slang", - "version": "0.18.2", + "version": "0.18.3", "type": "module", "description": "A modular set of compiler APIs empowering the next generation of Solidity code analysis and developer tooling. Written in Rust and distributed in multiple languages.", "homepage": "https://nomicfoundation.github.io/slang/", diff --git a/crates/solidity/outputs/npm/tests/jest.config.ts b/crates/solidity/outputs/npm/tests/jest.config.ts deleted file mode 100644 index ec6aa264d..000000000 --- a/crates/solidity/outputs/npm/tests/jest.config.ts +++ /dev/null @@ -1,17 +0,0 @@ -import type { Config } from "jest"; - -const config: Config = { - testMatch: ["/src/doc-examples/**/*.mts"], - - preset: "ts-jest/presets/default-esm", - resolver: "ts-jest-resolver", - moduleFileExtensions: ["js", "mjs", "cjs", "jsx", "ts", "mts", "cts", "tsx", "json", "node"], - - cacheDirectory: "/target/jest/cache", - slowTestThreshold: 5, - - clearMocks: true, - resetMocks: true, -}; - -export default config; diff --git a/crates/solidity/outputs/npm/tests/src/doc-examples/using-queries.mts b/crates/solidity/outputs/npm/tests/src/doc-examples/using-queries.test.mts similarity index 100% rename from crates/solidity/outputs/npm/tests/src/doc-examples/using-queries.mts rename to crates/solidity/outputs/npm/tests/src/doc-examples/using-queries.test.mts diff --git a/crates/solidity/outputs/npm/tests/src/doc-examples/using-the-ast.mts b/crates/solidity/outputs/npm/tests/src/doc-examples/using-the-ast.test.mts similarity index 100% rename from crates/solidity/outputs/npm/tests/src/doc-examples/using-the-ast.mts rename to crates/solidity/outputs/npm/tests/src/doc-examples/using-the-ast.test.mts diff --git a/crates/solidity/outputs/npm/tests/src/doc-examples/using-the-cursor.mts b/crates/solidity/outputs/npm/tests/src/doc-examples/using-the-cursor.test.mts similarity index 100% rename from crates/solidity/outputs/npm/tests/src/doc-examples/using-the-cursor.mts rename to crates/solidity/outputs/npm/tests/src/doc-examples/using-the-cursor.test.mts diff --git a/crates/solidity/outputs/npm/tests/src/doc-examples/using-the-parser.mts b/crates/solidity/outputs/npm/tests/src/doc-examples/using-the-parser.test.mts similarity index 100% rename from crates/solidity/outputs/npm/tests/src/doc-examples/using-the-parser.mts rename to crates/solidity/outputs/npm/tests/src/doc-examples/using-the-parser.test.mts diff --git a/crates/testlang/outputs/cargo/tests/src/query/engine_tests.rs b/crates/testlang/outputs/cargo/tests/src/query/engine_tests.rs index 5a1e78037..c04638136 100644 --- a/crates/testlang/outputs/cargo/tests/src/query/engine_tests.rs +++ b/crates/testlang/outputs/cargo/tests/src/query/engine_tests.rs @@ -267,6 +267,42 @@ fn test_one_or_more() { ); } +#[test] +fn test_one_or_more_anonymous() { + run_query_test( + &common_test_tree(), + "[TreeNode (@x [_])+ .]", + query_matches! { + {x: ["A", "B", "C", "DE"]} + {x: ["B", "C", "DE"]} + {x: ["C", "DE"]} + {x: ["DE"]} + }, + ); +} + +#[test] +fn test_one_or_more_anonymous_both_adjacent() { + run_query_test( + &common_test_tree(), + "[TreeNode . (@x [_])+ .]", + query_matches! { + {x: ["A", "B", "C", "DE"]} + }, + ); +} + +#[test] +fn test_one_or_more_anonymous_both_adjacent_with_trivia() { + run_query_test( + &common_test_tree_with_trivia(), + "[TreeNodeChild . @children [_]+ .]", + query_matches! { + {children: ["D", "E"]} + }, + ); +} + #[test] fn test_zero_or_more() { run_query_test( diff --git a/crates/testlang/outputs/cargo/wasm/src/generated/interface/generated/ast.wit b/crates/testlang/outputs/cargo/wasm/src/generated/interface/generated/ast.wit index 31c6a91f8..16ed17103 100644 --- a/crates/testlang/outputs/cargo/wasm/src/generated/interface/generated/ast.wit +++ b/crates/testlang/outputs/cargo/wasm/src/generated/interface/generated/ast.wit @@ -4,9 +4,9 @@ interface ast { use cst.{node, nonterminal-node}; resource selectors { - sequence: static func(node: nonterminal-node) -> result>, string>; - choice: static func(node: nonterminal-node) -> result; - repeated: static func(node: nonterminal-node) -> result, string>; - separated: static func(node: nonterminal-node) -> result>, string>; + sequence: static func(node: borrow) -> result>, string>; + choice: static func(node: borrow) -> result; + repeated: static func(node: borrow) -> result, string>; + separated: static func(node: borrow) -> result>, string>; } } diff --git a/crates/testlang/outputs/cargo/wasm/src/generated/wrappers/ast/mod.rs b/crates/testlang/outputs/cargo/wasm/src/generated/wrappers/ast/mod.rs index 5b262a178..cf50ecacd 100644 --- a/crates/testlang/outputs/cargo/wasm/src/generated/wrappers/ast/mod.rs +++ b/crates/testlang/outputs/cargo/wasm/src/generated/wrappers/ast/mod.rs @@ -10,7 +10,7 @@ mod ffi { Guest, GuestSelectors, }; pub use crate::wasm_crate::bindings::exports::nomic_foundation::slang::cst::{ - Node, NonterminalNode, + Node, NonterminalNodeBorrow, }; } @@ -29,25 +29,25 @@ impl ffi::Guest for crate::wasm_crate::World { pub struct SelectorsWrapper; impl ffi::GuestSelectors for SelectorsWrapper { - fn sequence(node: ffi::NonterminalNode) -> Result>, String> { + fn sequence(node: ffi::NonterminalNodeBorrow<'_>) -> Result>, String> { Ok(selectors::select_sequence(node._borrow_ffi())? .into_iter() .map(|opt| opt.map(|node| node._into_ffi())) .collect()) } - fn choice(node: ffi::NonterminalNode) -> Result { + fn choice(node: ffi::NonterminalNodeBorrow<'_>) -> Result { Ok(selectors::select_choice(node._borrow_ffi())?._into_ffi()) } - fn repeated(node: ffi::NonterminalNode) -> Result, String> { + fn repeated(node: ffi::NonterminalNodeBorrow<'_>) -> Result, String> { Ok(selectors::select_repeated(node._borrow_ffi())? .into_iter() .map(|node| node._into_ffi()) .collect()) } - fn separated(node: ffi::NonterminalNode) -> Result>, String> { + fn separated(node: ffi::NonterminalNodeBorrow<'_>) -> Result>, String> { Ok(selectors::select_separated(node._borrow_ffi())? .into_iter() .map(|vec| vec.into_iter().map(|node| node._into_ffi()).collect()) diff --git a/crates/testlang/outputs/npm/package/CHANGELOG.md b/crates/testlang/outputs/npm/package/CHANGELOG.md index 2cfbd7aef..5608328aa 100644 --- a/crates/testlang/outputs/npm/package/CHANGELOG.md +++ b/crates/testlang/outputs/npm/package/CHANGELOG.md @@ -1,5 +1,11 @@ # changelog +## 0.18.3 + +### Patch Changes + +- [#1130](https://github.com/NomicFoundation/slang/pull/1130) [`a97b27d`](https://github.com/NomicFoundation/slang/commit/a97b27d918c9719edddbb2816db3486f43f7ec24) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - fix a bug where CST nodes are invalidated after using AST types + ## 0.18.2 ### Patch Changes diff --git a/crates/testlang/outputs/npm/tests/jest.config.ts b/crates/testlang/outputs/npm/tests/jest.config.ts deleted file mode 100644 index 8cd86e9f3..000000000 --- a/crates/testlang/outputs/npm/tests/jest.config.ts +++ /dev/null @@ -1,17 +0,0 @@ -import type { Config } from "jest"; - -const config: Config = { - testMatch: ["/src/tests/**/*.mts"], - - preset: "ts-jest/presets/default-esm", - resolver: "ts-jest-resolver", - moduleFileExtensions: ["js", "mjs", "cjs", "jsx", "ts", "mts", "cts", "tsx", "json", "node"], - - cacheDirectory: "/target/jest/cache", - slowTestThreshold: 5, - - clearMocks: true, - resetMocks: true, -}; - -export default config; diff --git a/crates/testlang/outputs/npm/tests/src/tests/ast/ast.mts b/crates/testlang/outputs/npm/tests/src/ast/ast.test.mts similarity index 92% rename from crates/testlang/outputs/npm/tests/src/tests/ast/ast.mts rename to crates/testlang/outputs/npm/tests/src/ast/ast.test.mts index e85b9e045..66d31e04f 100644 --- a/crates/testlang/outputs/npm/tests/src/tests/ast/ast.mts +++ b/crates/testlang/outputs/npm/tests/src/ast/ast.test.mts @@ -201,3 +201,22 @@ test("create and use binary expressions", () => { assertIsTerminalNode(operator, TerminalKind.Plus, "+"); assertIsTerminalNode(rightOperand.variant, TerminalKind.Identifier, "bar"); }); + +it("can reuse the same CST nodes after selectors", () => { + // Bug: https://github.com/NomicFoundation/slang/issues/1128 + + const source = `foo + bar`; + + const parser = Parser.create("1.0.0"); + const parseOutput = parser.parse(NonterminalKind.SourceUnit, source); + parseOutput.isValid(); // true + + const cst = parseOutput.tree.asNonterminalNode()!; + const ast = new SourceUnit(cst); + + expect(ast.cst.kind).toBe(NonterminalKind.SourceUnit); + + expect(ast.members.cst.kind).toBe(NonterminalKind.SourceUnitMembers); + + expect(ast.cst.kind).toBe(NonterminalKind.SourceUnit); +}); diff --git a/crates/testlang/outputs/npm/tests/src/tests/cst/cursor.mts b/crates/testlang/outputs/npm/tests/src/cst/cursor.test.mts similarity index 100% rename from crates/testlang/outputs/npm/tests/src/tests/cst/cursor.mts rename to crates/testlang/outputs/npm/tests/src/cst/cursor.test.mts diff --git a/crates/testlang/outputs/npm/tests/src/tests/cst/nodes.mts b/crates/testlang/outputs/npm/tests/src/cst/nodes.test.mts similarity index 100% rename from crates/testlang/outputs/npm/tests/src/tests/cst/nodes.mts rename to crates/testlang/outputs/npm/tests/src/cst/nodes.test.mts diff --git a/crates/testlang/outputs/npm/tests/src/tests/cst/query.mts b/crates/testlang/outputs/npm/tests/src/cst/query.test.mts similarity index 100% rename from crates/testlang/outputs/npm/tests/src/tests/cst/query.mts rename to crates/testlang/outputs/npm/tests/src/cst/query.test.mts diff --git a/crates/testlang/outputs/npm/tests/src/tests/cst/terminal-kind-extensions.mts b/crates/testlang/outputs/npm/tests/src/cst/terminal-kind-extensions.test.mts similarity index 100% rename from crates/testlang/outputs/npm/tests/src/tests/cst/terminal-kind-extensions.mts rename to crates/testlang/outputs/npm/tests/src/cst/terminal-kind-extensions.test.mts diff --git a/crates/testlang/outputs/npm/tests/src/tests/parser/parse-error.mts b/crates/testlang/outputs/npm/tests/src/parser/parse-error.test.mts similarity index 100% rename from crates/testlang/outputs/npm/tests/src/tests/parser/parse-error.mts rename to crates/testlang/outputs/npm/tests/src/parser/parse-error.test.mts diff --git a/crates/testlang/outputs/npm/tests/src/tests/parser/parse.mts b/crates/testlang/outputs/npm/tests/src/parser/parse.test.mts similarity index 100% rename from crates/testlang/outputs/npm/tests/src/tests/parser/parse.mts rename to crates/testlang/outputs/npm/tests/src/parser/parse.test.mts diff --git a/crates/testlang/outputs/npm/tests/src/tests/parser/root-kind.mts b/crates/testlang/outputs/npm/tests/src/parser/root-kind.test.mts similarity index 100% rename from crates/testlang/outputs/npm/tests/src/tests/parser/root-kind.mts rename to crates/testlang/outputs/npm/tests/src/parser/root-kind.test.mts diff --git a/crates/testlang/outputs/npm/tests/src/tests/parser/versions.mts b/crates/testlang/outputs/npm/tests/src/parser/versions.test.mts similarity index 100% rename from crates/testlang/outputs/npm/tests/src/tests/parser/versions.mts rename to crates/testlang/outputs/npm/tests/src/parser/versions.test.mts diff --git a/crates/testlang/outputs/npm/tests/src/public-api.test.mts b/crates/testlang/outputs/npm/tests/src/public-api.test.mts new file mode 100644 index 000000000..f9448d7f7 --- /dev/null +++ b/crates/testlang/outputs/npm/tests/src/public-api.test.mts @@ -0,0 +1,19 @@ +import * as slang from "@slang-private/testlang-npm-package"; +import { NonterminalKind, TerminalKind } from "@slang-private/testlang-npm-package/cst"; +import { Parser } from "@slang-private/testlang-npm-package/parser"; + +test("use namespace imports of the API", () => { + expect(slang.cst.NonterminalKind.SourceUnit).toEqual("SourceUnit"); + expect(slang.cst.NonterminalKind.TreeNode).toEqual("TreeNode"); + expect(slang.cst.TerminalKind.Identifier).toEqual("Identifier"); +}); + +test("use nested imports of the API", () => { + expect(NonterminalKind.SourceUnit).toEqual("SourceUnit"); + expect(NonterminalKind.TreeNode).toEqual("TreeNode"); + expect(TerminalKind.Identifier).toEqual("Identifier"); +}); + +test("language exposes a root kind", () => { + expect(Parser.rootKind()).toEqual(NonterminalKind.SourceUnit); +}); diff --git a/documentation/mkdocs.yml b/documentation/mkdocs.yml index 885c8f285..3060d1d1f 100644 --- a/documentation/mkdocs.yml +++ b/documentation/mkdocs.yml @@ -18,6 +18,15 @@ edit_uri: "edit/main/documentation/public" docs_dir: "./public" site_dir: "./target/site" # _SLANG_MKDOCS_DOCUMENTATION_SITE_DIR_ (keep in sync) +# __SLANG_CARGO_PUBLISH_TEMPORARILY_DISABLED__ (keep in sync) +not_in_nav: | + user-guide/rust-crate/index.md + user-guide/rust-crate/installation.md + user-guide/rust-crate/using-queries.md + user-guide/rust-crate/using-the-cli.md + user-guide/rust-crate/using-the-cursor.md + user-guide/rust-crate/using-the-parser.md + validation: nav: absolute_links: "warn" @@ -25,6 +34,7 @@ validation: omitted_files: "warn" links: absolute_links: "warn" + anchors: "warn" not_found: "warn" unrecognized_links: "warn" diff --git a/documentation/public/user-guide/.navigation.md b/documentation/public/user-guide/.navigation.md index 14660d028..1ba4fd4da 100644 --- a/documentation/public/user-guide/.navigation.md +++ b/documentation/public/user-guide/.navigation.md @@ -2,5 +2,4 @@ - [Introduction](./introduction.md) - [Concepts](./concepts.md) - [Tree Query Language](./tree-query-language.md) -- [Rust Crate](./rust-crate/) - [NPM Package](./npm-package/) diff --git a/documentation/public/user-guide/index.md b/documentation/public/user-guide/index.md index c9d05fd78..d508183f9 100644 --- a/documentation/public/user-guide/index.md +++ b/documentation/public/user-guide/index.md @@ -2,5 +2,5 @@ - [Introduction](./introduction.md) - [Concepts](./concepts.md) -- [Rust Crate](./rust-crate/index.md) +- [Tree Query Language](./tree-query-language.md) - [NPM Package](./npm-package/index.md) diff --git a/documentation/public/user-guide/introduction.md b/documentation/public/user-guide/introduction.md index 231ec50b6..662607df3 100644 --- a/documentation/public/user-guide/introduction.md +++ b/documentation/public/user-guide/introduction.md @@ -24,4 +24,4 @@ This is why, instead of having to download separate versions of the tool for eac ## Distributions -Slang itself is written in Rust and we maintain a public Rust package on [crates.io](https://crates.io/crates/slang_solidity). At the moment, we also distribute it as an [npm package](https://www.npmjs.com/package/@nomicfoundation/slang) with TypeScript interface. In the future, we plan on expanding the language captures with Python and possibly more. +Slang itself is written in Rust, compiled as a WASM component, and distributed as an [npm package](https://www.npmjs.com/package/@nomicfoundation/slang) with a TypeScript interface. In the future, we are also looking into publishing it as a Rust crate, a Python library, and possibly more. diff --git a/documentation/public/user-guide/npm-package/using-queries.md b/documentation/public/user-guide/npm-package/using-queries.md index 07599407f..194770d35 100644 --- a/documentation/public/user-guide/npm-package/using-queries.md +++ b/documentation/public/user-guide/npm-package/using-queries.md @@ -2,7 +2,7 @@ It's often more convenient to use the declarative `Query` API to traverse the CST, as they allow you to express your intent more concisely and can largely replace the need for both internal (cursor), and external (visitor) iterator patterns. -The [query language](./../tree-query-language.md) is based on pattern matching, and the execution semantics are closer to unification than to regular expression matching. A query returns all possible matches, not just the longest/shortest/first/last match. +The [Tree Query Language](./../tree-query-language.md) is based on pattern matching, and the execution semantics are closer to unification than to regular expression matching. A query returns all possible matches, not just the longest/shortest/first/last match. If not specified otherwise, let's assume we already parsed a Solidity source and have a `cursor` pointing to the root node of the CST (created with `createTreeCursor`, see [Using the Cursor](./using-the-cursor.md)). @@ -13,7 +13,7 @@ You can create a `Query` object using `Query.parse`, which accepts a string valu You can pass multiple queries to a cursor to and efficiently traverse the tree looking for matches. They will be executed concurrently, returning matches in the order they appear in input. ```{ .ts } ---8<-- "crates/solidity/outputs/npm/tests/src/doc-examples/using-queries.mts:creating-a-query" +--8<-- "crates/solidity/outputs/npm/tests/src/doc-examples/using-queries.test.mts:creating-a-query" ``` ## Iterating over node patterns @@ -27,7 +27,7 @@ Let's use this to list all the contract definitions in the source file: ``` ```{ .ts } ---8<-- "crates/solidity/outputs/npm/tests/src/doc-examples/using-queries.mts:visiting-contracts" +--8<-- "crates/solidity/outputs/npm/tests/src/doc-examples/using-queries.test.mts:visiting-contracts" ``` ### Multiple patterns simultaneously @@ -35,7 +35,7 @@ Let's use this to list all the contract definitions in the source file: We can also intersperse multiple patterns in a single query, which will return all the matches for each pattern. This can be useful when you want to match multiple types of nodes in a single pass. ```{ .ts } ---8<-- "crates/solidity/outputs/npm/tests/src/doc-examples/using-queries.mts:multiple-patterns" +--8<-- "crates/solidity/outputs/npm/tests/src/doc-examples/using-queries.test.mts:multiple-patterns" ``` ## Matching on node's label @@ -49,7 +49,7 @@ To do so, we use `[label: _]` syntax. Here, we also use `_` to allow matching an ``` ```{ .ts } ---8<-- "crates/solidity/outputs/npm/tests/src/doc-examples/using-queries.mts:matching-on-label" +--8<-- "crates/solidity/outputs/npm/tests/src/doc-examples/using-queries.test.mts:matching-on-label" ``` ## Matching on node's literal content @@ -63,7 +63,7 @@ Let's say we prefer our code to be explicit and prefer using `uint256` instead o ``` ```{ .ts } ---8<-- "crates/solidity/outputs/npm/tests/src/doc-examples/using-queries.mts:matching-on-literal-value" +--8<-- "crates/solidity/outputs/npm/tests/src/doc-examples/using-queries.test.mts:matching-on-literal-value" ``` ## Example: Finding `tx.origin` patterns @@ -79,5 +79,5 @@ Let's use the motivating example from [https://soliditylang.org](https://docs.so Now, we can above features to write a query that matches all `tx.origin` patterns: ```{ .ts } ---8<-- "crates/solidity/outputs/npm/tests/src/doc-examples/using-queries.mts:tx-origin" +--8<-- "crates/solidity/outputs/npm/tests/src/doc-examples/using-queries.test.mts:tx-origin" ``` diff --git a/documentation/public/user-guide/npm-package/using-the-ast.md b/documentation/public/user-guide/npm-package/using-the-ast.md index 2acb36c42..74077483e 100644 --- a/documentation/public/user-guide/npm-package/using-the-ast.md +++ b/documentation/public/user-guide/npm-package/using-the-ast.md @@ -11,26 +11,26 @@ to create the CST type. Since it is a node of kind `FunctionDefinition`, we are the AST type of the same name to analyze it: ```{ .ts } ---8<-- "crates/solidity/outputs/npm/tests/src/doc-examples/using-the-ast.mts:imports" +--8<-- "crates/solidity/outputs/npm/tests/src/doc-examples/using-the-ast.test.mts:imports" ---8<-- "crates/solidity/outputs/npm/tests/src/doc-examples/using-the-ast.mts:parse-input" +--8<-- "crates/solidity/outputs/npm/tests/src/doc-examples/using-the-ast.test.mts:parse-input" ``` The `FunctionDefinition` type has named fields to access all its children. For example, we can check the name of the function: ```{ .ts } ---8<-- "crates/solidity/outputs/npm/tests/src/doc-examples/using-the-ast.mts:create-node" +--8<-- "crates/solidity/outputs/npm/tests/src/doc-examples/using-the-ast.test.mts:create-node" ``` We can also list its parameters: ```{ .ts } ---8<-- "crates/solidity/outputs/npm/tests/src/doc-examples/using-the-ast.mts:list-parameters" +--8<-- "crates/solidity/outputs/npm/tests/src/doc-examples/using-the-ast.test.mts:list-parameters" ``` Or attributes: ```{ .ts } ---8<-- "crates/solidity/outputs/npm/tests/src/doc-examples/using-the-ast.mts:list-attributes" +--8<-- "crates/solidity/outputs/npm/tests/src/doc-examples/using-the-ast.test.mts:list-attributes" ``` diff --git a/documentation/public/user-guide/npm-package/using-the-cursor.md b/documentation/public/user-guide/npm-package/using-the-cursor.md index 28aba2308..175c28bef 100644 --- a/documentation/public/user-guide/npm-package/using-the-cursor.md +++ b/documentation/public/user-guide/npm-package/using-the-cursor.md @@ -8,9 +8,9 @@ Let's start with this source file, that contains three contracts: ``` ```{ .ts } ---8<-- "crates/solidity/outputs/npm/tests/src/doc-examples/using-the-cursor.mts:imports" +--8<-- "crates/solidity/outputs/npm/tests/src/doc-examples/using-the-cursor.test.mts:imports" ---8<-- "crates/solidity/outputs/npm/tests/src/doc-examples/using-the-cursor.mts:parse-input" +--8<-- "crates/solidity/outputs/npm/tests/src/doc-examples/using-the-cursor.test.mts:parse-input" ``` ## Listing Contract Names @@ -18,7 +18,7 @@ Let's start with this source file, that contains three contracts: The below example uses a cursor to list the names of all contracts in a source file: ```{ .ts } ---8<-- "crates/solidity/outputs/npm/tests/src/doc-examples/using-the-cursor.mts:listing-contract-names" +--8<-- "crates/solidity/outputs/npm/tests/src/doc-examples/using-the-cursor.test.mts:listing-contract-names" ``` ## Visiting Only a Sub-tree @@ -32,7 +32,7 @@ which cheaply creates a new cursor that starts at the given node, without copyin This lets us visit the sub-tree of each contract, without modifying the original cursor: ```{ .ts } ---8<-- "crates/solidity/outputs/npm/tests/src/doc-examples/using-the-cursor.mts:visiting-sub-tree" +--8<-- "crates/solidity/outputs/npm/tests/src/doc-examples/using-the-cursor.test.mts:visiting-sub-tree" ``` ## Accessing Node Positions @@ -41,5 +41,5 @@ The `Cursor` API also tracks the position and range of the current node it is vi Here is an example that records the source range of each contract, along with its text: ```{ .ts } ---8<-- "crates/solidity/outputs/npm/tests/src/doc-examples/using-the-cursor.mts:accessing-node-positions" +--8<-- "crates/solidity/outputs/npm/tests/src/doc-examples/using-the-cursor.test.mts:accessing-node-positions" ``` diff --git a/documentation/public/user-guide/npm-package/using-the-parser.md b/documentation/public/user-guide/npm-package/using-the-parser.md index b4b5e3b72..6fca81694 100644 --- a/documentation/public/user-guide/npm-package/using-the-parser.md +++ b/documentation/public/user-guide/npm-package/using-the-parser.md @@ -14,9 +14,9 @@ We begin by creating a `Parser` object with a specified version. This is an entr Then we can use it to parse the source file, specifying the top-level nonterminal to parse: ```{ .ts } ---8<-- "crates/solidity/outputs/npm/tests/src/doc-examples/using-the-parser.mts:imports" +--8<-- "crates/solidity/outputs/npm/tests/src/doc-examples/using-the-parser.test.mts:imports" ---8<-- "crates/solidity/outputs/npm/tests/src/doc-examples/using-the-parser.mts:parse-input" +--8<-- "crates/solidity/outputs/npm/tests/src/doc-examples/using-the-parser.test.mts:parse-input" ``` ## Checking for Syntax Errors @@ -24,13 +24,13 @@ Then we can use it to parse the source file, specifying the top-level nontermina If the file has errors, we can get them from the `ParseOutput` type, and print them out: ```{ .ts } ---8<-- "crates/solidity/outputs/npm/tests/src/doc-examples/using-the-parser.mts:print-errors" +--8<-- "crates/solidity/outputs/npm/tests/src/doc-examples/using-the-parser.test.mts:print-errors" ``` Otherwise, we can check if input is valid using this helpful utility: ```{ .ts } ---8<-- "crates/solidity/outputs/npm/tests/src/doc-examples/using-the-parser.mts:assert-is-valid" +--8<-- "crates/solidity/outputs/npm/tests/src/doc-examples/using-the-parser.test.mts:assert-is-valid" ``` ## Inspecting the Parse Tree @@ -38,11 +38,11 @@ Otherwise, we can check if input is valid using this helpful utility: Now, let's try to inspect the resulting CST, and iterate on its children: ```{ .ts } ---8<-- "crates/solidity/outputs/npm/tests/src/doc-examples/using-the-parser.mts:inspect-tree" +--8<-- "crates/solidity/outputs/npm/tests/src/doc-examples/using-the-parser.test.mts:inspect-tree" ``` Additionally, we can convert the CST node back into the input string: ```{ .ts } ---8<-- "crates/solidity/outputs/npm/tests/src/doc-examples/using-the-parser.mts:unparse-node" +--8<-- "crates/solidity/outputs/npm/tests/src/doc-examples/using-the-parser.test.mts:unparse-node" ``` diff --git a/jest.config.ts b/jest.config.ts index db9d2192a..82c5ea8ac 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -1,11 +1,39 @@ import type { Config } from "jest"; -const config: Config = { - projects: [ - // List all directories with package-level "jest.config.ts" files: - "/crates/solidity/outputs/npm/tests/", - "/crates/testlang/outputs/npm/tests/", +export default { + testMatch: ["/**/*.test.mts"], + + testPathIgnorePatterns: [".*/\\.hermit/", ".*/node_modules/", ".*/submodules/", ".*/target/"], + + moduleFileExtensions: [ + /* Plain: */ ["js", "ts"], + /* ESM: */ ["mjs", "mts"], + /* CJS: */ ["cjs", "cts"], + /* JSX: */ ["jsx", "tsx"], + /* Other: */ ["json", "node", "wasm"], + ].flat(), + + extensionsToTreatAsEsm: [ + // ".mjs" is already included. + ".mts", ], -}; -export default config; + cacheDirectory: "/target/jest/cache", + + slowTestThreshold: 5, + + clearMocks: true, + resetMocks: true, + + resolver: "ts-jest-resolver", + + transform: { + "^.+\\.m?[tj]sx?$": [ + "ts-jest", + { + isolatedModules: true, + useESM: true, + }, + ], + }, +} satisfies Config; diff --git a/package-lock.json b/package-lock.json index 24339724f..00c40054f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -50,7 +50,7 @@ }, "crates/solidity/outputs/npm/package": { "name": "@nomicfoundation/slang", - "version": "0.18.2", + "version": "0.18.3", "license": "MIT", "dependencies": { "@bytecodealliance/preview2-shim": "0.17.0"