abicky / nodejs-repl.el

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

More robust multi-line regions #17

Closed Apteryks closed 6 years ago

Apteryks commented 6 years ago

I've had nodejs-repl-send-region fail when the region included a lambda definition. This won't run, but it might give you an idea:

supertest(options.shoreApi)
    .post('/Test/Enpoint')
    .set('Content-type', 'application/json')
    .send(testUser)
    .expect(status.OK)
    .end((err, res) => {
        if (err) {
            console.error(err);
        }
        console.log(res.body);
});

This would fail with the error message:

>     .post('/Test/Enpoint')
Invalid REPL keyword
>     .set('Content-type', 'application/json')
Invalid REPL keyword
>     .send(testUser)
Invalid REPL keyword
>     .expect(status.OK)
Invalid REPL keyword
>     .end((err, res) => {
Invalid REPL keyword
>         if (err) {
.....             console.error(err);
.....         }
ReferenceError: err is not defined
>         console.log(res.body);
ReferenceError: res is not defined
> });
});
^

SyntaxError: Unexpected token }

> 

Since NodeJS 6.4.0, it is possible to work around this by wrapping the multi-line string in a ".editor" multi-line-string Control-D (EOF) block.

I will send a PR that implement this.

abicky commented 6 years ago

I've released 0.1.7 including https://github.com/abicky/nodejs-repl.el/pull/18.