diff --git a/lib/repl.js b/lib/repl.js index 6fc984fbcf0..0d1aca6aa54 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -1254,13 +1254,16 @@ function defineDefaultCommands(repl) { try { var stats = fs.statSync(file); if (stats && stats.isFile()) { + this.editorMode = true; + REPLServer.super_.prototype.setPrompt.call(this, ''); var data = fs.readFileSync(file, 'utf8'); var lines = data.split('\n'); - this.displayPrompt(); for (var n = 0; n < lines.length; n++) { if (lines[n]) this.write(`${lines[n]}\n`); } + this.turnOffEditorMode(); + this.write('\n'); } else { this.outputStream.write('Failed to load:' + file + ' is not a valid file\n'); diff --git a/test/fixtures/repl-load-multiline.js b/test/fixtures/repl-load-multiline.js new file mode 100644 index 00000000000..faedf4ee07d --- /dev/null +++ b/test/fixtures/repl-load-multiline.js @@ -0,0 +1,6 @@ +const getLunch = () => + placeOrder('tacos') + .then(eat); + +const placeOrder = (order) => Promise.resolve(order); +const eat = (food) => ''; diff --git a/test/parallel/test-repl-load-multiline.js b/test/parallel/test-repl-load-multiline.js new file mode 100644 index 00000000000..fd58a3c21dd --- /dev/null +++ b/test/parallel/test-repl-load-multiline.js @@ -0,0 +1,38 @@ +'use strict'; +const common = require('../common'); +const fixtures = require('../common/fixtures'); +const assert = require('assert'); +const repl = require('repl'); + +const command = `.load ${fixtures.path('repl-load-multiline.js')}`; +const terminalCode = '\u001b[1G\u001b[0J \u001b[1G'; +const terminalCodeRegex = new RegExp(terminalCode.replace(/\[/g, '\\['), 'g'); + +const expected = `${command} +const getLunch = () => + placeOrder('tacos') + .then(eat); +const placeOrder = (order) => Promise.resolve(order); +const eat = (food) => ''; + +undefined +`; + +let accum = ''; + +const inputStream = new common.ArrayStream(); +const outputStream = new common.ArrayStream(); + +outputStream.write = (data) => accum += data.replace('\r', ''); + +const r = repl.start({ + prompt: '', + input: inputStream, + output: outputStream, + terminal: true, + useColors: false +}); + +r.write(`${command}\n`); +assert.strictEqual(accum.replace(terminalCodeRegex, ''), expected); +r.close();