|
|
@ -238,7 +238,33 @@ function REPLServer(prompt, |
|
|
|
|
|
|
|
eval_ = eval_ || defaultEval; |
|
|
|
|
|
|
|
function preprocess(code) { |
|
|
|
let cmd = code; |
|
|
|
if (/^\s*\{/.test(cmd) && /\}\s*$/.test(cmd)) { |
|
|
|
// It's confusing for `{ a : 1 }` to be interpreted as a block
|
|
|
|
// statement rather than an object literal. So, we first try
|
|
|
|
// to wrap it in parentheses, so that it will be interpreted as
|
|
|
|
// an expression.
|
|
|
|
cmd = `(${cmd})`; |
|
|
|
self.wrappedCmd = true; |
|
|
|
} else { |
|
|
|
// Mitigate https://github.com/nodejs/node/issues/548
|
|
|
|
cmd = cmd.replace( |
|
|
|
/^\s*function(?:\s*(\*)\s*|\s+)([^(]+)/, |
|
|
|
(_, genStar, name) => `var ${name} = function ${genStar || ''}${name}` |
|
|
|
); |
|
|
|
} |
|
|
|
// Append a \n so that it will be either
|
|
|
|
// terminated, or continued onto the next expression if it's an
|
|
|
|
// unexpected end of input.
|
|
|
|
return `${cmd}\n`; |
|
|
|
} |
|
|
|
|
|
|
|
function defaultEval(code, context, file, cb) { |
|
|
|
// Remove trailing new line
|
|
|
|
code = code.replace(/\n$/, ''); |
|
|
|
code = preprocess(code); |
|
|
|
|
|
|
|
var err, result, retry = false, input = code, wrappedErr; |
|
|
|
// first, create the Script object to check the syntax
|
|
|
|
|
|
|
@ -499,8 +525,7 @@ function REPLServer(prompt, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
var evalCmd = self.bufferedCommand + cmd; |
|
|
|
evalCmd = preprocess(evalCmd); |
|
|
|
const evalCmd = self.bufferedCommand + cmd + '\n'; |
|
|
|
|
|
|
|
debug('eval %j', evalCmd); |
|
|
|
self.eval(evalCmd, self.context, 'repl', finish); |
|
|
@ -557,28 +582,6 @@ function REPLServer(prompt, |
|
|
|
// Display prompt again
|
|
|
|
self.displayPrompt(); |
|
|
|
} |
|
|
|
|
|
|
|
function preprocess(code) { |
|
|
|
let cmd = code; |
|
|
|
if (/^\s*\{/.test(cmd) && /\}\s*$/.test(cmd)) { |
|
|
|
// It's confusing for `{ a : 1 }` to be interpreted as a block
|
|
|
|
// statement rather than an object literal. So, we first try
|
|
|
|
// to wrap it in parentheses, so that it will be interpreted as
|
|
|
|
// an expression.
|
|
|
|
cmd = `(${cmd})`; |
|
|
|
self.wrappedCmd = true; |
|
|
|
} else { |
|
|
|
// Mitigate https://github.com/nodejs/node/issues/548
|
|
|
|
cmd = cmd.replace( |
|
|
|
/^\s*function(?:\s*(\*)\s*|\s+)([^(]+)/, |
|
|
|
(_, genStar, name) => `var ${name} = function ${genStar || ''}${name}` |
|
|
|
); |
|
|
|
} |
|
|
|
// Append a \n so that it will be either
|
|
|
|
// terminated, or continued onto the next expression if it's an
|
|
|
|
// unexpected end of input.
|
|
|
|
return `${cmd}\n`; |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
self.on('SIGCONT', function onSigCont() { |
|
|
|