Skip to content

repl: fix tab completion not working with computer string properties #58709

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

dario-piotrowicz
Copy link
Member

I noticed that the repl tab completion doesn't correctly handle computed properties targeted by strings.

For example given the following context:

const obj = { one: 1 };

The current repl would provide valid (number) completions for lines such as:

obj.one.to

But would not provide correct completions for lines such as:

obj['one'].to

In fact it would provide incorrect (string) completions.

See:
Screenshot at 2025-06-15 01-03-50

This PR addresses the above issue

Note

This PR is not making everything work perfectly, for example it is not addressing lines such as
obj['o' + 'ne'].to (but it's not making them any worse either).
I think that a generally great solution would require more substantial code changes (potentially with some AST analysis).
I am planning on keeping improving things here but I figured I could do it incrementally and that I'd open this PR to
start moving things in the right direction anyways.

@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 Jun 15, 2025
@dario-piotrowicz dario-piotrowicz force-pushed the dario/repl-computed-simple branch from 66a2820 to 9cbd60d Compare June 15, 2025 00:22
Copy link

codecov bot commented Jun 15, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.13%. Comparing base (d6dade5) to head (da0d780).
Report is 4 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #58709   +/-   ##
=======================================
  Coverage   90.12%   90.13%           
=======================================
  Files         637      637           
  Lines      188121   188121           
  Branches    36892    36892           
=======================================
+ Hits       169552   169568   +16     
- Misses      11313    11316    +3     
+ Partials     7256     7237   -19     
Files with missing lines Coverage Δ
lib/repl.js 94.87% <100.00%> (-0.26%) ⬇️

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

@dario-piotrowicz dario-piotrowicz force-pushed the dario/repl-computed-simple branch from 9cbd60d to 3dec780 Compare June 15, 2025 18:22
@dario-piotrowicz dario-piotrowicz force-pushed the dario/repl-computed-simple branch from 3dec780 to da0d780 Compare June 15, 2025 20:01
@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot
Copy link
Collaborator

Copy link
Member

@BridgeAR BridgeAR left a comment

Choose a reason for hiding this comment

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

That is definitely a nice improvement!

We'd better use acorn to detect these things in the future though. We are for example still missing support for whitespace in-between. We also miss support for partial matches inside of a bracket. That would also be great.

@BridgeAR BridgeAR added commit-queue Add this label to land a pull request using GitHub Actions. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. labels Jun 17, 2025
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Jun 17, 2025
@nodejs-github-bot nodejs-github-bot merged commit 0722023 into nodejs:main Jun 17, 2025
60 checks passed
@nodejs-github-bot
Copy link
Collaborator

Landed in 0722023

@dario-piotrowicz dario-piotrowicz deleted the dario/repl-computed-simple branch June 17, 2025 08:57
@dario-piotrowicz
Copy link
Member Author

We'd better use acorn to detect these things in the future though. We are for example still missing support for whitespace in-between.

I 100% agree, as I mentioned in the PR description this was a first fix I figured I could already land (it also already includes some new tests which will help assuring that changes later work as intended)

I'll most likely be using acron on my next iteration here, also I really really want to get rid of this regex:

node/lib/repl.js

Lines 1228 to 1229 in da0d780

const simpleExpressionRE =
/(?:[\w$'"`[{(](?:(\w| |\t)*?['"`]|\$|['"`\]})])*\??(?:\.|])?)*?(?:[a-zA-Z_$])?(?:\w|\$)*\??\.?$/;

😁

(since it's very complex and not even fully correct)


We also miss support for partial matches inside of a bracket. That would also be great.

Can you elaborate? 🙂

RafaelGSS pushed a commit that referenced this pull request Jun 23, 2025
PR-URL: #58709
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. 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