Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ const {
StringPrototypeIncludes,
StringPrototypeRepeat,
StringPrototypeSlice,
StringPrototypeSplit,
StringPrototypeStartsWith,
StringPrototypeTrim,
Symbol,
Expand Down Expand Up @@ -802,11 +803,13 @@ class REPLServer extends Interface {
}

// Check REPL keywords and empty lines against a trimmed line input.
const trimmedCmd = StringPrototypeTrim(cmd);
let trimmedCmd = StringPrototypeTrim(cmd);

// Check to see if a REPL keyword was used. If it returns true,
// display next prompt and return.
if (trimmedCmd) {
const splitString = StringPrototypeSplit(trimmedCmd, '\r');
trimmedCmd = splitString[splitString.length - 1];
if (StringPrototypeCharAt(trimmedCmd, 0) === '.' &&
StringPrototypeCharAt(trimmedCmd, 1) !== '.' &&
NumberIsNaN(NumberParseFloat(trimmedCmd))) {
Expand Down
47 changes: 47 additions & 0 deletions test/parallel/test-repl-multiline-dot-commands-execution.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const { startNewREPLServer } = require('../common/repl');


const dotCommandSyntaxError =
/Uncaught SyntaxError: Unexpected token '\.'/;


function runDotCommand(command, validate) {
const { replServer, output } = startNewREPLServer();

replServer.on('exit', common.mustCall());
replServer.write(`${command}\n`);
replServer.write('let testObj = {\n');
replServer.write(`${command}:"dummy-value"\n`);
replServer.write(`}`);
replServer.write('function a() {\n');
replServer.write('console.log("logging");\n');
replServer.write(`let value = testObj ${command} \n`);
replServer.write('console.log(value) \n');
replServer.write(`${command}\n`);
validate(replServer, output);
replServer.write('arr = [1,\n');
replServer.write('consdole.log("logging");\n');
validate(replServer, output);
replServer.close();
}

runDotCommand('.break', common.mustCall((replServer, output) => {
replServer.write('1 + 1\n');
assert.doesNotMatch(output.accumulator, dotCommandSyntaxError);
assert.match(output.accumulator, /2\n/);
}, 2));

runDotCommand('.clear', common.mustCall((replServer, output) => {
replServer.write('1 + 1\n');
assert.doesNotMatch(output.accumulator, dotCommandSyntaxError);
assert.match(output.accumulator, /2\n/);
}, 2));

runDotCommand('.help', common.mustCall((replServer, output) => {
replServer.write('1 + 1\n');
assert.doesNotMatch(output.accumulator, dotCommandSyntaxError);
assert.match(output.accumulator, /2\n/);
}, 2));
Loading