Skip to content

Commit a119519

Browse files
committed
using symbol; added test
1 parent 7d70385 commit a119519

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

lib/repl.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ const domainSet = new SafeWeakSet();
204204

205205
const kBufferedCommandSymbol = Symbol('bufferedCommand');
206206
const kContextId = Symbol('contextId');
207+
const kLoadingSymbol = Symbol('loading');
207208

208209
let addedNewListener = false;
209210

@@ -882,7 +883,7 @@ function REPLServer(prompt,
882883
self[kBufferedCommandSymbol] += cmd + '\n';
883884

884885
// code alignment
885-
const matches = self._sawKeyPress && !self._loading ?
886+
const matches = self._sawKeyPress && !self[kLoadingSymbol] ?
886887
RegExpPrototypeExec(/^\s+/, cmd) : null;
887888
if (matches) {
888889
const prefix = matches[0];
@@ -1801,10 +1802,10 @@ function defineDefaultCommands(repl) {
18011802
const stats = fs.statSync(file);
18021803
if (stats && stats.isFile()) {
18031804
_turnOnEditorMode(this);
1804-
this._loading = true;
1805+
this[kLoadingSymbol] = true;
18051806
const data = fs.readFileSync(file, 'utf8');
18061807
this.write(data);
1807-
this._loading = false;
1808+
this[kLoadingSymbol] = false;
18081809
_turnOffEditorMode(this);
18091810
this.write('\n');
18101811
} else {

test/parallel/test-repl-save-load.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,14 @@ testMe.complete('inner.o', common.mustSucceed((data) => {
6767
// Clear the REPL.
6868
putIn.run(['.clear']);
6969

70+
testMe._sawKeyPress = true;
7071
// Load the file back in.
7172
putIn.run([`.load ${saveFileName}`]);
7273

74+
// Make sure loading doesn't insert extra indentation
75+
// https://github.com/nodejs/node/issues/47673
76+
assert.equal(testMe.line, '')
77+
7378
// Make sure that the REPL data is "correct".
7479
testMe.complete('inner.o', common.mustSucceed((data) => {
7580
assert.deepStrictEqual(data, works);

0 commit comments

Comments
 (0)