Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

repl: allow multiline function call #3823

Closed
wants to merge 1 commit into from
Closed
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 @@ -1126,7 +1126,10 @@ function isRecoverableError(e, self) {
self._inTemplateLiteral = true;
return true;
}
return /^(Unexpected end of input|Unexpected token)/.test(message);

return message.startsWith('Unexpected end of input') ||
message.startsWith('Unexpected token') ||
message.startsWith('missing ) after argument list');
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps a better approach would be defining a const as:

const remsg = new RegExp(
  '^(Unexpected end of input|' +
  'Unexpected token|' +
  'missing \\) after argument list)'
);

and using return remsg.test(message); ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup. We had discussed that in one of the old comments :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh lol. Sorry, missed that entirely ;)
On Nov 17, 2015 10:28 PM, "thefourtheye" [email protected] wrote:

In lib/repl.js
#3823 (comment):

@@ -1126,7 +1126,10 @@ function isRecoverableError(e, self) {
self._inTemplateLiteral = true;
return true;
}

  • return /^(Unexpected end of input|Unexpected token)/.test(message);
  • return message.startsWith('Unexpected end of input') ||
  •  message.startsWith('Unexpected token') ||
    
  •  message.startsWith('missing ) after argument list');
    
    }

Yup. We had discussed that in one of the old comments :)


Reply to this email directly or view it on GitHub
https://github.com/nodejs/node/pull/3823/files#r45164076.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jasnell I spent some time thinking about which way to go about this, and at the end decided with the "dumb" way. Doing it in fancy ways is possible, but doesn't give us readability or extensibility or anything else. So I fought the urge to rewrite that part.

...even though it's so tempting.

return false;
}
Expand Down
7 changes: 7 additions & 0 deletions test/parallel/test-repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,13 @@ function error_test() {
expect: prompt_multiline },
{ client: client_unix, send: '})()',
expect: '1' },
// Multiline function call
{ client: client_unix, send: 'function f(){}; f(f(1,',
expect: prompt_multiline },
{ client: client_unix, send: '2)',
expect: prompt_multiline },
{ client: client_unix, send: ')',
expect: 'undefined\n' + prompt_unix },
// npm prompt error message
{ client: client_unix, send: 'npm install foobar',
expect: expect_npm },
Expand Down