Skip to content

Keep original line numbers when loop protection is on - #4358

Merged
doradocodes merged 4 commits into
processing:developfrom
bhabishnu:fix/loop-protection-line-numbers
Oct 28, 2026
Merged

doradocodes merged 4 commits into
processing:developfrom
bhabishnu:fix/loop-protection-line-numbers

Conversation

@bhabishnu

Copy link
Copy Markdown
Contributor

Issue:

Fixes #4356

Loop protection currently regenerates the whole sketch after modifying the AST. That changes the original source layout by removing comments and blank lines and reformatting the code, so runtime errors can end up pointing to the wrong line in the editor.

Changes:

  • Keep using the Acorn AST to locate loops, but insert the protection code directly into the original source at those AST offsets.
  • Apply edits from the end of the file backwards so earlier insertions don't shift the remaining offsets.
  • Keep the inserted protection code on the existing lines so the original line numbers are preserved.
  • Add regression coverage for the original repro, nested and brace-less loops, shared edit positions, and infinite-loop protection.

AI tools were used as an assistive tool during investigation and implementation. I reviewed the final diff and verified the behaviour and tests locally.

I have verified that this pull request:

  • has no linting errors (npm run lint)
  • has no test errors (npm run test)
  • has no typecheck errors (npm run typecheck)
  • is from a uniquely-named feature branch and is up to date with the develop branch.
  • is descriptively named and links to an issue number, i.e. Fixes #123
  • meets the standards outlined in the accessibility guidelines

@welcome

welcome Bot commented Oct 13, 2026

Copy link
Copy Markdown

🎉 Thanks for opening this pull request! Please check out our contributing guidelines if you haven't already.

@davepagurek davepagurek left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This looks good to me! I'm going to get a web editor maintainer to take a look too to make sure there's nothing else I'm missing.

@doradocodes
doradocodes enabled auto-merge October 28, 2026 17:35
@doradocodes
doradocodes merged commit f3d77eb into processing:develop Oct 28, 2026
1 of 2 checks passed

This branch is waiting to be deployed

1 waiting deployment
e2e-tests — 78b49001 Waiting Oct 28, 2026 by doradocodes via test-e2e #404
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.

[p5.js 2.0+ Bug Report]: p5js editor gives wrong (spurious) line number for errors when loop protection is on

3 participants