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: refactor repl.js #6071

Closed
wants to merge 1 commit into from
Closed

repl: refactor repl.js #6071

wants to merge 1 commit into from

Conversation

Trott
Copy link
Member

@Trott Trott commented Apr 6, 2016

Checklist
  • tests and code linting passes
  • the commit message follows commit guidelines
Affected core subsystem(s)

repl

Description of change

There is some unnecessary logic in repl.js. Remove it.

@Trott Trott added the repl Issues and PRs related to the REPL subsystem. label Apr 6, 2016
@Fishrock123
Copy link
Contributor

@Trott
Copy link
Member Author

Trott commented Apr 6, 2016

@jasnell
Copy link
Member

jasnell commented Apr 7, 2016

LGTM

@@ -409,7 +408,7 @@ function REPLServer(prompt,

// Check to see if a REPL keyword was used. If it returns true,
// display next prompt and return.
if (cmd && cmd.charAt(0) === '.' && isNaN(parseFloat(cmd))) {
if (cmd.charAt(0) === '.' && isNaN(parseFloat(cmd))) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This won't have problems if a string doesn't get passed? If so, should the if (cmd) below be cmd !== ''?

Copy link
Member Author

Choose a reason for hiding this comment

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

The existing code does not protect against non-strings. It only protects against falsy values.

You can't send a non-string without messing with REPLServer. I'll see about writing a test to make sure we are failing the same way when someone does that.

Copy link
Member Author

Choose a reason for hiding this comment

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

Re-adding check for cmd, alas.

@Trott Trott added the test Issues and PRs related to the tests. label Apr 7, 2016
There is some unnecessary logic in repl.js. Remove it.
@Trott
Copy link
Member Author

Trott commented Apr 7, 2016

Re-instated check for falsy cmd and added test. PTAL

@Trott
Copy link
Member Author

Trott commented Apr 7, 2016

@Trott
Copy link
Member Author

Trott commented Apr 7, 2016

CI is blissfully green.

@Trott
Copy link
Member Author

Trott commented Apr 8, 2016

@jasnell: Still LGTY?

@jasnell
Copy link
Member

jasnell commented Apr 8, 2016

yep!

Trott added a commit to Trott/io.js that referenced this pull request Apr 8, 2016
There is some unnecessary logic in repl.js. Remove it.

PR-URL: nodejs#6071
Reviewed-By: James M Snell <jasnell@gmail.com>
@Trott
Copy link
Member Author

Trott commented Apr 8, 2016

Landed in c5afd98

@Trott Trott closed this Apr 8, 2016
MylesBorins pushed a commit that referenced this pull request Apr 19, 2016
There is some unnecessary logic in repl.js. Remove it.

PR-URL: #6071
Reviewed-By: James M Snell <jasnell@gmail.com>
MylesBorins pushed a commit that referenced this pull request Apr 20, 2016
There is some unnecessary logic in repl.js. Remove it.

PR-URL: #6071
Reviewed-By: James M Snell <jasnell@gmail.com>
@MylesBorins MylesBorins mentioned this pull request Apr 20, 2016
MylesBorins pushed a commit that referenced this pull request Apr 20, 2016
There is some unnecessary logic in repl.js. Remove it.

PR-URL: #6071
Reviewed-By: James M Snell <jasnell@gmail.com>
This was referenced Apr 21, 2016
jasnell pushed a commit that referenced this pull request Apr 26, 2016
There is some unnecessary logic in repl.js. Remove it.

PR-URL: #6071
Reviewed-By: James M Snell <jasnell@gmail.com>
@MylesBorins
Copy link
Contributor

@Trott this was causing a test to fail on v4.x-staging. Would you be willing to backport?

@Trott
Copy link
Member Author

Trott commented May 18, 2016

@thealphanerd I think this depends on #5388 which doesn't look like it has landed in the 4.x branch. If that's going to land in 4.x, land it first, then this should be fine (tests will pass, etc.). If that's not going to land in 4.x, then maybe this doesn't need to land in 4.x either.

@MylesBorins
Copy link
Contributor

Setting as do not land... thanks @Trott


var replserver = new repl.REPLServer();

replserver._inTemplateLiteral = true;
Copy link
Member

Choose a reason for hiding this comment

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

@Trott do you still remember why you added this here?

Copy link
Member Author

Choose a reason for hiding this comment

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

I remember why I did it, but I do not remember why I chose that over possible alternatives.

I did that because this is going to test that null inside a template string gets treated like an empty string. (See the code comment below.)

It's possible that I was being lazy and/or copying from another test. It may be better to open an actual template string by emiting a backtick in a line. Or it's possible that I tried that and ran into problems.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, and I was testing this particular corner case because I wanted to make sure that my refactoring the code didn't alter the behavior. And this seemed to me like odd behavior for which we had no tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
repl Issues and PRs related to the REPL subsystem. test Issues and PRs related to the tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants