Skip to content

repl: add auto-indentation for multiline input#64607

Open
hemanth wants to merge 1 commit into
nodejs:mainfrom
hemanth:repl/auto-indent
Open

repl: add auto-indentation for multiline input#64607
hemanth wants to merge 1 commit into
nodejs:mainfrom
hemanth:repl/auto-indent

Conversation

@hemanth

@hemanth hemanth commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Split from #64443 per review feedback to use idiomatic single-feature PRs.

Automatically inserts 2-space indentation on continuation lines based on the current nesting depth of braces, brackets, and parentheses.

Refs: #48164

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. repl Issues and PRs related to the REPL subsystem. labels Jul 19, 2026
Comment thread lib/repl.js Outdated
Comment thread lib/internal/repl/utils.js Outdated
Comment thread lib/internal/repl/utils.js Outdated
@hemanth
hemanth force-pushed the repl/auto-indent branch from 1c7938f to 98b285b Compare July 19, 2026 23:00
@hemanth

hemanth commented Jul 19, 2026

Copy link
Copy Markdown
Contributor Author
  • setupAutoIndent → standalone getAutoIndent(code) helper, no more monkey-patching the REPL instance
  • Dropped the typeof guard — direct call since the helper is always available
  • Swapped manual char scanner for Acorn tokenizer (same one used in isRecoverableError), falls back to simple brace-counting on parse failure

PTAL @avivkeller

Comment thread lib/internal/repl/utils.js Outdated
Comment thread lib/internal/repl/utils.js Outdated
@hemanth
hemanth force-pushed the repl/auto-indent branch from 98b285b to 7804264 Compare July 19, 2026 23:10
@hemanth

hemanth commented Jul 19, 2026

Copy link
Copy Markdown
Contributor Author

Good call — dropped the Acorn re-parse entirely. isRecoverableError already validates syntax before getAutoIndent runs, so a simple brace counter is sufficient here. Lighter and no duplicate work 👍

PTAL @avivkeller

@hemanth
hemanth force-pushed the repl/auto-indent branch from 7804264 to 63e25ed Compare July 19, 2026 23:13
Automatically insert 2-space indentation on continuation lines
based on brace/bracket/paren depth when entering multiline input.

Refs: nodejs#48164
Signed-off-by: hemanth <hemanth.hm@gmail.com>
@hemanth
hemanth force-pushed the repl/auto-indent branch from 63e25ed to aa16617 Compare July 19, 2026 23:32
@codecov

codecov Bot commented Jul 20, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.33333% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 90.12%. Comparing base (0bcc6ef) to head (aa16617).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
lib/internal/repl/utils.js 98.07% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #64607      +/-   ##
==========================================
- Coverage   90.14%   90.12%   -0.02%     
==========================================
  Files         741      741              
  Lines      242080   242140      +60     
  Branches    45563    45575      +12     
==========================================
+ Hits       218213   218239      +26     
- Misses      15375    15425      +50     
+ Partials     8492     8476      -16     
Files with missing lines Coverage Δ
lib/repl.js 92.96% <100.00%> (+0.04%) ⬆️
lib/internal/repl/utils.js 96.99% <98.07%> (+0.06%) ⬆️

... and 36 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

Labels

needs-ci PRs that need a full CI run. repl Issues and PRs related to the REPL subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants