abicky / nodejs-repl.el

Run Node.js REPL and communicate with the process
190 stars 38 forks source link

nodejs-repl-send-last-sexp fails in certain cases #12

Closed lazywithclass closed 7 years ago

lazywithclass commented 7 years ago

First of all thanks for this tool!

I am having a hard time figuring out how to use nodejs-repl-send-last-sexp, for example if I run it on the following:

[1,2,3].map(function(number) {
  return number * 2
})
// <-- from here

then this is evaluated

function(number) {
  return number * 2
}

while I would've liked the whole thing. Is there any way to have this? One could use nodejs-repl-send-region, as a fallback, is that intended?

I've had a look at the source code and the function responsible to figure out the extension of the sexp seems to be backward-sexp.

abicky commented 7 years ago

Thank you for your feedback! I've fixed the behavior in https://github.com/abicky/nodejs-repl.el/commit/91b19d2e563931a150ff6ebcf60e58543e1dec9c. Please try version 0.1.3.

lazywithclass commented 7 years ago

Hi @abicky thanks for this!

It does not work for things like

const answer = () => 41 + 1

const print = what => {
  console.log(what)
  return what
}

while instead it works for

const print = (what) => { // note the parens around what
  console.log(what)
  return what
}

But I think it's fine like this for now!

abicky commented 7 years ago

I've released version 0.1.5 and it supports the syntax of allow function as below:

const answer = () => 41 + 1  /* caret is here */ //=> 1
const answer = () => { return 41 + 1 }  /* caret is here */ //=> [Function] (() => { return 41 + 1 })
const answer = () => { return 41 /* caret is here */ + 1 }  //=> 41
const answer = () => { /* caret is here */ return 41 + 1 }  //=> No proper expression is found backward

By the way, I've renamed nodejs-repl-send-last-sexp to nodejs-repl-send-last-expression and marked nodejs-repl-send-last-sexp as deprecated.

lazywithclass commented 7 years ago

Thanks a lot for this addition!