GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — repl: avoid interpreting 'npm' as a command when errors are recoverable · nodejs/node@67b1d4c

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib
    • repl.js
  • test/parallel
    • test-repl.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/repl.js‎

Copy file name to clipboardExpand all lines: lib/repl.js
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -931,7 +931,9 @@ function REPLServer(prompt,
931931
ReflectApply(_memory, self, [cmd]);
932932

933933
if (e && !self[kBufferedCommandSymbol] &&
934-
StringPrototypeStartsWith(StringPrototypeTrim(cmd), 'npm ')) {
934+
StringPrototypeStartsWith(StringPrototypeTrim(cmd), 'npm ') &&
935+
!(e instanceof Recoverable)
936+
) {
935937
self.output.write('npm should be run outside of the ' +
936938
'Node.js REPL, in your normal shell.\n' +
937939
'(Press Ctrl+D to exit.)\n');
Collapse file

‎test/parallel/test-repl.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-repl.js
+21Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,17 @@ const strictModeTests = [
129129
},
130130
];
131131

132+
const possibleTokensAfterIdentifierWithLineBreak = [
133+
'(\n)',
134+
'[\n0]',
135+
'+\n1', '- \n1', '* \n1', '/ \n1', '% \n1', '** \n1',
136+
'== \n1', '=== \n1', '!= \n1', '!== \n1', '< \n1', '> \n1', '<= \n1', '>= \n1',
137+
'&& \n1', '|| \n1', '?? \n1',
138+
'= \n1', '+= \n1', '-= \n1', '*= \n1', '/= \n1', '%= \n1',
139+
': \n',
140+
'? \n1: 1',
141+
];
142+
132143
const errorTests = [
133144
// Uncaught error throws and prints out
134145
{
@@ -386,6 +397,16 @@ const errorTests = [
386397
'(Press Ctrl+D to exit.)',
387398
]
388399
},
400+
{
401+
send: 'let npm = () => {};',
402+
expect: 'undefined'
403+
},
404+
...possibleTokensAfterIdentifierWithLineBreak.map((token) => (
405+
{
406+
send: `npm ${token}; undefined`,
407+
expect: '... undefined'
408+
}
409+
)),
389410
{
390411
send: '(function() {\n\nreturn 1;\n})()',
391412
expect: '... ... ... 1'

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.