Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34.2k
repl: Proposal for better repl (implementation)#9601
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
Uh oh!
There was an error while loading. Please reload this page.
Conversation
princejwesley commented Nov 14, 2016 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
jasnell commented Nov 18, 2016
@princejwesley +1 on this... it's going to take some time to review properly tho. Will hopefully have some comments soon |
fhinkel commented Mar 26, 2017
@princejwesley Would it make sense to rebase this? |
princejwesley commented Mar 26, 2017
@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 48414f0Compareprincejwesley commented Apr 2, 2017
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'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this change intended?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope!
| constdocURL=`https://nodejs.org/dist/${version}/docs/api/repl.html`; | ||
| constwelcome=`Welcome to Node.js ${version} (${jsEngine} VM,`+ | ||
| ` ${jsEngineVersion})\nType ^M or enter to execute,`+ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment indentation is now out of date.
| functionindexOfInternalFrame(frames){ | ||
| returnframes.indexOf('vm.js')!==-1|| | ||
| frames.indexOf('REPLServer.')!==-1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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>>) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The VM should be gone now.
doc/api/repl.md Outdated
| ```js | ||
| $ node | ||
| >consta= [1, 2, 3]; | ||
| Welcome to Node.js v6.5.0 (v8 VM, 5.1.281.81) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto.
lib/repl.js Outdated
| this.run=function(data){ | ||
| for(varn=0;n<data.length;n++) | ||
| this.emit('data',`${data[n]}\n`); | ||
| this.run=(data,repl)=>{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
^M and ^J should be documented.
| repl.start({prompt:'> ', eval: myEval}); | ||
| ``` | ||
| #### Recoverable Errors |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TimothyGu we discussed this option here. Shift+Enter is not possible
BridgeAR commented Aug 26, 2017
Ping @princejwesley this needs a rebase. Do you still want to follow up on this? |
princejwesley commented Aug 28, 2017
@BridgeAR@TimothyGu point is valid, it will force user to use extra control key to execute or continue. |
lance commented Sep 6, 2017
@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. |
TimothyGu commented Sep 6, 2017
@lance Agreed. |
princejwesley commented Sep 7, 2017
@lance sure |
lance commented Sep 14, 2017
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 <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> 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 <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> 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 <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> 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