Skip to content

repl: add help() function for interactive introspection#64479

Open
hemanth wants to merge 2 commits into
nodejs:mainfrom
hemanth:repl/help-method
Open

repl: add help() function for interactive introspection#64479
hemanth wants to merge 2 commits into
nodejs:mainfrom
hemanth:repl/help-method

Conversation

@hemanth

@hemanth hemanth commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Description

Add a built-in help() function to the REPL context that provides Python-like interactive introspection.

Usage

> help()
Node.js REPL Help

Commands:
  .break        Sometimes you get stuck, this gets you out
  .clear        Break, and also clear the local context
  .editor       Enter editor mode
  .exit         Exit the REPL
  .help         Print this help message
  .load         Load JS from a file into the REPL session
  .save         Save all evaluated commands in this REPL session to a file

Shortcuts:
  Ctrl+C        Abort current expression
  Ctrl+D        Exit the REPL
  ...

> help(Array)
Class: Array
  Parameters: ...items
  Length:     0
  Prototype methods:
    at, concat, copyWithin, entries, every, fill, filter, find, ...

> help({x: 1, greet() {}})
Object {
  Methods:
    greet()
  Properties:
    x: 1
}

> help(42)
number: 42

Implementation Details

  • help() — Shows all REPL commands, keyboard shortcuts, and usage hints
  • help(fn) — Shows function kind (Function/AsyncFunction/GeneratorFunction/Class), name, parameters, arity, and prototype methods
  • help(obj) — Categorizes own properties into Methods, Accessors, and Properties; shows prototype chain
  • help(value) — Shows type + value for primitives, null, undefined
  • Uses util.styleText for colorized output (respects NO_COLOR)
  • Typing help without parens shows a custom inspect hint
  • Non-enumerable on context (doesn't pollute tab-completion)
  • Survives .clear (context reset)

Refs: #51763

Add a built-in help() function to the REPL context that provides
Python-like interactive introspection:

- help()         Show REPL commands, shortcuts, and usage guide
- help(fn)       Show function kind, name, parameters, arity, and
                 prototype methods for classes
- help(obj)      Categorize object's own properties into Methods,
                 Accessors, and Properties with prototype chain info
- help(value)    Show type and value for primitives, null, undefined

The function uses util.styleText for colorized output (respects
NO_COLOR and terminal capabilities). Typing 'help' without parens
shows a custom inspect hint.

The help function is added as a non-enumerable property on the REPL
context so it doesn't pollute tab-completion of user variables.
It survives .clear (context reset).

Refs: nodejs#51763
Signed-off-by: hemanth <hemanth.hm@gmail.com>
@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 13, 2026
@codecov

codecov Bot commented Jul 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.07113% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.24%. Comparing base (e7864e6) to head (8d989cb).
⚠️ Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
lib/internal/repl/utils.js 96.94% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #64479      +/-   ##
==========================================
- Coverage   90.24%   90.24%   -0.01%     
==========================================
  Files         741      741              
  Lines      241665   241927     +262     
  Branches    45543    45600      +57     
==========================================
+ Hits       218092   218320     +228     
- Misses      15105    15129      +24     
- Partials     8468     8478      +10     
Files with missing lines Coverage Δ
lib/repl.js 94.05% <100.00%> (+0.03%) ⬆️
lib/internal/repl/utils.js 96.50% <96.94%> (+0.11%) ⬆️

... and 27 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.

Add test cases for uncovered branches:
- GeneratorFunction and AsyncGeneratorFunction kinds
- Anonymous functions (no .name)
- Arrow functions (no .prototype)
- Objects with getter/setter accessors
- Prototype chain display for subclassed instances
- Error handling for objects that throw on property access
- useColors=true path exercising styleText
@hemanth hemanth force-pushed the repl/help-method branch from bbcbd69 to 8d989cb Compare July 14, 2026 04:43
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.

2 participants