Skip to content

Commit

Permalink
repl: Don't accumulate excess indentation in .load
Browse files Browse the repository at this point in the history
When using .load the REPL would accumulate indentation with each line
including the indentation from all previous lines. Now it keeps the
indentation at the correct level.

Fixes: #47673
  • Loading branch information
STRd6 committed Sep 2, 2023
1 parent 0add7a8 commit 7d70385
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,7 @@ function REPLServer(prompt,
self[kBufferedCommandSymbol] += cmd + '\n';

// code alignment
const matches = self._sawKeyPress ?
const matches = self._sawKeyPress && !self._loading ?
RegExpPrototypeExec(/^\s+/, cmd) : null;
if (matches) {
const prefix = matches[0];
Expand Down Expand Up @@ -1801,8 +1801,10 @@ function defineDefaultCommands(repl) {
const stats = fs.statSync(file);
if (stats && stats.isFile()) {
_turnOnEditorMode(this);
this._loading = true;
const data = fs.readFileSync(file, 'utf8');
this.write(data);
this._loading = false;
_turnOffEditorMode(this);
this.write('\n');
} else {
Expand Down

0 comments on commit 7d70385

Please sign in to comment.