-
Notifications
You must be signed in to change notification settings - Fork 30k
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
repl: allow multiline arrow functions in .load #14861
Conversation
lib/repl.js
Outdated
@@ -1256,13 +1256,16 @@ function defineDefaultCommands(repl) { | |||
try { | |||
var stats = fs.statSync(file); | |||
if (stats && stats.isFile()) { | |||
this.editorMode = true; | |||
REPLServer.super_.prototype.setPrompt.call(this, ''); |
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.
this is just so it'll be "pretty", right?
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.
Yes, and it duplicates the behavior in the .editor
command. As I was working on this, I thought this could benefit from a little refactoring so that there is an enableEditorMode()
function that handles everything in one place. Do you think it's needed?
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.
It would feel natural to have the enableEditorMode
but I think this should not block the PR from landing.
const assert = require('assert'); | ||
const repl = require('repl'); | ||
|
||
testLoadMultiline(); |
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.
You could replace this with an IIFE or even simply a block scope:
{
const command = `...`
...
r.close();
}
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.
Why even scope it all, now that you mention it? It's not leaky.
So this actually enables any multiline expression through |
Isn't #14503 a better solution? (Load and editor mode?) |
@Fishrock123 oh I hadn't seen that PR referenced in #14022 and didn't know about it. It looks fine too. I guess it's a question of surface area vs. subtle behavior changes. Modifying I lean towards reduced surface area, and don't really see how the behavior changes would have an external effect. Always hard to predict the future though and somewhere some code may depend on the My philosophical preference aside, if #14503 is already on its way to landing, and folks feel good about it I am fine with this being closed. I didn't mean to jump into something that was already in flight. |
I suppose the question would be, does If not, |
Well, function foo() {
return {
bar: function() {
return 'foobar'
}
}
}
const foobar = foo()
.bar();
console.log(foobar); Running this as
|
I think the answer is yes, multiline.jsconst foo = console
.log('foo'); d:\code\node$ node
> .load multiline.js
> const foo = console
undefined
> .log('foo');
Invalid REPL keyword
> |
Hmmm, in that case this may be the better approach. I've never actually used |
CI: https://ci.nodejs.org/job/node-test-pull-request/9743/ EDIT: CI failures all seem unrelated to this change |
I agree that this is likely the better of the approaches, although longer term I think a fairly major overhaul of this part of the code may be warranted. |
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.
LGTM and I think this is definitely the right approach.
lib/repl.js
Outdated
for (var n = 0; n < lines.length; n++) { | ||
if (lines[n]) | ||
this.write(`${lines[n]}\n`); | ||
} | ||
this.turnOffEditorMode(); | ||
this.write('\n'); |
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.
Does turning the turnOffEditorMode
and write("\n")
around also change the order of the blank line and the undefined
(looking at the test)? If so, I think that would be nice but it is not a blocker at all.
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.
@BridgeAR rather than hold up this PR, I will do this separately.
lib/repl.js
Outdated
@@ -1256,13 +1256,16 @@ function defineDefaultCommands(repl) { | |||
try { | |||
var stats = fs.statSync(file); | |||
if (stats && stats.isFile()) { | |||
this.editorMode = true; | |||
REPLServer.super_.prototype.setPrompt.call(this, ''); |
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.
It would feel natural to have the enableEditorMode
but I think this should not block the PR from landing.
Ping @lance |
The `.load` command would fail with any file that contains multiline `.` operator expressions. This was particularly noticeable when chaining promises or multi-line arrow expressions. This change Forces the REPL to be in `editorMode` while loading a file from disk using the `.load` command. Fixes: #14022 PR-URL: #14861 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Refael Ackermann <refack@gmail.com>
Landed in 4bd44c1 |
The `.load` command would fail with any file that contains multiline `.` operator expressions. This was particularly noticeable when chaining promises or multi-line arrow expressions. This change Forces the REPL to be in `editorMode` while loading a file from disk using the `.load` command. Fixes: nodejs/node#14022 PR-URL: nodejs/node#14861 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Refael Ackermann <refack@gmail.com>
The `.load` command would fail with any file that contains multiline `.` operator expressions. This was particularly noticeable when chaining promises or multi-line arrow expressions. This change Forces the REPL to be in `editorMode` while loading a file from disk using the `.load` command. Fixes: #14022 PR-URL: #14861 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Refael Ackermann <refack@gmail.com>
The `.load` command would fail with any file that contains multiline `.` operator expressions. This was particularly noticeable when chaining promises or multi-line arrow expressions. This change Forces the REPL to be in `editorMode` while loading a file from disk using the `.load` command. Fixes: #14022 PR-URL: #14861 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Refael Ackermann <refack@gmail.com>
Should this be backported to |
@MylesBorins I will submit a backport PR for it this week. |
The `.load` command would fail with any file that contains multiline `.` operator expressions. This was particularly noticeable when chaining promises or multi-line arrow expressions. This change Forces the REPL to be in `editorMode` while loading a file from disk using the `.load` command. Fixes: #14022 Backport-PR-URL: #15775 PR-URL: #14861 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Refael Ackermann <refack@gmail.com>
The `.load` command would fail with any file that contains multiline `.` operator expressions. This was particularly noticeable when chaining promises or multi-line arrow expressions. This change Forces the REPL to be in `editorMode` while loading a file from disk using the `.load` command. Fixes: #14022 Backport-PR-URL: #15775 PR-URL: #14861 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Refael Ackermann <refack@gmail.com>
Forces the REPL to be in
editorMode
while loading a file from disk using the.load
command.Fixes: #14022
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
repl