Commit Graph

76 Commits

Author SHA1 Message Date
Giovanni Bucci 5a23443104
repl: extract and standardize history from both repl and interface
PR-URL: https://github.com/nodejs/node/pull/58225
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Dario Piotrowicz <dario.piotrowicz@gmail.com>
2025-05-28 07:38:39 +00:00
Dario Piotrowicz 39ab68b2c1
readline: add stricter validation for functions called after closed
PR-URL: https://github.com/nodejs/node/pull/58283
Fixes: https://github.com/nodejs/node/issues/57678
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2025-05-18 19:46:38 +00:00
Giovanni Bucci 4a4aa58fa4
repl: add support for multiline history
PR-URL: https://github.com/nodejs/node/pull/57400
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Jordan Harband <ljharb@gmail.com>
2025-04-13 11:58:01 +00:00
Dario Piotrowicz 922ce9d236
debugger: fix behavior of plain object exec in debugger repl
Co-authored-by: Xuguang Mei <meixuguang@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/57498
Fixes: https://github.com/nodejs/node/issues/46808
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Xuguang Mei <meixuguang@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
2025-03-18 19:30:31 +00:00
Gürgün Dayıoğlu a20acd407d
lib: limit split function calls to prevent excessive array length
PR-URL: https://github.com/nodejs/node/pull/57501
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Jacob Smith <jacob@frende.me>
2025-03-18 15:52:50 +00:00
Gürgün Dayıoğlu 8ed50bcbe5
lib: remove startsWith/endsWith primordials for char checks
PR-URL: https://github.com/nodejs/node/pull/55407
Reviewed-By: Jacob Smith <jacob@frende.me>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Mattias Buelens <mattias@buelens.com>
Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
2024-10-19 10:18:10 +00:00
Aviv Keller c6d20a034d
repl: catch `\v` and `\r` in new-line detection
PR-URL: https://github.com/nodejs/node/pull/54512
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
Reviewed-By: LiviaMedeiros <livia@cirno.name>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
2024-09-25 08:51:11 +00:00
Luke Haas 479b8e5232
repl: fix await object patterns without values
fix lint issue

PR-URL: https://github.com/nodejs/node/pull/53331
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Kohei Ueno <kohei.ueno119@gmail.com>
2024-06-07 01:24:32 +00:00
linkgoron 12232946c0
repl: fix disruptive autocomplete without inspector
Fix an issue where the autocomplete wrongly autocompletes
a value from a correct value to an undefined value when `node`
is built without an inspector by disabling the preview view.

fixes: https://github.com/nodejs/node/issues/40635
PR-URL: https://github.com/nodejs/node/pull/40661
Fixes: https://github.com/nodejs/node/issues/40635
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
2024-05-12 11:15:25 +02:00
Rafael Gonzaga ff14b24e12
lib: fix output message when repl is used with pm
PR-URL: https://github.com/nodejs/node/pull/48438
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
2023-06-17 17:28:38 +00:00
Xuguang Mei 2566400aa2
repl: preserve preview on ESCAPE key press
Fix: #46876
PR-URL: https://github.com/nodejs/node/pull/46878
Fixes: https://github.com/nodejs/node/issues/46876
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
2023-03-16 03:24:23 +00:00
Duy Mac Van d0608c2b4d
repl: remove lastInputPreview conditional check
PR-URL: https://github.com/nodejs/node/pull/46857
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Kohei Ueno <kohei.ueno119@gmail.com>
2023-03-01 14:28:31 +00:00
Antoine du Hamel e4e8421c25
repl: add trailing commas in source files
PR-URL: https://github.com/nodejs/node/pull/46757
Reviewed-By: Deokjin Kim <deokjin81.kim@gmail.com>
Reviewed-By: Qingyu Deng <i@ayase-lab.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
2023-02-24 09:43:27 +01:00
Rafael Gonzaga 00c222593e
src,process: add permission model
Signed-off-by: RafaelGSS <rafael.nunu@hotmail.com>
PR-URL: https://github.com/nodejs/node/pull/44004
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2023-02-23 18:11:51 +00:00
Antoine du Hamel fe514bf960
lib: enforce use of trailing commas for functions
PR-URL: https://github.com/nodejs/node/pull/46629
Reviewed-By: Jacob Smith <jacob@frende.me>
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
2023-02-14 18:45:16 +01:00
Tobias Nießen b014266c33
repl: fix overzealous top-level await
Fixes: https://github.com/nodejs/node/issues/43777

PR-URL: https://github.com/nodejs/node/pull/43827
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
2022-07-15 20:30:50 +01:00
Antoine du Hamel a055337a02
lib: refactor to avoid unsafe regex primordials
PR-URL: https://github.com/nodejs/node/pull/43475
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
2022-06-27 17:16:06 +02:00
Rich Trott 55ceaec111 tools,benchmark,lib,test: enable no-case-declarations lint rule
PR-URL: https://github.com/nodejs/node/pull/41385
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Tierney Cyren <hello@bnb.im>
Reviewed-By: Ricky Zhou <0x19951125@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2022-01-05 07:42:19 -08:00
Mestery 92ecd9f6e4
repl: skip EmptyStatements and return result with TLA
Fixes: https://github.com/nodejs/node/issues/39932

PR-URL: https://github.com/nodejs/node/pull/40194
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
2021-09-27 19:54:01 +02:00
Mestery addb30f0c9
repl: fix top level await with surrogate characters
Fixes: https://github.com/nodejs/node/issues/39929

PR-URL: https://github.com/nodejs/node/pull/39931
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Shingo Inoue <leko.noor@gmail.com>
2021-09-08 21:12:33 +02:00
Don Jayamanne 3fe92a2554 repl: fix tla function hoisting
PR-URL: https://github.com/nodejs/node/pull/39745
Fixes: https://github.com/nodejs/node/issues/39744
Reviewed-By: Guy Bedford <guybedford@gmail.com>
2021-08-19 09:14:31 -07:00
ejose19 8879993079 repl: processTopLevelAwait fallback error handling
PR-URL: https://github.com/nodejs/node/pull/39290
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2021-07-08 11:13:55 -07:00
ejose19 394fdecc91 repl: correctly hoist top level await declarations
PR-URL: https://github.com/nodejs/node/pull/39265
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2021-07-08 10:40:53 -07:00
Guy Bedford 8189dcc52a repl: ensure correct syntax err for await parsing
PR-URL: https://github.com/nodejs/node/pull/39154
Reviewed-By: Anna Henningsen <anna@addaleax.net>
2021-07-02 15:52:11 -07:00
Michaël Zasso 189d584244
deps: update Acorn to v8.4.1
We can remove the Acorn plugins as their features are now supported
by default.

PR-URL: https://github.com/nodejs/node/pull/39166
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
2021-06-29 17:20:45 +02:00
Antoine du Hamel 54dfdbcccf
readline: move utilities to internal modules
PR-URL: https://github.com/nodejs/node/pull/38466
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
2021-05-02 09:20:18 +02:00
eladkeyshawn d6669645c0 repl: fix declaring a variable with the name `util`
The REPL no longer relies on `util` being a reference to the `util` core
module. It still relies on `globalThis` refering to the global object,
but no longer emits warnings when it's overwritten by the user.

PR-URL: https://github.com/nodejs/node/pull/38141
Fixes: https://github.com/nodejs/node/issues/38139
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
2021-04-18 16:12:41 +02:00
Antoine du Hamel 708f049471 repl: refactor to avoid unsafe array iteration
PR-URL: https://github.com/nodejs/node/pull/37345
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2021-02-15 23:06:35 +01:00
raisinten 9a18bf2f8c
repl: refactor to avoid unsafe array iteration
PR-URL: https://github.com/nodejs/node/pull/36663
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2021-01-18 13:29:43 -08:00
Antoine du Hamel bd6f2303f4 lib: add primordials.SafeStringIterator
PR-URL: https://github.com/nodejs/node/pull/36526
Reviewed-By: Rich Trott <rtrott@gmail.com>
2020-12-25 18:11:23 +00:00
Antoine du Hamel 825029ec59 repl: refactor to use more primordials
PR-URL: https://github.com/nodejs/node/pull/36264
Reviewed-By: Rich Trott <rtrott@gmail.com>
2020-12-02 20:22:03 +00:00
Mattias Runge-Broberg 60a97c0b42 readline: add getPrompt to get the current prompt
Since there is a setPrompt() there should be a getPrompt().
There are use-cases where it is needed to know what the
current prompt is. Adding a getPrompt() negates the need
to store the set prompt externally or read the internal
_prompt which would be bad practice.

Co-authored-by: Colin Ihrig <cjihrig@gmail.com>

PR-URL: https://github.com/nodejs/node/pull/33675
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
2020-11-10 19:46:51 +00:00
Michaël Zasso 0ddd69e2ed assert,repl: enable ecmaVersion 2021 in acorn parser
This adds support for the new logical assignment operators.

PR-URL: https://github.com/nodejs/node/pull/35827
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
2020-10-30 14:52:28 +00:00
Michaël Zasso 16b2bc01eb deps: update acorn to v8.0.4
This adds support for nullish coalescing, optional chaining and
numeric separators.
The acorn-numeric-separator plugin can be removed.

PR-URL: https://github.com/nodejs/node/pull/35791
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Shelley Vohr <codebytere@gmail.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
2020-10-27 03:26:56 +00:00
Brian White c24b74a7ab
lib: improve debuglog() performance
PR-URL: https://github.com/nodejs/node/pull/32260
Reviewed-By: James M Snell <jasnell@gmail.com>
2020-05-30 17:24:43 -04:00
Ruben Bridgewater b38d26a168 repl: show reference errors during preview
This aligns the behavior with the one in the Firefox console.
It will visualize ReferenceErrors in case the input has no possible
completion and no buffered input. That way typos can already be
highlighted before being evaluated.

Signed-off-by: Ruben Bridgewater <ruben@bridgewater.de>

PR-URL: https://github.com/nodejs/node/pull/33282
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
2020-05-15 01:48:13 +02:00
Ruben Bridgewater 80913e655f repl: improve repl preview
This aligns the REPL preview with the one used in the Chrome
DevTools console. It will now preview the output for the input
including the completion suffix as input. When pressing enter while
previewing such data, it will automatically insert the suffix
before evaluating the input. When pressing escape, that behavior
is deactivated until the input is changed.

Signed-off-by: Ruben Bridgewater <ruben@bridgewater.de>

PR-URL: https://github.com/nodejs/node/pull/33282
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
2020-05-15 01:48:08 +02:00
Ruben Bridgewater 9c18ff6440
repl: align preview with the actual executed code
This adds preview output for input that may not be wrapped.

PR-URL: https://github.com/nodejs/node/pull/32154
Reviewed-By: Shelley Vohr <codebytere@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2020-03-13 09:58:12 +01:00
Ruben Bridgewater 8fb5fe28a4
util: improve unicode support
The array grouping function relies on the width of the characters.
It was not calculated correct so far, since it used the string
length instead.
This improves the unicode output by calculating the mono-spaced
font width (other fonts might differ).

PR-URL: https://github.com/nodejs/node/pull/31319
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Steven R Loomis <srloomis@us.ibm.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
2020-01-22 15:33:03 +01:00
Ruben Bridgewater c3b702f9b4
repl: do not preview while pasting code
This makes sure no previews are triggered while pasting code. The
very last character is allowed to trigger the preview. The output
should be completely identical to the user.

PR-URL: https://github.com/nodejs/node/pull/31315
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
2020-01-13 08:59:45 +01:00
Ruben Bridgewater af5ddf2123
repl: fix preview cursor position
The cusor position was off in case the preview was exactly as long
as the current terminal was wide.

PR-URL: https://github.com/nodejs/node/pull/31293
Fixes: https://github.com/nodejs/node/issues/31291
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
2020-01-12 20:43:12 +01:00
Ruben Bridgewater fe058188a1 repl,readline: clean up code
This simplifies code that was more complicated than it had to be
and removes code that should never be reached.

PR-URL: https://github.com/nodejs/node/pull/31288
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
2020-01-11 14:06:45 -08:00
Ruben Bridgewater 84c3b87494
test: add repl tests to verify unicode support in previews
This also adds a test to verify that changed writer options also
change the preview output depending on the options.

PR-URL: https://github.com/nodejs/node/pull/31112
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2020-01-10 09:11:57 +01:00
Ruben Bridgewater 5235394e66
repl: activate previews for lines exceeding the terminal columns
This improves the completion previews by activating them for lines
that exceed the current terminal columns.
As a drive-by fix it also simplifies some statements.

PR-URL: https://github.com/nodejs/node/pull/31112
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2020-01-10 09:11:56 +01:00
Ruben Bridgewater 625a0ec5e1
readline,repl: add substring based history search
This improves the current history search feature by adding substring
based history search similar to ZSH. In case the `UP` or `DOWN`
buttons are pressed after writing a few characters, the start string
up to the current cursor is used to search the history.

All other history features work exactly as they used to.

PR-URL: https://github.com/nodejs/node/pull/31112
Fixes: https://github.com/nodejs/node/issues/28437
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2020-01-10 09:11:47 +01:00
Ruben Bridgewater 07c55bb81f
repl: improve preview length calculation
The preview had an off by one error in case colors where deactivated
and did not take fullwidth unicode characters into account when
displaying the preview.

PR-URL: https://github.com/nodejs/node/pull/31112
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2020-01-10 09:11:46 +01:00
Sebastien Ahkrin 256c9a43f4 lib: replace Set global by the primordials
PR-URL: https://github.com/nodejs/node/pull/31154
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
2020-01-04 12:41:09 -08:00
cjihrig befff8fa60
repl: use public getCursorPos()
_getCursorPos() recently became public API. This commit updates
the remaining uses of _getCursorPos() to use the public API.

PR-URL: https://github.com/nodejs/node/pull/31091
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
2019-12-25 20:12:23 -05:00
Ruben Bridgewater 9e4349e797
repl: implement reverse search
Add a reverse search that works similar to the ZSH one. It is
triggered with <ctrl> + r and <ctrl> + s. It skips duplicated history
entries and works with multiline statements. Matching entries indicate
the search parameter with an underscore and cancelling with <ctrl> + c
or escape brings back the original line.
Multiple matches in a single history entry work as well and are
matched in the order of the current search direction. The cursor is
positioned at the current match position of the history entry.
Changing the direction immediately checks for the next entry in the
expected direction from the current position on.
Entries are accepted as soon any button is pressed that doesn't
correspond with the reverse search.
The behavior is deactivated for simple terminals. They do not support
most ANSI escape codes that are necessary for this feature.

PR-URL: https://github.com/nodejs/node/pull/31006
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
2019-12-25 11:16:38 +01:00
Ruben Bridgewater ca9f12bf83
repl: fix preview of lines that exceed the terminal columns
This adds support for very long input lines to still display the
input preview correct.

PR-URL: https://github.com/nodejs/node/pull/31006
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
2019-12-25 11:15:03 +01:00