-
Notifications
You must be signed in to change notification settings - Fork 30.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The `.load` command would fail with any file that contains multiline `.` operator expressions. This was particularly noticeable when chaining promises or multi-line arrow expressions. This change Forces the REPL to be in `editorMode` while loading a file from disk using the `.load` command. Fixes: #14022 Backport-PR-URL: #15775 PR-URL: #14861 Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Refael Ackermann <[email protected]>
- Loading branch information
1 parent
d8f5637
commit 02b4684
Showing
3 changed files
with
53 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
const getLunch = () => | ||
placeOrder('tacos') | ||
.then(eat); | ||
|
||
const placeOrder = (order) => Promise.resolve(order); | ||
const eat = (food) => '<nom nom nom>'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) => '<nom nom nom>'; | ||
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(); |