Don't strip spaces for regular REPL input#2246
Don't strip spaces for regular REPL input#2246edef1c wants to merge 1 commit intonodejs:masterfrom edef1c:fix-repl-dots
Conversation
This means ` .method()` isn't misparsed as a REPL keyword, and significantly improves the usability of `.load`.
|
Expected (and this patch's) behaviour: Current behaviour: |
|
Oops, probably my fault. Hmm, will need to fix this before the 2.5.0 release. |
|
@Fishrock123 Nah, this has been the case for years. |
|
Hmmm. I knew about this weak REPL command check when I submitted REPL bug fixes PR, but I could not come up with a practical usecase. So, apart from removing the check mentioned in this PR, it would be better if we improved the REPL command check with a regular expression. Instead of if we had it would be better. Also, I would recommend including a test as well. Edit: To me, stripping spaces is not the actual problem here (even though leaving the spaces when we are not inside a string literal is not a big deal), but considering the current line of input as a REPL command just because it starts with Edit 2: It would be better if the RegEx is |
|
@thefourtheye you can easily run into this issue by copy-pasting something in the REPL |
|
@targos Yup, I understand that after seeing the example shown in the PR. That is why using a RegEx to validate the string should work here. What do you think? |
|
@thefourtheye Yes a RegExp could be the solution. We just need to make sure that it does not identify too much valid JS as a REPL command. |
Fixes the problem shown in nodejs#2246 The REPL module, treats any line which starts with a dot character as a REPL command and this limits the ability to use function calls in the next lines to improve readability. This patch checks if the current line starts with `.` and then a series of lowercase letters and then any characters. For example: > process.version 'v2.4.0' > function sum(arr) { ... return arr ... .reduce(function(c, x) { return x + c; }); Invalid REPL keyword undefined but then, this patches allows this: > process.version 'v2.4.1-pre' > function sum(arr) { ... return arr ... .reduce(function(c, x) { return x + c; }); ... } undefined
|
@nathan7 @thefourtheye @Fishrock123 ... what's the status on this one? |
|
@Fishrock123 @thefourtheye |
|
@princejwesley I proposed almost the same in #2254. But the problem is, load and save accept filenames as inputs following them. If they had |
|
@jasnell @thefourtheye #3835 fixed this issue. |
This means
.method()isn't misparsed as a REPL keyword, and significantly improves the usability of.load.