Skip to content

Commit c5afd98

Browse files
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 e67fee0 commit c5afd98

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
@@ -398,7 +398,6 @@ function REPLServer(prompt,
398398
self.on('line', function(cmd) {
399399
debug('line %j', cmd);
400400
sawSIGINT = false;
401-
var skipCatchall = false;
402401

403402
// leading whitespaces in template literals should not be trimmed.
404403
if (self._inTemplateLiteral) {
@@ -417,11 +416,12 @@ function REPLServer(prompt,
417416
return;
418417
} else if (!self.bufferedCommand) {
419418
self.outputStream.write('Invalid REPL keyword\n');
420-
skipCatchall = true;
419+
finish(null);
420+
return;
421421
}
422422
}
423423

424-
if (!skipCatchall && (cmd || (!cmd && self.bufferedCommand))) {
424+
if (cmd || self.bufferedCommand) {
425425
var evalCmd = self.bufferedCommand + cmd;
426426
if (/^\s*\{/.test(evalCmd) && /\}\s*$/.test(evalCmd)) {
427427
// It's confusing for `{ a : 1 }` to be interpreted as a block
@@ -1022,7 +1022,7 @@ REPLServer.prototype.memory = function memory(cmd) {
10221022
// self.lines.level.length === 0
10231023
// TODO? keep a log of level so that any syntax breaking lines can
10241024
// be cleared on .break and in the case of a syntax error?
1025-
// TODO? if a log was kept, then I could clear the bufferedComand and
1025+
// TODO? if a log was kept, then I could clear the bufferedCommand and
10261026
// eval these lines and throw the syntax error
10271027
} else {
10281028
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)