repl: Proposal for better repl (implementation)#9601
repl: Proposal for better repl (implementation)#9601princejwesley wants to merge 7 commits intonodejs:masterfrom
Conversation
|
@princejwesley +1 on this... it's going to take some time to review properly tho. Will hopefully have some comments soon |
|
@princejwesley Would it make sense to rebase this? |
|
@fhinkel sure, I'll do |
* Welcome message with version and help guide
* `displayWelcomeMessage` flag is used to
turn on/off
* Differentiate execute & continue actions
* ^M or enter key to execute the command
* ^J to continue building multiline expression.
* `executeOnTimeout` value is used to determine
the end of expression when `terminal` is false.
* Pretty stack trace.
* REPL specific stack frames are removed before
emitting to output stream.
* Recoverable errors.
* No more recoverable errors & no false positives.
* Defined commands(like .exit, .load) are meaningful
only at the top level.
* Remove `.break` command.
Welcome message template
------------------------
```js
$ node
Welcome to Node.js <<version>> (<<vm name>> VM, <<vm version>>)
Type ^M or enter to execute, ^J to continue, ^C to exit
Or try
```
Pretty stack trace
------------------
```js
$ node -i
> throw new Error('tiny stack')
Error: tiny stack
at repl:1:7
> var x y;
var x y;
^
SyntaxError: Unexpected identifier
>
```
429e046 to
48414f0
Compare
lib/repl.js
Outdated
| exports.REPL_MODE_SLOPPY = Symbol('repl-sloppy'); | ||
| exports.REPL_MODE_STRICT = Symbol('repl-strict'); | ||
| exports.REPL_MODE_MAGIC = exports.REPL_MODE_SLOPPY; | ||
| exports.REPL_MODE_MAGIC = Symbol('repl-strict'); |
| const docURL = `https://nodejs.org/dist/${version}/docs/api/repl.html`; | ||
|
|
||
| const welcome = `Welcome to Node.js ${version} (${jsEngine} VM,` + | ||
| ` ${jsEngineVersion})\nType ^M or enter to execute,` + |
There was a problem hiding this comment.
I think Node.js ${version} (${jsEngine} ${jsEngineVersion}) should suffice; the "VM" seems a bit extraneous.
lib/repl.js
Outdated
| replMap.set(magic, replMap.get(this)); | ||
| magic.context = magic.createContext(); | ||
| flat.run(tmp); // eval the flattened code | ||
| flat.run(tmp, magic); // eval the flattened code |
There was a problem hiding this comment.
The comment indentation is now out of date.
|
|
||
| function indexOfInternalFrame(frames) { | ||
| return frames.indexOf('vm.js') !== -1 || | ||
| frames.indexOf('REPLServer.') !== -1; |
There was a problem hiding this comment.
Can this interfere with userland script files named vm.js?
lib/repl.js
Outdated
| } | ||
| inherits(Recoverable, SyntaxError); | ||
| exports.Recoverable = Recoverable; | ||
| }, 'replServer.convertToContext() is deprecated'); |
There was a problem hiding this comment.
The DEP0024 code was removed accidentally.
doc/api/repl.md
Outdated
| displayed. Defaults to `false`. | ||
| ```js | ||
| > node | ||
| Welcome to Node.js <<version>> (<<vm name>> VM, <<vm version>>) |
doc/api/repl.md
Outdated
| ```js | ||
| $ node | ||
| > const a = [1, 2, 3]; | ||
| Welcome to Node.js v6.5.0 (v8 VM, 5.1.281.81) |
lib/repl.js
Outdated
| this.run = function(data) { | ||
| for (var n = 0; n < data.length; n++) | ||
| this.emit('data', `${data[n]}\n`); | ||
| this.run = (data, repl) => { |
There was a problem hiding this comment.
Can this function be put into the prototype object?
| * `<ctrl>-C` - When pressed once, it will break the current command. | ||
| When pressed twice on a blank line, has the same effect as the `.exit` | ||
| command. | ||
| * `<ctrl>-D` - Has the same effect as the `.exit` command. |
There was a problem hiding this comment.
^M and ^J should be documented.
| repl.start({prompt: '> ', eval: myEval}); | ||
| ``` | ||
|
|
||
| #### Recoverable Errors |
There was a problem hiding this comment.
I for one am not very happy this feature got removed. In recent versions of Chrome, a similar function just got added (instead of having to type Shift+Enter, the prompt automatically recognizes line continuation), and to have to type an awkward Ctrl+J for the same feature does not sound very appealing to me.
If this change is here to stay, may I suggest we at least add support to Shift+Enter also/instead? It is the syntax in most IM apps, and also in most developer consoles.
There was a problem hiding this comment.
@TimothyGu we discussed this option here. Shift+Enter is not possible
|
Ping @princejwesley this needs a rebase. Do you still want to follow up on this? |
|
@BridgeAR @TimothyGu point is valid, it will force user to use extra control key to execute or continue. |
|
@princejwesley @BridgeAR @TimothyGu This PR is comprised of a lot of incremental improvements. Some of these are still somewhat controversial. In order to move forward with some of the items that are universally agreed on (e.g. better stack traces and improved welcome message), would it perhaps be better and more fruitful in the short term to submit those as individual PRs? @princejwesley if you are not opposed, I could take a look at this. |
|
@lance Agreed. |
|
@lance sure |
|
Due to the various reasons noted above, I'm closing this PR. Feel free to reopen if you would like to continue work on it. |
When a user executes code in the REPLServer which generates an exception, there is no need to display the REPLServer internal stack frames. PR-URL: #15351 Reviewed-By: Prince John Wesley <princejohnwesley@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Refs: #9601
When a user executes code in the REPLServer which generates an exception, there is no need to display the REPLServer internal stack frames. PR-URL: nodejs/node#15351 Reviewed-By: Prince John Wesley <princejohnwesley@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Refs: nodejs/node#9601
When a user executes code in the REPLServer which generates an exception, there is no need to display the REPLServer internal stack frames. PR-URL: #15351 Backport-PR-URL: #16457 Reviewed-By: Prince John Wesley <princejohnwesley@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Refs: #9601
Checklist
make -j4 test(UNIX), orvcbuild test nosign(Windows) passesAffected core subsystem(s)
repl
Description of change
displayWelcomeMessageflag is used toturn on/off
executeOnTimeoutvalue is used to determinethe end of expression when
terminalis false.emitting to output stream.
.breakis removed - no more get stuckWelcome message template
Pretty stack trace
Refs: #8195
Original WIP PR: #8504