diff --git a/lib/repl.js b/lib/repl.js index 6e2d8120ad2167..a7aa4c717837dd 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -931,7 +931,9 @@ function REPLServer(prompt, ReflectApply(_memory, self, [cmd]); if (e && !self[kBufferedCommandSymbol] && - StringPrototypeStartsWith(StringPrototypeTrim(cmd), 'npm ')) { + StringPrototypeStartsWith(StringPrototypeTrim(cmd), 'npm ') && + !(e instanceof Recoverable) + ) { self.output.write('npm should be run outside of the ' + 'Node.js REPL, in your normal shell.\n' + '(Press Ctrl+D to exit.)\n'); diff --git a/test/parallel/test-repl.js b/test/parallel/test-repl.js index 4d406a8a36caaf..3b885936496f0a 100644 --- a/test/parallel/test-repl.js +++ b/test/parallel/test-repl.js @@ -129,6 +129,17 @@ const strictModeTests = [ }, ]; +const possibleTokensAfterIdentifierWithLineBreak = [ + '(\n)', + '[\n0]', + '+\n1', '- \n1', '* \n1', '/ \n1', '% \n1', '** \n1', + '== \n1', '=== \n1', '!= \n1', '!== \n1', '< \n1', '> \n1', '<= \n1', '>= \n1', + '&& \n1', '|| \n1', '?? \n1', + '= \n1', '+= \n1', '-= \n1', '*= \n1', '/= \n1', '%= \n1', + ': \n', + '? \n1: 1', +]; + const errorTests = [ // Uncaught error throws and prints out { @@ -386,6 +397,16 @@ const errorTests = [ '(Press Ctrl+D to exit.)', ] }, + { + send: 'let npm = () => {};', + expect: 'undefined' + }, + ...possibleTokensAfterIdentifierWithLineBreak.map((token) => ( + { + send: `npm ${token}; undefined`, + expect: '... undefined' + } + )), { send: '(function() {\n\nreturn 1;\n})()', expect: '... ... ... 1'