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..c9b1952b996c5f 100644 --- a/test/parallel/test-repl.js +++ b/test/parallel/test-repl.js @@ -129,6 +129,18 @@ const strictModeTests = [ }, ]; +const possibleTokensAfterIdentifier = [ + '()', + '[0]', + '+ 1', '- 1', '* 1', '/ 1', '% 1', '** 1', + '== 1', '=== 1', '!= 1', '!== 1', '< 1', '> 1', '<= 1', '>= 1', + '&& 1', '|| 1', '?? 1', + '= 1', '+= 1', '-= 1', '*= 1', '/= 1', '%= 1', + '++', '--', + ':', + '? 1: 1', +]; + const errorTests = [ // Uncaught error throws and prints out { @@ -386,6 +398,16 @@ const errorTests = [ '(Press Ctrl+D to exit.)', ] }, + { + send: 'let npm = () => {};', + expect: 'undefined' + }, + ...possibleTokensAfterIdentifier.map((token) => ( + { + send: `npm ${token}; undefined`, + expect: 'undefined' + } + )), { send: '(function() {\n\nreturn 1;\n})()', expect: '... ... ... 1'