ast-grep-cli 0.26.2__tar.gz → 0.26.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/Cargo.lock +17 -17
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/Cargo.toml +6 -6
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/PKG-INFO +1 -1
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/config/Cargo.toml +1 -1
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/config/src/transform/mod.rs +26 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/config/src/transform/transformation.rs +37 -18
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/core/Cargo.toml +1 -1
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/core/src/match_tree/strictness.rs +4 -1
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/core/src/meta_var.rs +14 -2
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/core/src/replacer/indent.rs +21 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/core/src/replacer.rs +2 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/dynamic/Cargo.toml +1 -1
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/language/Cargo.toml +1 -1
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/lsp/Cargo.toml +1 -1
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/pyproject.toml +1 -1
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/LICENSE +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/README.md +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/cli/Cargo.toml +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/cli/src/bin/ast-grep.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/cli/src/completions.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/cli/src/config.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/cli/src/debug.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/cli/src/error.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/cli/src/lang/custom_lang.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/cli/src/lang/injection.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/cli/src/lang/lang_globs.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/cli/src/lang.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/cli/src/lib.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/cli/src/lsp.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/cli/src/main.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/cli/src/new.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/cli/src/print/cloud_print.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/cli/src/print/colored_print/test.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/cli/src/print/colored_print.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/cli/src/print/interactive_print.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/cli/src/print/json_print.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/cli/src/print/mod.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/cli/src/run.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/cli/src/scan.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/cli/src/utils.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/cli/src/verify/case_result.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/cli/src/verify/find_file.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/cli/src/verify/mod.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/cli/src/verify/reporter.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/cli/src/verify/snapshot.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/cli/src/verify/test_case.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/cli/tests/common/mod.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/cli/tests/run_test.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/cli/tests/scan_test.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/cli/tests/verify_test.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/config/src/check_var.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/config/src/combined.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/config/src/fixer.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/config/src/lib.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/config/src/maybe.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/config/src/rule/deserialize_env.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/config/src/rule/mod.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/config/src/rule/nth_child.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/config/src/rule/referent_rule.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/config/src/rule/relational_rule.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/config/src/rule/stop_by.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/config/src/rule_collection.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/config/src/rule_config.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/config/src/rule_core.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/config/src/transform/rewrite.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/config/src/transform/string_case.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/core/src/language.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/core/src/lib.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/core/src/match_tree/match_node.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/core/src/match_tree/mod.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/core/src/matcher/kind.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/core/src/matcher/node_match.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/core/src/matcher/pattern.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/core/src/matcher/text.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/core/src/matcher.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/core/src/node.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/core/src/ops.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/core/src/pinned.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/core/src/replacer/structural.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/core/src/replacer/template.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/core/src/source.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/core/src/traversal.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/dynamic/src/lib.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/language/src/bash.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/language/src/cpp.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/language/src/csharp.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/language/src/css.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/language/src/elixir.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/language/src/go.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/language/src/haskell.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/language/src/html.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/language/src/json.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/language/src/kotlin.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/language/src/lib.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/language/src/lua.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/language/src/parsers.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/language/src/php.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/language/src/python.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/language/src/ruby.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/language/src/rust.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/language/src/scala.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/language/src/swift.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/lsp/src/lib.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/lsp/src/utils.rs +0 -0
- {ast_grep_cli-0.26.2 → ast_grep_cli-0.26.3}/crates/lsp/tests/basic.rs +0 -0
|
@@ -114,7 +114,7 @@ dependencies = [
|
|
|
114
114
|
|
|
115
115
|
[[package]]
|
|
116
116
|
name = "ast-grep"
|
|
117
|
-
version = "0.26.
|
|
117
|
+
version = "0.26.3"
|
|
118
118
|
dependencies = [
|
|
119
119
|
"ansi_term",
|
|
120
120
|
"anyhow",
|
|
@@ -145,7 +145,7 @@ dependencies = [
|
|
|
145
145
|
|
|
146
146
|
[[package]]
|
|
147
147
|
name = "ast-grep-config"
|
|
148
|
-
version = "0.26.
|
|
148
|
+
version = "0.26.3"
|
|
149
149
|
dependencies = [
|
|
150
150
|
"anyhow",
|
|
151
151
|
"ast-grep-core",
|
|
@@ -161,7 +161,7 @@ dependencies = [
|
|
|
161
161
|
|
|
162
162
|
[[package]]
|
|
163
163
|
name = "ast-grep-core"
|
|
164
|
-
version = "0.26.
|
|
164
|
+
version = "0.26.3"
|
|
165
165
|
dependencies = [
|
|
166
166
|
"bit-set",
|
|
167
167
|
"regex",
|
|
@@ -172,7 +172,7 @@ dependencies = [
|
|
|
172
172
|
|
|
173
173
|
[[package]]
|
|
174
174
|
name = "ast-grep-dynamic"
|
|
175
|
-
version = "0.26.
|
|
175
|
+
version = "0.26.3"
|
|
176
176
|
dependencies = [
|
|
177
177
|
"ast-grep-core",
|
|
178
178
|
"ignore",
|
|
@@ -184,7 +184,7 @@ dependencies = [
|
|
|
184
184
|
|
|
185
185
|
[[package]]
|
|
186
186
|
name = "ast-grep-language"
|
|
187
|
-
version = "0.26.
|
|
187
|
+
version = "0.26.3"
|
|
188
188
|
dependencies = [
|
|
189
189
|
"ast-grep-core",
|
|
190
190
|
"ignore",
|
|
@@ -216,7 +216,7 @@ dependencies = [
|
|
|
216
216
|
|
|
217
217
|
[[package]]
|
|
218
218
|
name = "ast-grep-lsp"
|
|
219
|
-
version = "0.26.
|
|
219
|
+
version = "0.26.3"
|
|
220
220
|
dependencies = [
|
|
221
221
|
"ast-grep-config",
|
|
222
222
|
"ast-grep-core",
|
|
@@ -230,7 +230,7 @@ dependencies = [
|
|
|
230
230
|
|
|
231
231
|
[[package]]
|
|
232
232
|
name = "ast-grep-napi"
|
|
233
|
-
version = "0.26.
|
|
233
|
+
version = "0.26.3"
|
|
234
234
|
dependencies = [
|
|
235
235
|
"ast-grep-config",
|
|
236
236
|
"ast-grep-core",
|
|
@@ -249,7 +249,7 @@ dependencies = [
|
|
|
249
249
|
|
|
250
250
|
[[package]]
|
|
251
251
|
name = "ast-grep-py"
|
|
252
|
-
version = "0.26.
|
|
252
|
+
version = "0.26.3"
|
|
253
253
|
dependencies = [
|
|
254
254
|
"anyhow",
|
|
255
255
|
"ast-grep-config",
|
|
@@ -317,7 +317,7 @@ dependencies = [
|
|
|
317
317
|
|
|
318
318
|
[[package]]
|
|
319
319
|
name = "benches"
|
|
320
|
-
version = "0.26.
|
|
320
|
+
version = "0.26.3"
|
|
321
321
|
dependencies = [
|
|
322
322
|
"ast-grep-config",
|
|
323
323
|
"ast-grep-core",
|
|
@@ -450,9 +450,9 @@ dependencies = [
|
|
|
450
450
|
|
|
451
451
|
[[package]]
|
|
452
452
|
name = "clap_complete"
|
|
453
|
-
version = "4.5.
|
|
453
|
+
version = "4.5.23"
|
|
454
454
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
455
|
-
checksum = "
|
|
455
|
+
checksum = "531d7959c5bbb6e266cecdd0f20213639c3a5c3e4d615f97db87661745f781ff"
|
|
456
456
|
dependencies = [
|
|
457
457
|
"clap",
|
|
458
458
|
]
|
|
@@ -1514,18 +1514,18 @@ checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b"
|
|
|
1514
1514
|
|
|
1515
1515
|
[[package]]
|
|
1516
1516
|
name = "serde"
|
|
1517
|
-
version = "1.0.
|
|
1517
|
+
version = "1.0.209"
|
|
1518
1518
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
1519
|
-
checksum = "
|
|
1519
|
+
checksum = "99fce0ffe7310761ca6bf9faf5115afbc19688edd00171d81b1bb1b116c63e09"
|
|
1520
1520
|
dependencies = [
|
|
1521
1521
|
"serde_derive",
|
|
1522
1522
|
]
|
|
1523
1523
|
|
|
1524
1524
|
[[package]]
|
|
1525
1525
|
name = "serde_derive"
|
|
1526
|
-
version = "1.0.
|
|
1526
|
+
version = "1.0.209"
|
|
1527
1527
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
1528
|
-
checksum = "
|
|
1528
|
+
checksum = "a5831b979fd7b5439637af1752d535ff49f4860c0f341d1baeb6faf0f4242170"
|
|
1529
1529
|
dependencies = [
|
|
1530
1530
|
"proc-macro2",
|
|
1531
1531
|
"quote",
|
|
@@ -1545,9 +1545,9 @@ dependencies = [
|
|
|
1545
1545
|
|
|
1546
1546
|
[[package]]
|
|
1547
1547
|
name = "serde_json"
|
|
1548
|
-
version = "1.0.
|
|
1548
|
+
version = "1.0.127"
|
|
1549
1549
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
1550
|
-
checksum = "
|
|
1550
|
+
checksum = "8043c06d9f82bd7271361ed64f415fe5e12a77fdb52e573e7f06a516dea329ad"
|
|
1551
1551
|
dependencies = [
|
|
1552
1552
|
"indexmap",
|
|
1553
1553
|
"itoa",
|
|
@@ -7,7 +7,7 @@ resolver = "2"
|
|
|
7
7
|
lto = true
|
|
8
8
|
|
|
9
9
|
[workspace.package]
|
|
10
|
-
version = "0.26.
|
|
10
|
+
version = "0.26.3"
|
|
11
11
|
authors = ["Herrington Darkholme <2883231+HerringtonDarkholme@users.noreply.github.com>"]
|
|
12
12
|
edition = "2021"
|
|
13
13
|
license = "MIT"
|
|
@@ -18,11 +18,11 @@ rust-version = "1.67"
|
|
|
18
18
|
readme = "README.md"
|
|
19
19
|
|
|
20
20
|
[workspace.dependencies]
|
|
21
|
-
ast-grep-core = { path = "crates/core", version = "0.26.
|
|
22
|
-
ast-grep-config = { path = "crates/config", version = "0.26.
|
|
23
|
-
ast-grep-dynamic = { path = "crates/dynamic", version = "0.26.
|
|
24
|
-
ast-grep-language = { path = "crates/language", version = "0.26.
|
|
25
|
-
ast-grep-lsp = { path = "crates/lsp", version = "0.26.
|
|
21
|
+
ast-grep-core = { path = "crates/core", version = "0.26.3" }
|
|
22
|
+
ast-grep-config = { path = "crates/config", version = "0.26.3" }
|
|
23
|
+
ast-grep-dynamic = { path = "crates/dynamic", version = "0.26.3" }
|
|
24
|
+
ast-grep-language = { path = "crates/language", version = "0.26.3" }
|
|
25
|
+
ast-grep-lsp = { path = "crates/lsp", version = "0.26.3" }
|
|
26
26
|
|
|
27
27
|
bit-set = { version = "0.8.0" }
|
|
28
28
|
ignore = { version = "0.4.22" }
|
|
@@ -118,4 +118,30 @@ mod test {
|
|
|
118
118
|
let ret = Transform::deserialize(&trans, &env);
|
|
119
119
|
assert!(ret.is_ok());
|
|
120
120
|
}
|
|
121
|
+
|
|
122
|
+
#[test]
|
|
123
|
+
fn test_transform_indentation() {
|
|
124
|
+
let src = "
|
|
125
|
+
if (true) {
|
|
126
|
+
let a = {
|
|
127
|
+
b: 123
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
";
|
|
131
|
+
let expected = "{
|
|
132
|
+
b: 123
|
|
133
|
+
}";
|
|
134
|
+
let mut trans = HashMap::new();
|
|
135
|
+
let tr = from_str("{ substring: { source: $A } }").expect("should work");
|
|
136
|
+
trans.insert("TR".into(), tr);
|
|
137
|
+
let grep = TypeScript::Tsx.ast_grep(src);
|
|
138
|
+
let root = grep.root();
|
|
139
|
+
let mut nm = root.find("let a = $A").expect("should find");
|
|
140
|
+
let env = DeserializeEnv::new(TypeScript::Tsx);
|
|
141
|
+
let trans = Transform::deserialize(&trans, &env).expect("should deserialize");
|
|
142
|
+
trans.apply_transform(nm.get_env_mut(), &Default::default(), &Default::default());
|
|
143
|
+
let actual = nm.get_env().get_transformed("TR").expect("should have TR");
|
|
144
|
+
let actual = std::str::from_utf8(actual).expect("should work");
|
|
145
|
+
assert_eq!(actual, expected);
|
|
146
|
+
}
|
|
121
147
|
}
|
|
@@ -109,6 +109,18 @@ pub enum Transformation<T> {
|
|
|
109
109
|
Rewrite(Rewrite<T>),
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
+
impl<T> Transformation<T> {
|
|
113
|
+
fn source(&self) -> &T {
|
|
114
|
+
use Transformation as T;
|
|
115
|
+
match self {
|
|
116
|
+
T::Replace(r) => &r.source,
|
|
117
|
+
T::Substring(s) => &s.source,
|
|
118
|
+
T::Convert(c) => &c.source,
|
|
119
|
+
T::Rewrite(r) => &r.source,
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
112
124
|
pub(crate) fn parse_meta_var<L: Language>(
|
|
113
125
|
src: &str,
|
|
114
126
|
lang: &L,
|
|
@@ -148,38 +160,25 @@ impl Transformation<String> {
|
|
|
148
160
|
}
|
|
149
161
|
|
|
150
162
|
pub fn used_vars(&self) -> &str {
|
|
151
|
-
fn strip(s: &str) -> &str {
|
|
152
|
-
s.strip_prefix("$$$").unwrap_or_else(|| &s[1..])
|
|
153
|
-
// match s {
|
|
154
|
-
// MetaVariable::Capture(s, _) => s,
|
|
155
|
-
// MetaVariable::Dropped(_) => "",
|
|
156
|
-
// MetaVariable::MultiCapture(s) => s,
|
|
157
|
-
// MetaVariable::Multiple => "",
|
|
158
|
-
// }
|
|
159
|
-
}
|
|
160
|
-
use Transformation as T;
|
|
161
163
|
// NOTE: meta_var in transform always starts with `$`, for now
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
T::Substring(s) => strip(&s.source),
|
|
165
|
-
T::Convert(c) => strip(&c.source),
|
|
166
|
-
T::Rewrite(r) => strip(&r.source),
|
|
167
|
-
}
|
|
164
|
+
let s = self.source();
|
|
165
|
+
s.strip_prefix("$$$").unwrap_or_else(|| &s[1..])
|
|
168
166
|
}
|
|
169
167
|
}
|
|
170
168
|
impl Transformation<MetaVariable> {
|
|
171
169
|
pub(super) fn insert<D: Doc>(&self, key: &str, ctx: &mut Ctx<D>) {
|
|
170
|
+
let src = self.source();
|
|
172
171
|
// TODO: add this debug assertion back
|
|
173
172
|
// debug_assert!(ctx.env.get_transformed(key).is_none());
|
|
174
173
|
// avoid cyclic
|
|
175
|
-
ctx.env.insert_transformation(key, vec![]);
|
|
174
|
+
ctx.env.insert_transformation(src, key, vec![]);
|
|
176
175
|
let opt = self.compute(ctx);
|
|
177
176
|
let bytes = if let Some(s) = opt {
|
|
178
177
|
<D::Source as Content>::decode_str(&s).to_vec()
|
|
179
178
|
} else {
|
|
180
179
|
vec![]
|
|
181
180
|
};
|
|
182
|
-
ctx.env.insert_transformation(key, bytes);
|
|
181
|
+
ctx.env.insert_transformation(src, key, bytes);
|
|
183
182
|
}
|
|
184
183
|
fn compute<D: Doc>(&self, ctx: &mut Ctx<D>) -> Option<String> {
|
|
185
184
|
use Transformation as T;
|
|
@@ -436,5 +435,25 @@ mod test {
|
|
|
436
435
|
assert_eq!(actual, "camelcase_not");
|
|
437
436
|
Ok(())
|
|
438
437
|
}
|
|
438
|
+
|
|
439
|
+
#[test]
|
|
440
|
+
fn test_transform_indentation_with_insertion() -> R {
|
|
441
|
+
let src = "
|
|
442
|
+
if (true) {
|
|
443
|
+
let a = {
|
|
444
|
+
b: 123
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
";
|
|
448
|
+
// note the indentation
|
|
449
|
+
let expected = "{
|
|
450
|
+
b: 123
|
|
451
|
+
}";
|
|
452
|
+
let tr = parse("{ substring: { source: $A } }")?;
|
|
453
|
+
let actual = get_transformed(src, "let a = $A", &tr).ok_or(())?;
|
|
454
|
+
assert_eq!(actual, expected);
|
|
455
|
+
Ok(())
|
|
456
|
+
}
|
|
457
|
+
|
|
439
458
|
// TODO: add a symbolic test for Rewrite
|
|
440
459
|
}
|
|
@@ -39,7 +39,10 @@ impl MatchStrictness {
|
|
|
39
39
|
) -> MatchOneNode {
|
|
40
40
|
use MatchStrictness as M;
|
|
41
41
|
let k = candidate.kind_id();
|
|
42
|
-
|
|
42
|
+
// work around ast-grep/ast-grep#1419 and tree-sitter/tree-sitter-typescript#306
|
|
43
|
+
// tree-sitter-typescript has wrong span of unnamed node so text would not match
|
|
44
|
+
// just compare kind for unnamed node
|
|
45
|
+
if k == kind && (!is_named || text == candidate.text()) {
|
|
43
46
|
return MatchOneNode::MatchedBoth;
|
|
44
47
|
}
|
|
45
48
|
let (skip_goal, skip_candidate) = match self {
|
|
@@ -5,6 +5,8 @@ use crate::{Doc, Language, Node, StrDoc};
|
|
|
5
5
|
use std::borrow::Cow;
|
|
6
6
|
use std::collections::HashMap;
|
|
7
7
|
|
|
8
|
+
use crate::replacer::formatted_slice;
|
|
9
|
+
|
|
8
10
|
pub type MetaVariableID = String;
|
|
9
11
|
|
|
10
12
|
type Underlying<D> = Vec<<<D as Doc>::Source as Content>::Underlying>;
|
|
@@ -44,8 +46,18 @@ impl<'tree, D: Doc> MetaVarEnv<'tree, D> {
|
|
|
44
46
|
}
|
|
45
47
|
}
|
|
46
48
|
|
|
47
|
-
pub fn insert_transformation(&mut self, name: &str,
|
|
48
|
-
|
|
49
|
+
pub fn insert_transformation(&mut self, var: &MetaVariable, name: &str, slice: Underlying<D>) {
|
|
50
|
+
let node = match var {
|
|
51
|
+
MetaVariable::Capture(v, _) => self.single_matched.get(v),
|
|
52
|
+
MetaVariable::MultiCapture(vs) => self.multi_matched.get(vs).and_then(|vs| vs.first()),
|
|
53
|
+
_ => None,
|
|
54
|
+
};
|
|
55
|
+
let deindented = if let Some(v) = node {
|
|
56
|
+
formatted_slice(&slice, v.root.doc.get_source(), v.range().start).to_vec()
|
|
57
|
+
} else {
|
|
58
|
+
slice
|
|
59
|
+
};
|
|
60
|
+
self.transformed_var.insert(name.to_string(), deindented);
|
|
49
61
|
}
|
|
50
62
|
|
|
51
63
|
pub fn get_match(&self, var: &str) -> Option<&'_ Node<'tree, D>> {
|
|
@@ -146,6 +146,27 @@ pub fn extract_with_deindent<C: Content>(content: &C, range: Range<usize>) -> De
|
|
|
146
146
|
DeindentedExtract::MultiLine(extract_slice, indent)
|
|
147
147
|
}
|
|
148
148
|
|
|
149
|
+
fn deindent_slice<'a, C: Content>(
|
|
150
|
+
slice: &'a [C::Underlying],
|
|
151
|
+
content: &'a C,
|
|
152
|
+
start: usize,
|
|
153
|
+
) -> DeindentedExtract<'a, C> {
|
|
154
|
+
if !slice.contains(&get_new_line::<C>()) {
|
|
155
|
+
return DeindentedExtract::SingleLine(slice);
|
|
156
|
+
}
|
|
157
|
+
let indent = get_indent_at_offset::<C>(content.get_range(0..start));
|
|
158
|
+
DeindentedExtract::MultiLine(slice, indent)
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
pub fn formatted_slice<'a, C: Content>(
|
|
162
|
+
slice: &'a [C::Underlying],
|
|
163
|
+
content: &'a C,
|
|
164
|
+
start: usize,
|
|
165
|
+
) -> Cow<'a, [C::Underlying]> {
|
|
166
|
+
let deindent = deindent_slice(slice, content, start);
|
|
167
|
+
indent_lines(0, deindent)
|
|
168
|
+
}
|
|
169
|
+
|
|
149
170
|
pub fn indent_lines<C: Content>(
|
|
150
171
|
indent: usize,
|
|
151
172
|
extract: DeindentedExtract<C>,
|
|
@@ -4,7 +4,7 @@ build-backend = "maturin"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "ast-grep-cli"
|
|
7
|
-
version = "0.26.
|
|
7
|
+
version = "0.26.3"
|
|
8
8
|
description = "Structural Search and Rewrite code at large scale using precise AST pattern."
|
|
9
9
|
authors = [{ name = "Herrington Darkholme", email = "2883231+HerringtonDarkholme@users.noreply.github.com" }]
|
|
10
10
|
maintainers = [{ name = "Herrington Darkholme", email = "2883231+HerringtonDarkholme@users.noreply.github.com" }]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|