Skip to content

repl: support .help expression for introspection#64479

Open
hemanth wants to merge 1 commit into
nodejs:mainfrom
hemanth:repl/help-method
Open

repl: support .help expression for introspection#64479
hemanth wants to merge 1 commit into
nodejs:mainfrom
hemanth:repl/help-method

Conversation

@hemanth

@hemanth hemanth commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Description

Extend the .help REPL command to accept an optional expression, providing interactive introspection without adding anything to the REPL context.

Without an argument, .help prints the command listing exactly as before. With an argument, the expression is evaluated in the REPL context and introspection info about the resulting value is printed.

Usage

> .help Array
Function: Array
  Length:     1
  Prototype methods:
    at, concat, copyWithin, entries, every, fill, filter, find, ...

> .help process.versions
Object {
  Properties:
    node: '27.0.0-pre'
    ...
}

> .help fetchData
AsyncFunction: fetchData
  Parameters: url
  Length:     1

> .help 42
number: 42

Implementation Details

  • .help expression evaluates the expression via the REPL's own eval (so custom evaluators, context vars, etc. all work) and prints type, function kind (Function/AsyncFunction/GeneratorFunction/Class), signature, own properties categorized into Methods/Accessors/Properties, and the prototype chain
  • Uses util.styleText for colorized output (respects NO_COLOR)
  • Evaluation errors are reported without breaking the REPL
  • No changes to the REPL context: per review feedback, the earlier global help() approach was dropped in favor of extending the existing dot-command

Refs: #51763

@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 95.23810% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.23%. Comparing base (e7864e6) to head (a9e0938).
⚠️ Report is 36 commits behind head on main.

Files with missing lines Patch % Lines
lib/internal/repl/utils.js 96.51% 6 Missing ⚠️
lib/repl.js 82.35% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #64479      +/-   ##
==========================================
- Coverage   90.24%   90.23%   -0.01%     
==========================================
  Files         741      739       -2     
  Lines      241665   241931     +266     
  Branches    45543    45608      +65     
==========================================
+ Hits       218092   218313     +221     
- Misses      15105    15127      +22     
- Partials     8468     8491      +23     
Files with missing lines Coverage Δ
lib/repl.js 93.87% <82.35%> (-0.14%) ⬇️
lib/internal/repl/utils.js 96.41% <96.51%> (+0.02%) ⬆️

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

@hemanth
hemanth force-pushed the repl/help-method branch from bbcbd69 to 8d989cb Compare July 14, 2026 04:43
@avivkeller

Copy link
Copy Markdown
Member

.help makes sense, but I don't think polluting the global object with help() does

@hemanth
hemanth force-pushed the repl/help-method branch from 8d989cb to 49c4da6 Compare July 15, 2026 00:33
@hemanth

hemanth commented Jul 15, 2026

Copy link
Copy Markdown
Contributor Author

hmm, so it would be like .help [param]? like today .help just prints the help message. _help is odd?

@ljharb

ljharb commented Jul 15, 2026

Copy link
Copy Markdown
Member

having any repl command that doesn't start with . is odd, i'd think

@hemanth

hemanth commented Jul 16, 2026

Copy link
Copy Markdown
Contributor Author

nods, but we do have just the _ which holds the value of the pervious line that was executed.

Extend the `.help` REPL command to accept an optional expression.
When one is given, it is evaluated in the REPL context and
introspection information about the resulting value is printed:
type, function signature, properties, methods, and prototype chain.
Without an argument, `.help` prints the command listing as before.

An earlier revision injected a global `help()` function into the
REPL context instead; review feedback was that REPL functionality
should live behind dot-commands rather than pollute the context.

Refs: nodejs#51763
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@hemanth
hemanth force-pushed the repl/help-method branch from 49c4da6 to a9e0938 Compare July 17, 2026 19:11
@hemanth hemanth changed the title repl: add help() function for interactive introspection repl: support .help expression for introspection Jul 17, 2026
@hemanth

hemanth commented Jul 17, 2026

Copy link
Copy Markdown
Contributor Author

Reworked as suggested: the global help() is gone, and the existing .help command now takes an optional expression instead.

  • .help with no argument prints the command listing, unchanged.
  • .help expression evaluates the expression via the REPL's own eval and prints introspection info (type, function signature, properties/methods/accessors, prototype chain). Since it goes through the regular eval path, context variables and custom evaluators work as expected.

Nothing is added to the REPL context anymore, so there's no pollution in useGlobal mode and no shadowing of user-defined help. Docs updated and tests rewritten to drive .help through the REPL input stream.

//cc @avivkeller @ljharb && @nodejs/repl

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.

4 participants