repl: refactor repl.js
There is some unnecessary logic in repl.js. Remove it. PR-URL: https://github.com/nodejs/node/pull/6071 Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
e67fee0fb5
commit
c5afd98b48
@ -398,7 +398,6 @@ function REPLServer(prompt,
|
|||||||
self.on('line', function(cmd) {
|
self.on('line', function(cmd) {
|
||||||
debug('line %j', cmd);
|
debug('line %j', cmd);
|
||||||
sawSIGINT = false;
|
sawSIGINT = false;
|
||||||
var skipCatchall = false;
|
|
||||||
|
|
||||||
// leading whitespaces in template literals should not be trimmed.
|
// leading whitespaces in template literals should not be trimmed.
|
||||||
if (self._inTemplateLiteral) {
|
if (self._inTemplateLiteral) {
|
||||||
@ -417,11 +416,12 @@ function REPLServer(prompt,
|
|||||||
return;
|
return;
|
||||||
} else if (!self.bufferedCommand) {
|
} else if (!self.bufferedCommand) {
|
||||||
self.outputStream.write('Invalid REPL keyword\n');
|
self.outputStream.write('Invalid REPL keyword\n');
|
||||||
skipCatchall = true;
|
finish(null);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!skipCatchall && (cmd || (!cmd && self.bufferedCommand))) {
|
if (cmd || self.bufferedCommand) {
|
||||||
var evalCmd = self.bufferedCommand + cmd;
|
var evalCmd = self.bufferedCommand + cmd;
|
||||||
if (/^\s*\{/.test(evalCmd) && /\}\s*$/.test(evalCmd)) {
|
if (/^\s*\{/.test(evalCmd) && /\}\s*$/.test(evalCmd)) {
|
||||||
// It's confusing for `{ a : 1 }` to be interpreted as a block
|
// It's confusing for `{ a : 1 }` to be interpreted as a block
|
||||||
@ -1022,7 +1022,7 @@ REPLServer.prototype.memory = function memory(cmd) {
|
|||||||
// self.lines.level.length === 0
|
// self.lines.level.length === 0
|
||||||
// TODO? keep a log of level so that any syntax breaking lines can
|
// TODO? keep a log of level so that any syntax breaking lines can
|
||||||
// be cleared on .break and in the case of a syntax error?
|
// be cleared on .break and in the case of a syntax error?
|
||||||
// TODO? if a log was kept, then I could clear the bufferedComand and
|
// TODO? if a log was kept, then I could clear the bufferedCommand and
|
||||||
// eval these lines and throw the syntax error
|
// eval these lines and throw the syntax error
|
||||||
} else {
|
} else {
|
||||||
self.lines.level = [];
|
self.lines.level = [];
|
||||||
|
17
test/parallel/test-repl-null.js
Normal file
17
test/parallel/test-repl-null.js
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
'use strict';
|
||||||
|
require('../common');
|
||||||
|
const repl = require('repl');
|
||||||
|
const assert = require('assert');
|
||||||
|
|
||||||
|
var replserver = new repl.REPLServer();
|
||||||
|
|
||||||
|
replserver._inTemplateLiteral = true;
|
||||||
|
|
||||||
|
// `null` gets treated like an empty string. (Should it? You have to do some
|
||||||
|
// strange business to get it into the REPL. Maybe it should really throw?)
|
||||||
|
|
||||||
|
assert.doesNotThrow(() => {
|
||||||
|
replserver.emit('line', null);
|
||||||
|
});
|
||||||
|
|
||||||
|
replserver.emit('line', '.exit');
|
Loading…
x
Reference in New Issue
Block a user