ast_grep_replace: dryRun previews invalid rewrites as success; $$$ captures flatten multi-line matches
AFT: 0.62.0, OpenCode 2.1.4, macOS.
Two ast_grep_replace problems:
dryRunpreviews an invalid rewrite as success, while apply refuses it. Patternfoo($A, $B), rewritebar($B, $A(unbalanced),lang: typescript,dryRun: true→ "Would replace 2 match(es)" with a diff containingbar(2, 1;. WithoutdryRunan invalid rewrite fails with "rewritten code failed syntax validation; no files were written". The preview should run the same validation, so a preview never promises a change apply will reject.- Variadic captures flatten multi-line matches. Source
foo(\n 3,\n 4\n);, patternfoo($$$A), rewritebar($$$A)→bar(3,\n4);(indentation lost; dryRun and apply agree). Expected the captured nodes to keep their original separators/indentation. Relatedlyast_grep_searchdisplays the capture as$A: 1,,,2.
Working as expected: $$$ matching, ignoring matches in strings/comments, globs and negated globs, dryRun leaving files untouched, apply matching the preview for valid rewrites.
Rechecked on 0.63.5. The dry-run part is fixed: an invalid rewrite is now refused in the preview, and search shows $A: 1, 2. The $$$ rewrite output is still flattened.
Pattern foo($$$ARGS), rewrite bar($$$ARGS), TypeScript, dryRun: true:
foo(
3,
4
);
previews as
bar(3,
4);
Nested in a function, the same call previews as bar(3,\n 4);, so the first argument moves up onto the call line and the original indentation of the remaining lines is lost. I expected the captured text to come back as it was: bar(\n 3,\n 4\n);.
The 0.63.4 notes say $$$ captures are preserved, but issue_827_828_repro_test.rs only covers the search display and the dry-run refusal, not the rewritten output.
Confirmed on current main: invalid rewrites are refused in preview, and variadic search display is repaired, but multiline $$$ARGS replacements still flatten the original layout. The reported example previews and applies as bar(3,\n4);. Keeping this open for the rewrite-formatting portion.