Skip to content

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:

constobj={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-botnodejs-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-piotrowiczdario-piotrowiczforce-pushed the dario/repl-computed-simple branch from 66a2820 to 9cbd60dCompareJune 15, 2025 00:22
@codecov
Copy link

codecovbot 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 linesCoverage Δ
lib/repl.js94.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-piotrowiczdario-piotrowiczforce-pushed the dario/repl-computed-simple branch from 9cbd60d to 3dec780CompareJune 15, 2025 18:22
@dario-piotrowiczdario-piotrowiczforce-pushed the dario/repl-computed-simple branch from 3dec780 to da0d780CompareJune 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

@BridgeARBridgeAR 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.

@BridgeARBridgeAR 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-botnodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Jun 17, 2025
@nodejs-github-botnodejs-github-bot merged commit 0722023 into nodejs:mainJun 17, 2025
60 checks passed
@nodejs-github-bot
Copy link
Collaborator

Landed in 0722023

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

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

constsimpleExpressionRE=
/(?:[\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
aduh95 pushed a commit that referenced this pull request Jul 21, 2025
aduh95 pushed a commit that referenced this pull request Jul 24, 2025
marco-ippolito pushed a commit that referenced this pull request Aug 18, 2025
marco-ippolito pushed a commit that referenced this pull request Aug 20, 2025
marco-ippolito pushed a commit that referenced this pull request Aug 20, 2025
marco-ippolito pushed a commit that referenced this pull request Aug 23, 2025
marco-ippolito pushed a commit that referenced this pull request Aug 25, 2025
marco-ippolito pushed a commit that referenced this pull request Aug 25, 2025
marco-ippolito pushed a commit that referenced this pull request Aug 25, 2025
marco-ippolito pushed a commit that referenced this pull request Aug 25, 2025
marco-ippolito pushed a commit that referenced this pull request Aug 26, 2025
marco-ippolito pushed a commit that referenced this pull request Aug 27, 2025
addaleax added a commit to addaleax/node that referenced this pull request Sep 5, 2025
A number of recent changes to the REPL tab completion logic have introduced the ability for completion to cause side effects, specifically, calling arbitrary functions or variable assignments/updates. This was first introduced in 0722023 and the problem exacerbated in 8ba66c5. Our team noticed this because our tests started failing when attempting to update to Node.js 20.19.5. Some recent commits, such as 1093f38 or 6945337, have messages or PR descriptions that imply the intention to avoid side effects, which I can can generally be agreed upon is in line with the expectations that a user has of autocomplete functionality. However, some of the tests introduced in those commts specifically verify that side effects *can* happen under specific circunmstances. I am assuming here that this is unintentional, and the corresponding tests have been removed/replaced in this commit. Refs: nodejs#58709 Refs: nodejs#58775 Refs: nodejs#57909 Refs: nodejs#58891
addaleax added a commit to addaleax/node that referenced this pull request Sep 5, 2025
A number of recent changes to the REPL tab completion logic have introduced the ability for completion to cause side effects, specifically, calling arbitrary functions or variable assignments/updates. This was first introduced in 0722023 and the problem exacerbated in 8ba66c5. Our team noticed this because our tests started failing when attempting to update to Node.js 20.19.5. Some recent commits, such as 1093f38 or 6945337, have messages or PR descriptions that imply the intention to avoid side effects, which I can can generally be agreed upon is in line with the expectations that a user has of autocomplete functionality. However, some of the tests introduced in those commts specifically verify that side effects *can* happen under specific circunmstances. I am assuming here that this is unintentional, and the corresponding tests have been removed/replaced in this commit. Refs: nodejs#58709 Refs: nodejs#58775 Refs: nodejs#57909 Refs: nodejs#58891
addaleax added a commit to addaleax/node that referenced this pull request Sep 5, 2025
A number of recent changes to the REPL tab completion logic have introduced the ability for completion to cause side effects, specifically, calling arbitrary functions or variable assignments/updates. This was first introduced in 0722023 and the problem exacerbated in 8ba66c5. Our team noticed this because our tests started failing when attempting to update to Node.js 20.19.5. Some recent commits, such as 1093f38 or 6945337, have messages or PR descriptions that imply the intention to avoid side effects, which I can can generally be agreed upon is in line with the expectations that a user has of autocomplete functionality. However, some of the tests introduced in those commts specifically verify that side effects *can* happen under specific circunmstances. I am assuming here that this is unintentional, and the corresponding tests have been removed/replaced in this commit. Refs: nodejs#58709 Refs: nodejs#58775 Refs: nodejs#57909 Refs: nodejs#58891
addaleax added a commit to addaleax/node that referenced this pull request Sep 5, 2025
A number of recent changes to the REPL tab completion logic have introduced the ability for completion to cause side effects, specifically, calling arbitrary functions or variable assignments/updates. This was first introduced in 0722023 and the problem exacerbated in 8ba66c5. Our team noticed this because our tests started failing when attempting to update to Node.js 20.19.5. Some recent commits, such as 1093f38 or 6945337, have messages or PR descriptions that imply the intention to avoid side effects, which I can can generally be agreed upon is in line with the expectations that a user has of autocomplete functionality. However, some of the tests introduced in those commts specifically verify that side effects *can* happen under specific circunmstances. I am assuming here that this is unintentional, and the corresponding tests have been removed/replaced in this commit. Fixes: nodejs#58903 Refs: nodejs#58709 Refs: nodejs#58775 Refs: nodejs#57909 Refs: nodejs#58891
addaleax added a commit to addaleax/node that referenced this pull request Sep 7, 2025
A number of recent changes to the REPL tab completion logic have introduced the ability for completion to cause side effects, specifically, calling arbitrary functions or variable assignments/updates. This was first introduced in 0722023 and the problem exacerbated in 8ba66c5. Our team noticed this because our tests started failing when attempting to update to Node.js 20.19.5. Some recent commits, such as 1093f38 or 6945337, have messages or PR descriptions that imply the intention to avoid side effects, which I can can generally be agreed upon is in line with the expectations that a user has of autocomplete functionality. However, some of the tests introduced in those commts specifically verify that side effects *can* happen under specific circunmstances. I am assuming here that this is unintentional, and the corresponding tests have been removed/replaced in this commit. Fixes: nodejs#59731Fixes: nodejs#58903 Refs: nodejs#58709 Refs: nodejs#58775 Refs: nodejs#57909 Refs: nodejs#58891
nodejs-github-bot pushed a commit that referenced this pull request Sep 8, 2025
A number of recent changes to the REPL tab completion logic have introduced the ability for completion to cause side effects, specifically, calling arbitrary functions or variable assignments/updates. This was first introduced in 0722023 and the problem exacerbated in 8ba66c5. Our team noticed this because our tests started failing when attempting to update to Node.js 20.19.5. Some recent commits, such as 1093f38 or 6945337, have messages or PR descriptions that imply the intention to avoid side effects, which I can can generally be agreed upon is in line with the expectations that a user has of autocomplete functionality. However, some of the tests introduced in those commts specifically verify that side effects *can* happen under specific circunmstances. I am assuming here that this is unintentional, and the corresponding tests have been removed/replaced in this commit. Fixes: #59731Fixes: #58903 Refs: #58709 Refs: #58775 Refs: #57909 Refs: #58891 PR-URL: #59774 Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Dario Piotrowicz <[email protected]>
targos pushed a commit that referenced this pull request Sep 9, 2025
A number of recent changes to the REPL tab completion logic have introduced the ability for completion to cause side effects, specifically, calling arbitrary functions or variable assignments/updates. This was first introduced in 0722023 and the problem exacerbated in 8ba66c5. Our team noticed this because our tests started failing when attempting to update to Node.js 20.19.5. Some recent commits, such as 1093f38 or 6945337, have messages or PR descriptions that imply the intention to avoid side effects, which I can can generally be agreed upon is in line with the expectations that a user has of autocomplete functionality. However, some of the tests introduced in those commts specifically verify that side effects *can* happen under specific circunmstances. I am assuming here that this is unintentional, and the corresponding tests have been removed/replaced in this commit. Fixes: #59731Fixes: #58903 Refs: #58709 Refs: #58775 Refs: #57909 Refs: #58891 PR-URL: #59774 Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Dario Piotrowicz <[email protected]>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commit-queue-squashAdd this label to instruct the Commit Queue to squash all the PR commits into the first one.needs-ciPRs that need a full CI run.replIssues and PRs related to the REPL subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@dario-piotrowicz@nodejs-github-bot@anonrig@BridgeAR