Skip to content

Commit 2254f1a

Browse files
TrottMyles Borins
authored and
Myles Borins
committed
repl: refactor repl.js
There is some unnecessary logic in repl.js. Remove it. PR-URL: #6071 Reviewed-By: James M Snell <[email protected]>
1 parent a81fca4 commit 2254f1a

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

lib/repl.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,6 @@ function REPLServer(prompt,
396396
self.on('line', function(cmd) {
397397
debug('line %j', cmd);
398398
sawSIGINT = false;
399-
var skipCatchall = false;
400399

401400
// leading whitespaces in template literals should not be trimmed.
402401
if (self._inTemplateLiteral) {
@@ -415,11 +414,12 @@ function REPLServer(prompt,
415414
return;
416415
} else if (!self.bufferedCommand) {
417416
self.outputStream.write('Invalid REPL keyword\n');
418-
skipCatchall = true;
417+
finish(null);
418+
return;
419419
}
420420
}
421421

422-
if (!skipCatchall && (cmd || (!cmd && self.bufferedCommand))) {
422+
if (cmd || self.bufferedCommand) {
423423
var evalCmd = self.bufferedCommand + cmd;
424424
if (/^\s*\{/.test(evalCmd) && /\}\s*$/.test(evalCmd)) {
425425
// It's confusing for `{ a : 1 }` to be interpreted as a block
@@ -1002,7 +1002,7 @@ REPLServer.prototype.memory = function memory(cmd) {
10021002
// self.lines.level.length === 0
10031003
// TODO? keep a log of level so that any syntax breaking lines can
10041004
// be cleared on .break and in the case of a syntax error?
1005-
// TODO? if a log was kept, then I could clear the bufferedComand and
1005+
// TODO? if a log was kept, then I could clear the bufferedCommand and
10061006
// eval these lines and throw the syntax error
10071007
} else {
10081008
self.lines.level = [];

test/parallel/test-repl-null.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
'use strict';
2+
require('../common');
3+
const repl = require('repl');
4+
const assert = require('assert');
5+
6+
var replserver = new repl.REPLServer();
7+
8+
replserver._inTemplateLiteral = true;
9+
10+
// `null` gets treated like an empty string. (Should it? You have to do some
11+
// strange business to get it into the REPL. Maybe it should really throw?)
12+
13+
assert.doesNotThrow(() => {
14+
replserver.emit('line', null);
15+
});
16+
17+
replserver.emit('line', '.exit');

0 commit comments

Comments
 (0)