| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 0d0c57f commit 4271732
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -220,7 +220,7 @@ function REPLServer(prompt, | |||
| 220 | 220 | eval_ = eval_ || defaultEval; | |
| 221 | 221 | ||
| 222 | 222 | function defaultEval(code, context, file, cb) { | |
| 223 | - var err, result, retry = false; | ||
| 223 | + var err, result, retry = false, input = code, wrappedErr; | ||
| 224 | 224 | // first, create the Script object to check the syntax | |
| 225 | 225 | while (true) { | |
| 226 | 226 | try { | |
@@ -238,14 +238,23 @@ function REPLServer(prompt, | |||
| 238 | 238 | debug('parse error %j', code, e); | |
| 239 | 239 | if (self.replMode === exports.REPL_MODE_MAGIC && | |
| 240 | 240 | e.message === BLOCK_SCOPED_ERROR && | |
| 241 | - !retry) { | ||
| 242 | - retry = true; | ||
| 241 | + !retry || self.wrappedCmd) { | ||
| 242 | + if (self.wrappedCmd) { | ||
| 243 | + self.wrappedCmd = false; | ||
| 244 | + // unwrap and try again | ||
| 245 | + code = `${input.substring(1, input.length - 2)}\n`; | ||
| 246 | + wrappedErr = e; | ||
| 247 | + } else { | ||
| 248 | + retry = true; | ||
| 249 | + } | ||
| 243 | 250 | continue; | |
| 244 | 251 | } | |
| 245 | - if (isRecoverableError(e, self)) | ||
| 246 | - err = new Recoverable(e); | ||
| 252 | + // preserve original error for wrapped command | ||
| 253 | + const error = wrappedErr || e; | ||
| 254 | + if (isRecoverableError(error, self)) | ||
| 255 | + err = new Recoverable(error); | ||
| 247 | 256 | else | |
| 248 | - err = e; | ||
| 257 | + err = error; | ||
| 249 | 258 | } | |
| 250 | 259 | break; | |
| 251 | 260 | } | |
@@ -418,6 +427,7 @@ function REPLServer(prompt, | |||
| 418 | 427 | // to wrap it in parentheses, so that it will be interpreted as | |
| 419 | 428 | // an expression. | |
| 420 | 429 | evalCmd = '(' + evalCmd + ')\n'; | |
| 430 | + self.wrappedCmd = true; | ||
| 421 | 431 | } else { | |
| 422 | 432 | // otherwise we just append a \n so that it will be either | |
| 423 | 433 | // terminated, or continued onto the next expression if it's an | |
@@ -435,6 +445,7 @@ function REPLServer(prompt, | |||
| 435 | 445 | debug('finish', e, ret); | |
| 436 | 446 | self.memory(cmd); | |
| 437 | 447 | ||
| 448 | + self.wrappedCmd = false; | ||
| 438 | 449 | if (e && !self.bufferedCommand && cmd.trim().match(/^npm /)) { | |
| 439 | 450 | self.outputStream.write('npm should be run outside of the ' + | |
| 440 | 451 | 'node repl, in your normal shell.\n' + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -323,6 +323,8 @@ function error_test() { | |||
| 323 | 323 | { client: client_unix, send: 'function x(s) {\nreturn s.replace(/.*/,"");\n}', | |
| 324 | 324 | expect: prompt_multiline + prompt_multiline + | |
| 325 | 325 | 'undefined\n' + prompt_unix }, | |
| 326 | + { client: client_unix, send: '{ var x = 4; }', | ||
| 327 | + expect: 'undefined\n' + prompt_unix }, | ||
| 326 | 328 | ]); | |
| 327 | 329 | } | |
| 328 | 330 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments