benjamn / benjamn/ast-types

off by one error when updating indices after mutation

Open
#56 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
1.2k
Forks
194
Avg merge
22h 43m
Merged PRs (30d)
10

Description

I can't repro this in an isolated case but there is an off-by-one error for a combination of an
`path.insertBefore(...nodes)` and `path.replace()` (deletion). I worked around by moving from:

```
// path.insertBefore have called multiple times before this.
path.insertBefore(...nodes);
path.replace();
```

to

```
// path.insertBefore have called multiple times before this.
path.replace(...nodes);
```

I'll keep trying to repro in isolated code but I wanted to report the issue incase you have any ideas

Contributor guide

No contributing guide indexed for this repository

Research direction

No file or test is named. Start by building a minimal reproduction around repeated path.insertBefore(...nodes) followed by path.replace(), compare it with path.replace(...nodes), and trace the index updates during mutation. Done means the off-by-one behavior is reproduced and the relevant update path has a verified regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.