Skip to content

Commit c5b0df9

Browse files
committed
fixup! simplify code further
1 parent 10af9e6 commit c5b0df9

2 files changed

Lines changed: 7 additions & 15 deletions

File tree

lib/internal/readline/interface.js

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ const kYank = Symbol('_yank');
144144
const kYanking = Symbol('_yanking');
145145
const kYankPop = Symbol('_yankPop');
146146
const kNormalizeHistoryLineEndings = Symbol('_normalizeHistoryLineEndings');
147-
const kDenormalizeHistoryLineEndings = Symbol('_denormalizeHistoryLineEndings');
148147

149148
function InterfaceConstructor(input, output, completer, terminal) {
150149
this[kSawReturnAt] = 0;
@@ -461,13 +460,8 @@ class Interface extends InterfaceConstructor {
461460
}
462461

463462
// Convert newlines to a consistent format for history storage
464-
[kNormalizeHistoryLineEndings](line) {
465-
return StringPrototypeReplaceAll(line, '\n', '\r');
466-
}
467-
468-
// Convert newlines back to the format expected by the UI
469-
[kDenormalizeHistoryLineEndings](line) {
470-
return StringPrototypeReplaceAll(line, '\r', '\n');
463+
[kNormalizeHistoryLineEndings](line, from, to) {
464+
return StringPrototypeReplaceAll(line, from, to);
471465
}
472466

473467
[kAddHistory]() {
@@ -478,7 +472,7 @@ class Interface extends InterfaceConstructor {
478472

479473
// If the trimmed line is empty then return the line
480474
if (StringPrototypeTrim(this.line).length === 0) return this.line;
481-
const normalizedLine = this[kNormalizeHistoryLineEndings](this.line);
475+
const normalizedLine = this[kNormalizeHistoryLineEndings](this.line, '\n', '\r');
482476

483477
if (this.history.length === 0 || this.history[0] !== normalizedLine) {
484478
if (this[kLastCommandErrored] && this.historyIndex === 0) {
@@ -1021,7 +1015,7 @@ class Interface extends InterfaceConstructor {
10211015
if (index === -1) {
10221016
this[kSetLine](search);
10231017
} else {
1024-
this[kSetLine](this[kDenormalizeHistoryLineEndings](this.history[index]));
1018+
this[kSetLine](this[kNormalizeHistoryLineEndings](this.history[index], '\r', '\n'));
10251019
}
10261020
this.historyIndex = index;
10271021
this.cursor = this.line.length; // Set cursor to end of line.
@@ -1065,7 +1059,7 @@ class Interface extends InterfaceConstructor {
10651059
if (index === this.history.length) {
10661060
this[kSetLine](search);
10671061
} else {
1068-
this[kSetLine](this[kDenormalizeHistoryLineEndings](this.history[index]));
1062+
this[kSetLine](this[kNormalizeHistoryLineEndings](this.history[index], '\r', '\n'));
10691063
}
10701064
this.historyIndex = index;
10711065
this.cursor = this.line.length; // Set cursor to end of line.
@@ -1511,5 +1505,4 @@ module.exports = {
15111505
kMultilinePrompt,
15121506
kLastCommandErrored,
15131507
kNormalizeHistoryLineEndings,
1514-
kDenormalizeHistoryLineEndings,
15151508
};

lib/repl.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,6 @@ function REPLServer(prompt,
359359
this.editorMode = false;
360360
// Context id for use with the inspector protocol.
361361
this[kContextId] = undefined;
362-
this[kLastCommandErrored] = false;
363362

364363
if (this.breakEvalOnSigint && eval_) {
365364
// Allowing this would not reflect user expectations.
@@ -933,6 +932,8 @@ function REPLServer(prompt,
933932
debug('finish', e, ret);
934933
ReflectApply(_memory, self, [cmd]);
935934

935+
self[kLastCommandErrored] = false;
936+
936937
if (e && !self[kBufferedCommandSymbol] &&
937938
StringPrototypeStartsWith(StringPrototypeTrim(cmd), 'npm ') &&
938939
!(e instanceof Recoverable)
@@ -977,8 +978,6 @@ function REPLServer(prompt,
977978
if (e) {
978979
self._domain.emit('error', e.err || e);
979980
self[kLastCommandErrored] = true;
980-
} else {
981-
self[kLastCommandErrored] = false;
982981
}
983982

984983
// Clear buffer if no SyntaxErrors

0 commit comments

Comments
 (0)