fix: Include binding defaults in destructuring taint - #87
Conversation
📝 WalkthroughWalkthroughThe parser now includes destructuring default initializer expressions in binding dependency spans. The project version and changelog were updated to 0.25.1. ChangesDestructuring binding spans
Estimated code review effort: 2 (Simple) | ~10 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/tsparse/tsparse.go`:
- Around line 546-555: Update the recursive binding collection logic around the
child mapping and default-span handling so ancestor default spans are retained
separately from each child’s mapped source span, then union those ancestor spans
into every descendant binding range. Preserve the existing child-source
selection while ensuring nested object and array defaults, including fallback
expressions, remain covered; add regression tests for both cases.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: c0e0efde-6e00-483e-ab5d-fdbbc9933720
📒 Files selected for processing (3)
CHANGELOG.mdVERSIONinternal/tsparse/tsparse.go
| // A binding default (`= expr`) is a second dependency: its value is used | ||
| // when the destructured slot is undefined. It sits on the pattern (LHS), | ||
| // disjoint from the mapped source (RHS), so widen the span to cover both — | ||
| // otherwise a symbol used only inside a default would escape taint detection. | ||
| if be.Initializer != nil { | ||
| ds := posToLine(scanner.SkipTrivia(text, be.Initializer.Pos()), lineMap) | ||
| de := posToLine(be.Initializer.End(), lineMap) | ||
| start = minLine(start, ds) | ||
| end = maxLine(end, de) | ||
| } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Preserve enclosing default spans during recursive binding collection.
The widened span is lost for nested bindings. The recursive child mapping at Line 540-542 replaces the inherited start and end values with the child source span.
For const { a: { b } = fallback } = { a: { b: value } }, the recorded span for b excludes fallback. A tainted symbol used only by fallback can therefore remain undetected.
Keep ancestor default spans separate from mapped source spans. Union the ancestor defaults after selecting each child source. Add regression tests for nested object and array defaults.
🐛 Proposed fix direction
-func collectBindings(pattern *ast.Node, init *ast.Node, fbStart, fbEnd int, text string, lineMap []core.TextPos, out *[]boundBinding) {
+func collectBindings(pattern *ast.Node, init *ast.Node, fbStart, fbEnd, inheritedDefaultStart, inheritedDefaultEnd int, text string, lineMap []core.TextPos, out *[]boundBinding) {
...
- collectBindings(name, vd.Initializer, fbStart, fbEnd, text, lineMap, &out)
+ collectBindings(name, vd.Initializer, fbStart, fbEnd, 0, 0, text, lineMap, &out)
...
+ childDefaultStart, childDefaultEnd := inheritedDefaultStart, inheritedDefaultEnd
+ start = minLine(start, inheritedDefaultStart)
+ end = maxLine(end, inheritedDefaultEnd)
if be.Initializer != nil {
...
+ childDefaultStart = minLine(childDefaultStart, ds)
+ childDefaultEnd = maxLine(childDefaultEnd, de)
...
- collectBindings(en, src, start, end, text, lineMap, out)
+ collectBindings(en, src, start, end, childDefaultStart, childDefaultEnd, text, lineMap, out)📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| // A binding default (`= expr`) is a second dependency: its value is used | |
| // when the destructured slot is undefined. It sits on the pattern (LHS), | |
| // disjoint from the mapped source (RHS), so widen the span to cover both — | |
| // otherwise a symbol used only inside a default would escape taint detection. | |
| if be.Initializer != nil { | |
| ds := posToLine(scanner.SkipTrivia(text, be.Initializer.Pos()), lineMap) | |
| de := posToLine(be.Initializer.End(), lineMap) | |
| start = minLine(start, ds) | |
| end = maxLine(end, de) | |
| } | |
| childDefaultStart, childDefaultEnd := inheritedDefaultStart, inheritedDefaultEnd | |
| start = minLine(start, inheritedDefaultStart) | |
| end = maxLine(end, inheritedDefaultEnd) | |
| // A binding default (`= expr`) is a second dependency: its value is used | |
| // when the destructured slot is undefined. It sits on the pattern (LHS), | |
| // disjoint from the mapped source (RHS), so widen the span to cover both — | |
| // otherwise a symbol used only inside a default would escape taint detection. | |
| if be.Initializer != nil { | |
| ds := posToLine(scanner.SkipTrivia(text, be.Initializer.Pos()), lineMap) | |
| de := posToLine(be.Initializer.End(), lineMap) | |
| start = minLine(start, ds) | |
| end = maxLine(end, de) | |
| childDefaultStart = minLine(childDefaultStart, ds) | |
| childDefaultEnd = maxLine(childDefaultEnd, de) | |
| } |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@internal/tsparse/tsparse.go` around lines 546 - 555, Update the recursive
binding collection logic around the child mapping and default-span handling so
ancestor default spans are retained separately from each child’s mapped source
span, then union those ancestor spans into every descendant binding range.
Preserve the existing child-source selection while ensuring nested object and
array defaults, including fallback expressions, remain covered; add regression
tests for both cases.
Risk: low
Summary by CodeRabbit
New Features
Documentation
Chores