diff --git a/lib/repl.js b/lib/repl.js index 127fd80bf82f65..f841b3e3eff34b 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -1301,15 +1301,16 @@ function defineDefaultCommands(repl) { try { var stats = fs.statSync(file); if (stats && stats.isFile()) { - var self = this; + this.editorMode = true; + REPLServer.super_.prototype.setPrompt.call(this, ''); var data = fs.readFileSync(file, 'utf8'); var lines = data.split('\n'); - this.displayPrompt(); - lines.forEach(function(line) { - if (line) { - self.write(line + '\n'); - } - }); + 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 00000000000000..faedf4ee07d106 --- /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 00000000000000..3a60c7b4576a79 --- /dev/null +++ b/test/parallel/test-repl-load-multiline.js @@ -0,0 +1,39 @@ +'use strict'; +const common = require('../common'); +const path = require('path'); +const fixtures = common.fixturesDir; +const assert = require('assert'); +const repl = require('repl'); + +const command = `.load ${path.join(fixtures, '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();