FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

test: replace function with arrow function by Leko · Pull Request #17345 · nodejs/node · GitHub

/ node Public

test: replace function with arrow function - #17345

Closed
Leko wants to merge 5 commits into
nodejs:masterfrom
Leko:replace_function_with_arrow_function
Closed

test: replace function with arrow function#17345
Leko wants to merge 5 commits into
nodejs:masterfrom
Leko:replace_function_with_arrow_function

Conversation

Leko commented Nov 27, 2017

Copy link
Copy Markdown
Contributor

This is part of Nodefest's Code and Learn nodejs/code-and-learn#72

Among the list of Code and Learn, I solved the unfinished task of replacing function with arrow function

  • test/parallel/test-assert.js
  • test/parallel/test-domain-top-level-error-handler-clears-stack.js
  • test/parallel/test-querystring.js
  • test/parallel/test-whatwg-url-searchparams-getall.js
  • test/parallel/test-writeint.js
  • test/parallel/test-zerolengthbufferbug.js
Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines
Affected core subsystem(s)

test

Among the list of [Code and Learn](nodejs/code-and-learn#72 (comment)), I solved the unfinished task of replacing function with arrow function
nodejs-github-bot added the test Issues and PRs related to the tests. label Nov 27, 2017
vsemozhetbyt added the code-and-learn Issues related to the Code-and-Learn events and PRs submitted during the events. label Nov 27, 2017
function makeBlock(f) {
const args = Array.prototype.slice.call(arguments, 1);
return function() {
return () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This makes this lexical. Is it OK here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Thank you for your review.

I think that it is OK because test passed locally.
It is not called with neither .call nor .apply in this file.
This code equivalent to:

  return () => {
    return f.apply(null, args);
  };

Should I replace this with null ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Maybe, for a clarity, but let's see what others think)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I got it.
Please let us know what others think.

Comment thread test/parallel/test-assert.js Outdated
// having an identical prototype property
const nbRoot = {
toString: function() { return `${this.first} ${this.last}`; }
toString: () => { return `${this.first} ${this.last}`; }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

The same.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Thank you for your review.
I was mistaken.

I'll fix this problem with like:

  toString() { return `${this.first} ${this.last}`; }

*/
/* eslint-disable */
test(function() {
test(() => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

As per the comment above, it seems we should not change this fragment.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Modifications to them should be upstreamed first.

I'm sorry to have missed it.
I'll revert changes in this file.

}, 'getAll() basics');

test(function() {
test(() => {

vsemozhetbyt Nov 27, 2017
edited
Loading

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Ditto.

Leko added 2 commits November 27, 2017 20:04
Arrow function makes `this` lexical scope.
But toString expects evaluate `this` in runtime.
These tests are copied from WPT.
I should not changed it directly.
Comment thread test/parallel/test-assert.js Outdated
testAssertionMessage(/abc/gim, '/abc/gim');
testAssertionMessage(function f() {}, '[Function: f]');
testAssertionMessage(function() {}, '[Function]');
testAssertionMessage(() => {}, '[Function]');

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I think that it should be reverted because function() {} and () => {} are should be tested both.
This PR changes only syntax, should not change test case.
So it better of separated by another PR.

What do you think about it ?

Comment thread test/parallel/test-assert.js Outdated
testAssertionMessage(/abc/gim, '/abc/gim');
testAssertionMessage(function f() {}, '[Function: f]');
testAssertionMessage(function() {}, '[Function]');
testAssertionMessage(() => {}, '[Function]');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

In my humble opinion, this check would be better to not replace arrow function. Because assert message also should have '[Function]' when function() {} is input.
We would be better to check both function style arrow function and normal function.

makeBlock does not need `this`.
update `this` with `null` to clarify the intent.
mscdex added assert Issues and PRs related to the assert subsystem. domain Issues and PRs related to the domain subsystem. querystring Issues and PRs related to the built-in querystring module. labels Nov 27, 2017

Copy link
Copy Markdown
Contributor

`function() {}` and `() => {}` are should be tested both.
See also #17345 (comment)

Copy link
Copy Markdown
Contributor

Copy link
Copy Markdown
Contributor

Hmm. It seems CI does not post status to PR currently.

Leko commented Nov 27, 2017

Copy link
Copy Markdown
Contributor Author

Yesterday, status integration is worked fine.
What's happen ... ? 🤔

Leko commented Nov 29, 2017

Copy link
Copy Markdown
Contributor Author

Hi @vsemozhetbyt.
Should I take any action to merge this PR ?

Copy link
Copy Markdown
Contributor

@Leko Sorry for the delay. Let's run the CI again. If it is green, we will land it today.

https://ci.nodejs.org/job/node-test-pull-request/11798/

Leko commented Nov 29, 2017

Copy link
Copy Markdown
Contributor Author

@vsemozhetbyt I got it. Thank you for quick reply !

Copy link
Copy Markdown
Contributor

One CI failure seems unrelated. Landing...

vsemozhetbyt pushed a commit that referenced this pull request Nov 29, 2017
1. Among the list of Code and Learn,
I solved the unfinished task of replacing function with arrow function:
nodejs/code-and-learn#72 (comment)

2. Replace arrow function with shorter property syntax
Arrow function makes `this` lexical scope.
But toString expects evaluate `this` in runtime.

3. Replace this with null
makeBlock does not need `this`.
update `this` with `null` to clarify the intent.

PR-URL: #17345
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Jon Moss <me@jonathanmoss.me>
Reviewed-By: Yosuke Furukawa <yosuke.furukawa@gmail.com>

Copy link
Copy Markdown
Contributor

Squashed and landed in 3c62f33

Thank you, @Leko!

MylesBorins pushed a commit that referenced this pull request Dec 12, 2017
1. Among the list of Code and Learn,
I solved the unfinished task of replacing function with arrow function:
nodejs/code-and-learn#72 (comment)

2. Replace arrow function with shorter property syntax
Arrow function makes `this` lexical scope.
But toString expects evaluate `this` in runtime.

3. Replace this with null
makeBlock does not need `this`.
update `this` with `null` to clarify the intent.

PR-URL: #17345
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Jon Moss <me@jonathanmoss.me>
Reviewed-By: Yosuke Furukawa <yosuke.furukawa@gmail.com>
MylesBorins pushed a commit that referenced this pull request Dec 12, 2017
1. Among the list of Code and Learn,
I solved the unfinished task of replacing function with arrow function:
nodejs/code-and-learn#72 (comment)

2. Replace arrow function with shorter property syntax
Arrow function makes `this` lexical scope.
But toString expects evaluate `this` in runtime.

3. Replace this with null
makeBlock does not need `this`.
update `this` with `null` to clarify the intent.

PR-URL: #17345
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Jon Moss <me@jonathanmoss.me>
Reviewed-By: Yosuke Furukawa <yosuke.furukawa@gmail.com>
MylesBorins mentioned this pull request Dec 12, 2017
gibfahn pushed a commit that referenced this pull request Dec 19, 2017
1. Among the list of Code and Learn,
I solved the unfinished task of replacing function with arrow function:
nodejs/code-and-learn#72 (comment)

2. Replace arrow function with shorter property syntax
Arrow function makes `this` lexical scope.
But toString expects evaluate `this` in runtime.

3. Replace this with null
makeBlock does not need `this`.
update `this` with `null` to clarify the intent.

PR-URL: #17345
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Jon Moss <me@jonathanmoss.me>
Reviewed-By: Yosuke Furukawa <yosuke.furukawa@gmail.com>
gibfahn mentioned this pull request Dec 20, 2017
gibfahn pushed a commit that referenced this pull request Dec 20, 2017
1. Among the list of Code and Learn,
I solved the unfinished task of replacing function with arrow function:
nodejs/code-and-learn#72 (comment)

2. Replace arrow function with shorter property syntax
Arrow function makes `this` lexical scope.
But toString expects evaluate `this` in runtime.

3. Replace this with null
makeBlock does not need `this`.
update `this` with `null` to clarify the intent.

PR-URL: #17345
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Jon Moss <me@jonathanmoss.me>
Reviewed-By: Yosuke Furukawa <yosuke.furukawa@gmail.com>
gibfahn mentioned this pull request Dec 20, 2017
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

assert Issues and PRs related to the assert subsystem. code-and-learn Issues related to the Code-and-Learn events and PRs submitted during the events. domain Issues and PRs related to the domain subsystem. querystring Issues and PRs related to the built-in querystring module. test Issues and PRs related to the tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants


Back | FazBrowse Home | New Git URL