node icon indicating copy to clipboard operation
node copied to clipboard

REPL should raise Exception immediately when it gets naturally invalid multi-line.

Open hhsprings opened this issue 11 years ago β€’ 6 comments

I'm using v5.0.0 on Windows.

Of course this is invalid as javascript:

a = 3.5e
-5;
console.log(a);

But REPL enters multi-line editting mode:

> a = 3.5e
... 
... 
... .break

We have no way to exit from the mode except .break (or Ctrl-C), and .break will make nothing.

hhsprings avatar Oct 30 '15 20:10 hhsprings

confirmed the bug is present in all versions

targos avatar Oct 30 '15 20:10 targos

This particular case is not trivial to fix. REPL goes in multi-line mode because the first line generates a "Unexpected token ILLEGAL" error, which can happen in recoverable cases. See https://github.com/nodejs/node-v0.x-archive/pull/8875.

targos avatar Oct 30 '15 21:10 targos

I think it should be fixable, we should just do extra checks for ; which I feel most people will try to use as a line-ending break-out in this case. Either that or make two enter's break out. Or both.

Fwiw, you can also break out by:

  • Typing a ' or ", which will trigger a syntax error.
  • Typing just ., which will register as an invalid repl command.

Fishrock123 avatar Nov 02 '15 15:11 Fishrock123

I think it should be fixable

Good news.

; which I feel most people will try to use as a line-ending break-out in this case

I think so. I tried it actually.

Either that or make two enter's break out.

I hope this solution if we have no valid two enters.

Typing a ' or ", which will trigger a syntax error. Typing just ., which will register as an invalid repl command.

Ah, that’s true. And I noticed typing backslash will trigger a syntax error also.

hhsprings avatar Nov 02 '15 16:11 hhsprings

Proposed fix: https://github.com/nodejs/node/pull/7104

Trott avatar Jun 02 '16 06:06 Trott

#7104 landed so this should be fixed in the next 6.x release (which will be either 6.2.2 or 6.3.0).

Trott avatar Jun 04 '16 21:06 Trott