GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — repl: support standalone blocks · nodejs/node@4271732

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib
    • repl.js
  • test/parallel
    • test-repl.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/repl.js‎

Copy file name to clipboardExpand all lines: lib/repl.js
+17-6Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ function REPLServer(prompt,
220220
eval_ = eval_ || defaultEval;
221221

222222
function defaultEval(code, context, file, cb) {
223-
var err, result, retry = false;
223+
var err, result, retry = false, input = code, wrappedErr;
224224
// first, create the Script object to check the syntax
225225
while (true) {
226226
try {
@@ -238,14 +238,23 @@ function REPLServer(prompt,
238238
debug('parse error %j', code, e);
239239
if (self.replMode === exports.REPL_MODE_MAGIC &&
240240
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+
}
243250
continue;
244251
}
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);
247256
else
248-
err = e;
257+
err = error;
249258
}
250259
break;
251260
}
@@ -418,6 +427,7 @@ function REPLServer(prompt,
418427
// to wrap it in parentheses, so that it will be interpreted as
419428
// an expression.
420429
evalCmd = '(' + evalCmd + ')\n';
430+
self.wrappedCmd = true;
421431
} else {
422432
// otherwise we just append a \n so that it will be either
423433
// terminated, or continued onto the next expression if it's an
@@ -435,6 +445,7 @@ function REPLServer(prompt,
435445
debug('finish', e, ret);
436446
self.memory(cmd);
437447

448+
self.wrappedCmd = false;
438449
if (e && !self.bufferedCommand && cmd.trim().match(/^npm /)) {
439450
self.outputStream.write('npm should be run outside of the ' +
440451
'node repl, in your normal shell.\n' +
Collapse file

‎test/parallel/test-repl.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-repl.js
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,8 @@ function error_test() {
323323
{ client: client_unix, send: 'function x(s) {\nreturn s.replace(/.*/,"");\n}',
324324
expect: prompt_multiline + prompt_multiline +
325325
'undefined\n' + prompt_unix },
326+
{ client: client_unix, send: '{ var x = 4; }',
327+
expect: 'undefined\n' + prompt_unix },
326328
]);
327329
}
328330

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.