Skip to content

Commit

Permalink
using symbol; added test
Browse files Browse the repository at this point in the history
  • Loading branch information
STRd6 committed Sep 3, 2023
1 parent 7d70385 commit a119519
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ const domainSet = new SafeWeakSet();

const kBufferedCommandSymbol = Symbol('bufferedCommand');
const kContextId = Symbol('contextId');
const kLoadingSymbol = Symbol('loading');

let addedNewListener = false;

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

// code alignment
const matches = self._sawKeyPress && !self._loading ?
const matches = self._sawKeyPress && !self[kLoadingSymbol] ?
RegExpPrototypeExec(/^\s+/, cmd) : null;
if (matches) {
const prefix = matches[0];
Expand Down Expand Up @@ -1801,10 +1802,10 @@ function defineDefaultCommands(repl) {
const stats = fs.statSync(file);
if (stats && stats.isFile()) {
_turnOnEditorMode(this);
this._loading = true;
this[kLoadingSymbol] = true;
const data = fs.readFileSync(file, 'utf8');
this.write(data);
this._loading = false;
this[kLoadingSymbol] = false;
_turnOffEditorMode(this);
this.write('\n');
} else {
Expand Down
5 changes: 5 additions & 0 deletions test/parallel/test-repl-save-load.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,14 @@ testMe.complete('inner.o', common.mustSucceed((data) => {
// Clear the REPL.
putIn.run(['.clear']);

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

// Make sure loading doesn't insert extra indentation
// https://github.com/nodejs/node/issues/47673
assert.equal(testMe.line, '')

Check failure on line 76 in test/parallel/test-repl-save-load.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

'assert.equal' is restricted from being used. Use `assert.strictEqual()` rather than `assert.equal()`

Check failure on line 76 in test/parallel/test-repl-save-load.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Missing semicolon

// Make sure that the REPL data is "correct".
testMe.complete('inner.o', common.mustSucceed((data) => {
assert.deepStrictEqual(data, works);
Expand Down

0 comments on commit a119519

Please sign in to comment.