Skip to content

fix: Include binding defaults in destructuring taint - #87

Merged
martinnaj merged 1 commit into
masterfrom
mnaj-include-binding-defaults-destructuring-taint
Aug 7, 2026
Merged

fix: Include binding defaults in destructuring taint#87
martinnaj merged 1 commit into
masterfrom
mnaj-include-binding-defaults-destructuring-taint

Conversation

@martinnaj

@martinnaj martinnaj commented Aug 7, 2026

Copy link
Copy Markdown
Member

Risk: low

Summary by CodeRabbit

  • New Features

    • Improved binding analysis for destructured declarations by including default initializer expressions in dependency spans.
  • Documentation

    • Added release notes for version 0.25.1.
  • Chores

    • Updated the application version to 0.25.1.

@martinnaj
martinnaj enabled auto-merge August 7, 2026 15:45
@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The parser now includes destructuring default initializer expressions in binding dependency spans. The project version and changelog were updated to 0.25.1.

Changes

Destructuring binding spans

Layer / File(s) Summary
Binding span collection and release metadata
internal/tsparse/tsparse.go, VERSION, CHANGELOG.md
collectBindings combines mapped source spans with default initializer spans. New helpers preserve unset line boundaries. The project version and changelog now reference 0.25.1.

Estimated code review effort: 2 (Simple) | ~10 minutes

Poem

I’m a rabbit with bindings to trace,
Default values now join the race.
Across each line, the spans grow wide,
With version notes hopping beside.
0.25.1—clean and bright!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: including binding default initializers in destructuring taint spans.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Comment @coderabbitai help to get the list of available commands.

@martinnaj
martinnaj merged commit 6c0ed9a into master Aug 7, 2026
6 of 7 checks passed
@martinnaj
martinnaj deleted the mnaj-include-binding-defaults-destructuring-taint branch August 7, 2026 15:48

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 43aedea and 0446604.

📒 Files selected for processing (3)
  • CHANGELOG.md
  • VERSION
  • internal/tsparse/tsparse.go

Comment on lines +546 to +555
// 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)
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 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.

Suggested change
// 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants