I had just something to test with deno repl. I was trying this code:
objWithFunc =
{ sayHi: function() {
console.log(`hi, ${this.name}!;`;
console.log(this))
},
name: 'Joel'
};
obviously it contained syntax errors, but I didn't know that (primarily because I just typed all that in one line) until I ran this code again with node repl and threw an error, while Deno stayed silent. It just does nothing and allows you to type anything more, like as if the code has not been finished yet:
It throws an error on node. But it does not on deno. I think the expected action should be to throw an error.
$ uname -a
Darwin 7o 18.7.0 Darwin Kernel Version 18.7.0: Tue Aug 20 16:57:14 PDT 2019; root:xnu-4903.271.2~2/RELEASE_X86_64 x86_64
$ deno -v
deno: 0.20.0
v8: 7.9.218
typescript: 3.6.3
Smaller examples:
> console.log(1 ;
> console.log(1 @
> console.log(1 '
Happens for any unexpected token in place of an argument comma or closing bracket.
The REPL will ask for more input despite the unexpected token, and obviously nothing you enter will make it finish parsing.
This is unfortunately due to that current REPL relies on V8 compile error messages to "guess" if we should wait for more user input (https://github.com/denoland/deno/blob/b3331e81d920ac6654545094c31bfe07abc750d5/cli/js/repl.ts#L58-L70), instead of having a JS parser ourselves. Basically given code that looks like
console.log(1 ;
)
error message from V8 still believes that a ) is missing.
Node uses Acorn to do the recoverable error check: https://github.com/nodejs/node/blob/57c70835af07485948bb3690b78adbf52d2205cd/lib/internal/repl/utils.js
Maybe we should also vendor a JS parser ourselves (ideally even with TS, though currently we don't support TS in REPL)
@nayeemrmn @kevinkassimo Ahhh... thank y'all for the clarification. Now I understand why.
CC @caspervonb could you look into this issue?
So we no longer use errors to validate multi line inputs, but instead use brace matching so this is fixed.
Example on master yields
> objWithFunc =
{ sayHi: function() {
console.log(`hi, ${this.name}!;`;
console.log(this))
},
name: 'Joel'
};
Uncaught SyntaxError: missing ) after argument list