denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
95.43k stars 5.3k forks source link

repl: parse error: Unexpected token `<eof>` (unfinished math expression) #11594

Open ghost opened 3 years ago

ghost commented 3 years ago

Reproduce

  1. In Deno REPL, issue: > 1 %
  2. See parse error.
Error description ``` parse error: Unexpected token 'eof'. Expected this, import, async, function, [ for array literal, { for object literal, @ for decorator, function, class, null, true, false, number, bigint, string, regexp, ` for template literal, (, or an identifier at 1:2 ```

grafik

I would expect a new line, just like node does: grafik

Is this working as expected? Would this be eligible as enhancement for REPL?

dsherret commented 3 years ago

Chrome's REPL also seems to work this way. It also doesn't work in old versions of Deno before type stripping:

Deno 1.7.5
exit using ctrl+d or close()
> 1 %
Uncaught SyntaxError: Unexpected end of input

We might be able to solve this by looking for a trailing operator at the end of the line and if that's the case we can continue reading input (before sending it to type stripping and evaluation). I don't think it would be hard to do.